-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.json
1 lines (1 loc) ยท 186 KB
/
index.json
1
[{"authors":["young-kim","whi-kwon"],"categories":[],"content":" Multi-scale ์ด๋ฒ ์ฅ ์์๋ ๋คํด์๋(Multi-scale)์ ๋ํ ๊ฐ๋
๊ณผ ์ ํต์ ์ธ Computer Vision์์ Multi-scale Image ์ฒ๋ฆฌ๋ฅผ ํ๋ ๋ฐฉ๋ฒ์ ์์๋ณด๊ฒ ์ต๋๋ค. ์ผ๋ฐ์ ์ผ๋ก ํ๋์ ํด์๋์ ์ต์ ํ๋ Computer Vision Model๋ณด๋ค ๋คํด์๋๋ฅผ ์ฒ๋ฆฌํ ์ ์๋ Computer Vision Model์ด ๋ ์ข์ ์ฑ๋ฅ์ ๋ผ ๊ฐ๋ฅ์ฑ์ด ๋๊ธฐ ๋๋ฌธ์ Multi-scale ๋ฌธ์ ๋ ๊ผญ ํด๊ฒฐํด์ผ๋ง ํ๋ ๋ฌธ์ ์
๋๋ค. ์ฌ๊ธฐ์์๋ ๊ฐ์ฅ ๋จ์ํ๊ณ ์ค๋๋ ๊ธฐ๋ฒ์ธ Image Pyramid๊ธฐ๋ฒ๋ง์ ์์๋ณด๊ฒ ์ต๋๋ค. ๋จ์ํ๊ฒ ์์ฝํ๋ฉด ํผ๋ผ๋ฏธ๋๋ก ์์ ๊ฒ ๊ฐ์ด ๋ค์ํ ํฌ๊ธฐ์ Image๋ฅผ ๋ง์ด ์ค๋นํ๋ ๋ฐฉ๋ฒ ์
๋๋ค. Image pyramid Import Libraries import os import sys import math from platform import python_version import cv2 import matplotlib.pyplot as plt import matplotlib import imutils import numpy as np print(f\u0026quot;Python version : {python_version()}\u0026quot;, ) print(f\u0026quot;Opencv version : {cv2.__version__}\u0026quot;, ) Python version : 3.6.9 Opencv version : 4.1.2 Data load sample_image_path = '../image/' sample_image = 'kitten.jpg' img = cv2.imread(os.path.join(sample_image_path, sample_image), cv2.IMREAD_GRAYSCALE) h, w = img.shape matplotlib.rcParams['figure.figsize'] = (8.0, 8.0) Image\u0026nbsp;Pyramid ์ ํต์ ์ธ Computer Vision์ด๋ Deep Learning ๋ชจ๋ ๊ณตํต์ ์ผ๋ก ํฌ๊ธฐ ๋ณํ์ ์ทจ์ฝํ๋ค๋ ๋จ์ ์ ๊ฐ์ง๊ณ ์์ต๋๋ค. ์ฆ, ๊ฐ์ ๋ชจ๋ธ๋ก ๋ ํฌ๊ฑฐ๋ ์์ Image๋ฅผ ๋ถ์ํ ๊ฒฝ์ฐ ๊ฒฐ๊ณผ๊ฐ ์ ํ ๋ฌ๋ผ์ง ์ ์๋ค๋ ๋ง ์
๋๋ค. ์ด์ ๋์ํ๊ธฐ ์ํด ํ์ฌ Feature์ถ์ถ, ์ถ๋ก ๋ฑ์์ ๋ค์ํ ํด์๋์ Image๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ๋ณดํต์
๋๋ค. Image Pyramid[2]๋, Image๋ฅผ ๋ค์ํ ํด์๋์ Image๋ก ๋ณํํ๊ณ ์์์ฌ๋ ค์ ๋ง์น ํผ๋ผ๋ฏธ๋์ ๊ฐ์ ํ์์ ๋๋๋ก ์ค๋นํ๋ ์ ์ฒ๋ฆฌ ๊ธฐ๋ฒ์
๋๋ค. ์ด๋ Multi-scale ๋ฌธ์ ๋ฅผ ํด๊ฒฐํด์ผ ํ ๋ ์์ฃผ ์ฐ์ด๋ ๊ธฐ๋ฒ์ด๋ฉฐ, Deep Learning์์ ์ฐ์ด๋ FPN ๋ฑ์ ๋ฐฉ๋ฒ๋ค์ด ์ด Image Pyramid ๊ธฐ๋ฒ์ ๊ฐ์ ํ๋ ๊ณผ์ ์์ ๊ณ ์๋ ๊ฒ์์ ๊ฐ์ํ ๋, Image Pyramid๊ธฐ๋ฒ์ Multi-scale ๋ฌธ์ ํด๊ฒฐ์ ์์์ ์ด๋ผ๊ณ ํ ์ ์์ต๋๋ค. ๋คํด์๋ ์ฒ๋ฆฌ Image Pyramid์์ ๊ฒฐ๊ตญ ๊ด๊ฑด์ ๋ค์ํ ํด์๋์ Image๋ฅผ ์ด๋ป๊ฒ ์ค๋นํ ๊ฒ์ด๋ ์ธ๋ฐ, ํฌ๊ธฐ๊ฐ ์์ Image๋ผ๋ฉด Upsampling์ ํด์ ๋ ํฐ ํด์๋๋ก ๋ง๋ค์ด์ผ ํ๊ณ , ํฌ๊ธฐ๊ฐ ํฐ Image๋ผ๋ฉด Downsampling์ ํด์ Image ํฌ๊ธฐ๋ฅผ ์ค์ฌ์ผ ํฉ๋๋ค. ๊ทธ๋ฌ๋ ๋ ๋ฐฉ๋ฒ ๋ชจ๋ ๋จ์ํ ์ ์ฉํ๋ฉด ์ ๋ณด๋์ ๋ณํ๋ก ์ธํด ์๋ Image๋ณด๋ค ๋ค์ ๋ถ์์ฐ์ค๋ฌ์ ๋ณด์ด๊ฒ ๋๋ Aliasing์ด๋ผ๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๊ฒ ๋๋๋ฐ, ์ด๋ฅผ ๋ณด์ํ๋ ๋ฐฉ๋ฒ์ ๋ํด ๊ฐ๋จํ ์์๋ณด๊ฒ ์ต๋๋ค. Upsample Upsample์์ ๋ฐ์ํ๋ Aliasing๋ฌธ์ ๋ ๋๋ถ๋ถ์ ๊ฒฝ์ฐ ์ง๋ ์ฅ์์ ํ์ธํ Interpolation ๋ฐฉ๋ฒ์ผ๋ก ํด๊ฒฐํฉ๋๋ค. ์์ฑ๋ชจ๋ธ์ด๋ ํ์ธต ๋ ๋์ ์ ๊ตํจ์ ์๊ตฌํ๋ ๋ชจ๋ธ์๊ฒฝ์ฐ ๋ฐ์ดํฐ์ ๋ง๊ฒ ํ์ต๋ Filter๋ฅผ ์ด์ฉํ๋ Deconvolution ๋ฑ์ด ์ฌ์ฉ๋๊ธฐ๋ ํฉ๋๋ค. Downsample Downsample์ ๊ฒฝ์ฐ ํน์ ํ์๋ฅผ ์ ํ์ ์ผ๋ก ์ ๊ฑฐํด์ผ ํ๋ฏ๋ก ๋ฌธ์ ๊ฐ ๋ฐ์ํฉ๋๋ค. ๋จ์ํ ์ง์๋ฒ์งธ๋ ํ์๋ฒ์งธ ํ์๋ฅผ ์ ๊ฑฐํ๋ ๋ฐฉ์์ ์ฌ์ฉํ ๊ฒฝ์ฐ, ์ ๊ฑฐ๋๋ ํ์๋งํผ ๊ทธ๋๋ก ์์ค์ด ๋๊ธฐ ๋๋ฌธ์ Image์ ํ์ง์ด ๋น ๋ฅด๊ฒ ๋๋น ์ง๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค. img_half = cv2.resize(img, (w // 2, h // 2)) img_quard = cv2.resize(img, (w // 4, h // 4)) img_eight = cv2.resize(img, (w // 8, h // 8)) plt.subplot(221) plt.imshow(img, cmap='gray') plt.title('Original image') plt.subplot(222) plt.imshow(img_half, cmap='gray') plt.title('1/2 sized') plt.subplot(223) plt.imshow(img_quard, cmap='gray') plt.title('1/4 sized') plt.subplot(224) plt.imshow(img_eight, cmap='gray') plt.title('8/1 sized') plt.suptitle('Kitten with many size', size=15) plt.show() ์ด๋ฌํ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํ ๋์์ ์๋ณธ Image์ Smoothing์ ์ ์ฉํ ํ Downsampling์ ์ ์ฉํ๋ ๊ฒ ์
๋๋ค. ์ ํ์ ์ผ๋ก ์ ๊ฑฐ๋๋ ํฝ์
์ ์ ๋ณด๋ฅผ ์ฃผ๋ณ ํฝ์
๋ค์ ์กฐ๊ธ์ฉ ๋ฐ์ํด์ฃผ๋ ์๋ฆฌ์
๋๋ค. ์๋ ์์ ๋ ๊ต์ฌ์์ ์ฌ์ฉ๋ ์ปค๋ ํจ์๋ก Smoothing์ ์ ์ฉํ ๊ฒฐ๊ณผ์
๋๋ค. kernel = np.array([[0.05, 0.25, 0.4, 0.25, 0.05]]) kernel = np.dot(kernel.T, kernel) blur_img_half = cv2.resize(cv2.filter2D(img, -1, kernel), (w // 2, h // 2)) blur_img_quard = cv2.resize( cv2.filter2D(blur_img_half, -1, kernel), (w // 4, h // 4)) blur_img_eight = cv2.resize( cv2.filter2D(blur_img_quard, -1, kernel), (w // 8, h // 8)) plt.subplot(221) plt.imshow(img, cmap='gray') plt.title('Original') plt.subplot(222) plt.imshow(blur_img_half, cmap='gray') plt.title('Blur_half') plt.subplot(223) plt.imshow(blur_img_quard, cmap='gray') plt.title('Blur_quard') plt.subplot(224) plt.imshow(blur_img_eight, cmap='gray') plt.title('Blur_eight') plt.suptitle('Soft Kitten with many size', size=15) plt.show() Conclusion Multi-scale Image๋ฅผ ์์ฑํ ๋ ๋ฐ์ํ๋ ๋ฌธ์ ์ ์ด์ ๋์ํ๊ธฐ ์ํด ํ์ํ ์์
๋ค์ ์ดํด๋ณด์์ต๋๋ค. ์ฌ๊ธฐ์์ Smoothing ์์
์ ์งํํ ๋, ๋ค์ํ ์ปค๋์ ์ด์ฉํ ์ ์๋๋ฐ, Image์ ๋ฐ๋ผ ๋ชฉ์ ์ ๋ฐ๋ผ ์ต์ ์ ์ปค๋์ด ๋ฐ๋ก ์กด์ฌํฉ๋๋ค. ์ด ๋ง์ ๊ทธ๋ ๊ทธ๋ ์๋ง์ ์ปค๋์ ์ง์ ์ฐพ์์ ์ฌ์ฉํด์ผ ํ๋ค๋ ๋ป์ด๊ธฐ๋ ํฉ๋๋ค. ์ด๋ฌํ ๋ถ๋ถ์ด ์ ํต์ ์ธ ๋ฐฉ์์ Computer Vision์ด ๊ฐ์ง๊ณ ์์๋ ๊ณ ์ง์ ์ธ ์ฝ์ ์
๋๋ค. Reference [1] ์ค์ผ์, \u0026ldquo;๋คํด์๋,\u0026rdquo; in ์ปดํจํฐ ๋น์ , vol.4, Republic of Korea:ํ๋น์์นด๋ฐ๋ฏธ, 2014, pp. 93-96 [2] Accessed: \u0026lsquo;Image Pyramids\u0026rsquo;, opencv official, [Online] Avaliable: https://docs.opencv.org/3.4/dc/dff/tutorial_py_pyramids.html ","date":1593480000,"expirydate":-62135596800,"kind":"page","lang":"en","lastmod":1593480000,"objectID":"cd0ca439f351e600735eee7a47d1c293","permalink":"/post/2020-06-30-multi_scale/","publishdate":"2020-06-30T10:20:00+09:00","relpermalink":"/post/2020-06-30-multi_scale/","section":"post","summary":"Handling multi-scale images using OpenCV","tags":[],"title":"[Tutorial] Multi-scale","type":"post"},{"authors":["young-kim","whi-kwon"],"categories":[],"content":" Morphology ์ด๋ฒ ์ฅ ์์๋ Morphology Operation[2]์ ๋ํ์ฌ ์์๋ณด๊ฒ ์ต๋๋ค. Morphology Operation์ด๋, Image์ ํํ๋ฅผ ์กฐ์ํ๋ ์ฐ์ฐ์ ์ข
๋ฅ๋ฅผ ํต์นญํฉ๋๋ค. ์ ์ฉ ๋์์ด ์ด๋ค Image๋์ ๋ฐ๋ผ Binary, Grayscale๋ก ๋๋ ์ ์๊ณ , ์ฐ์ฐ ๋ฐฉ์์ ๋ฐ๋ผ Dilation(ํ์ฐ)๊ณผ Erosion(์นจ์)์ผ๋ก ๋๋ ์ ์์ต๋๋ค. ๋ ์ฐ์ฐ ๋ชจ๋ ๊ณตํต์ ์ผ๋ก Source Image Kernel์ ํตํด Target Image๋ฅผ ์์ฑํ๋ ๊ณผ์ ์ ๊ฐ์ต๋๋ค. Morphology Operation์ ์์ฉํ๋ฉด Edge Detection์ด๋ Image Denoising ๋ฑ์ ์์
์ ํ ์ ์์ต๋๋ค. ๋ชฉ์ฐจ๋ ์๋์ ๊ฐ์ต๋๋ค. Binary Morphology Grayscale Morphology Composited Morphological Operations Import Libraries import os import sys import math from platform import python_version import cv2 import matplotlib.pyplot as plt import matplotlib import numpy as np print(\u0026quot;Python version : \u0026quot;, python_version()) print(\u0026quot;Opencv version : \u0026quot;, cv2.__version__) Python version : 3.6.9 Opencv version : 4.1.2 Data load sample_image_path = '../image/' sample_image = 'kitten.jpg' img = cv2.imread(os.path.join(sample_image_path, sample_image), cv2.IMREAD_GRAYSCALE) h, w = [int(x) for x in img.shape] matplotlib.rcParams['figure.figsize'] = (8.0, 8.0) Binary\u0026nbsp;Morphology ์ ์ฒด Image๊ฐ 0 ๋๋ 1๋ก ์ด๋ฃจ์ด์ง Image๋ฅผ Binary Image๋ผ๊ณ ํฉ๋๋ค. ์๋ ์ค๋ช
์ ๋ชจ๋ Binary Image๋ฅผ ๊ธฐ์ค์ผ๋ก ํ๊ฒ ์ต๋๋ค. ์ด๋ฌํ Image๋ ๋ณดํต Image ์์ฒด๋ก ์ด์ฉ๋๊ธฐ๋ณด๋ค RoI(Region of Interest)๋ฅผ ์ ํํ๊ธฐ ์ํ Mask๋ก์ ์ด์ฉ๋ฉ๋๋ค. Binary Image์ Morphology๋ฅผ ์ ์ฉํ๋ฉด ์์ํ Noise๋ฅผ ์ ๊ฑฐํ๋๋ฐ ๋์์ด ๋ฉ๋๋ค. Erosion ์ฐ์ฐ์ ์นจ์์ด๋ผ๋ ๋ง ๋ป์ด ์๋ฏธํ๋ฏ์ด 1์ ํด๋นํ๋ ๋ฐ์ ์์ญ์ด ์กฐ๊ธ์ฉ ์ค์ด๋๋ ๋ชจ์ต์ ๋ณด์
๋๋ค. RoI ๋ฐ๊นฅ์ 1์ ๊ฐ์ ๊ฐ๋ Noise๊ฐ ๋ฐ์ํ๋ ๊ฒฝ์ฐ์ Erosion ์ฐ์ฐ์ ํตํด Noise๋ฅผ ๋ณด์ ํ ์ ์์ต๋๋ค. Dilation ์ฐ์ฐ์ ํฝ์ฐฝ์ด๋ผ๋ ๋ป์ธ๋ฐ, ํฐ์ ์์ญ์ด ์กฐ๊ธ ์ปค์ง๋ ๋ชจ์ต์ ๋ณด์
๋๋ค. RoI ์ค๊ฐ์ 0์ ๊ฐ์ ๊ฐ๋ Noise๊ฐ ๋ฐ์ํ๋ ๊ฒฝ์ฐ์ Dilation ์ฐ์ฐ์ผ๋ก ๋ณด์ ํ ์ ์์ต๋๋ค. ํ ๋ฒ์ ํธ์ถ๋ก ๋ช ๋ฒ์ฉ ์ฐ์ฐ์ ๋ฐ๋ณตํ ์ง๋ฅผ ์ธ์ \u0026lsquo;iterations\u0026rsquo;๋ก ์กฐ์ ํ ์ ์์ต๋๋ค. ret, th = cv2.threshold(img, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU) kernel = np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]], dtype=np.uint8) erosion = cv2.erode(th, kernel, iterations=1) dilation = cv2.dilate(th, kernel, iterations=1) th = cv2.cvtColor(th, cv2.COLOR_GRAY2RGB) erosion = cv2.cvtColor(erosion, cv2.COLOR_GRAY2RGB) dilation = cv2.cvtColor(dilation, cv2.COLOR_GRAY2RGB) th = cv2.rectangle(th, (200, 140), (400, 340), (255, 0, 0), 3) erosion = cv2.rectangle(erosion, (200, 140), (400, 340), (255, 0, 0), 3) dilation = cv2.rectangle(dilation, (200, 140), (400, 340), (255, 0, 0), 3) plt.subplot(221) plt.imshow(th, cmap='gray') plt.title('Binary Kitten') plt.subplot(223) plt.imshow(erosion, cmap='gray') plt.title('Erosed Kitten') plt.subplot(224) plt.imshow(dilation, cmap='gray') plt.title('Dilated Kitten') plt.suptitle('Binary Kitten with morphology', size=15) plt.show() Grayscale\u0026nbsp;Morphology Morphology Operation์ Grayscale Image์ ์ ์ฉํ๊ฒ ๋๋ฉด ๊ธฐ๋ณธ ์๋ฆฌ๋ ๋์ผํ์ง๋ง ๊ฒฐ๊ณผ๊ฐ ์์ฃผ ๋ฌ๋ผ์ง๋๋ค. 1, 0์ ๊ฐ์ ์ฌ์ฉํ๋ ๊ฒ์ด ์๋๋ผ Dilation์ ๊ฒฝ์ฐ Max๊ฐ์, Erosion์ ๊ฒฝ์ฐ Min ๊ฐ์ ์ฌ์ฉํ๋ค๋ ์ ์ด ๋ค๋ฅธ ์ ์
๋๋ค. ์์ธํ ๊ฒ์ ์๋ ์์์ ํตํด ํ์ธํ ์ ์์ต๋๋ค. grayscale dilation : $ (I\\oplus k)(j,i)=max_{(y,x)\\subseteq k} (I(j-y,i-x)+k(y,x))$ grayscale erosion : $ (I\\ominus k)(j,i)=min_{(y,x)\\subseteq k} (I(j+y,i+x)-k(y,x))$ I = Image, k = kernel ์์์์ ์ ์ ์๋ฏ Min, Max์ฐ์ฐ์ด ์ ์ฉ๋ฉ๋๋ค. Dilation์ ๊ฒฝ์ฐ ํฐ ๊ฐ์ ๋ ํฌ๊ฒ, ์์ ๊ฐ์ ๋ ์๊ฒ ํ์ฌ ํฝ์
๊ฐ๊ฐ์ ์ฐจ์ด๋ฅผ ๊ทน๋ํํ๋ ์ฐ์ฐ์ด๊ณ , Erosion์ ๊ฒฝ์ฐ ํฐ ๊ฐ์ ์๊ฒ, ์์ ๊ฐ์ ํฌ๊ฒ ํ์ฌ ์ ์ฒด์ ์ผ๋ก ํํํ๊ฒ ๋ง๋๋ ์ฐ์ฐ์
๋๋ค. kernel = np.array([[1, 2, 1]]) gray_kernel = np.dot(kernel.T, kernel) gray_erosion = cv2.erode(img, gray_kernel, iterations=1) gray_dilation = cv2.dilate(img, gray_kernel, iterations=1) plt.subplot(221) plt.imshow(img, cmap='gray') plt.title('Gray Kitten') plt.subplot(223) plt.imshow(gray_erosion, cmap='gray') plt.title('Gray Erosed Kitten') plt.subplot(224) plt.imshow(gray_dilation, cmap='gray') plt.title('Gray Dilated Kitten') plt.suptitle('Gray Kitten with morphology', size=15) plt.show() ์ด๋ค Image์ ์ปค๋์ ์ ์ฉํ๋๋๊ฐ Morphology Operation ์ ํต์ฌ์
๋๋ค. ๋ฌผ๋ก ์ด๋ค ์ปค๋์ ์ค๊ณํ๋๋๋ ์ค์ํ์ง๋ง, ์ด๋ค ์ฐ์ฐ์ ์ด๋ค ์์๋ก ๋ช ๋ฒ ์ฉ ์ ์ฉํ ๊ฒ์ธ๊ฐ ๋ํ ๊ฒฐ๊ณผ๋ฌผ์ ๋ง์ ์ํฅ์ ๋ผ์นฉ๋๋ค. ์ ๊ฒฐ๊ณผ๋ฌผ์ ์ป๋๋ฐ ์ฌ์ฉํ kernel์ ๊ฐ์ด๋ฐ์ชฝ์ ๋ ๋ง์ ๊ฐ์ค์น๋ฅผ ์ฃผ๊ฒ ๋์ด ์ฃผ๋ณ๊ณผ์ ๋ช
์ ์ฐจ์ด๋ฅผ ๋ ํฌ๊ฒ ํ๋ ํจ๊ณผ๊ฐ ์์ต๋๋ค. Morphology์ฐ์ฐ์ Heuristicํ ํน์ฑ์ด ํฌ๊ฒ ๋๋ฌ๋๋ ์ฐ์ฐ์
๋๋ค. ๋ค์ํ ํน์ฑ์ด ์กด์ฌํ๋ Image ์ ์ฒด์ ์ผ๊ด์ ์ผ๋ก ๋์ผํ Morphology Operation์ ์ ์ฉํ๋ ๊ฒ์ ๋๋ถ๋ถ ์๋ฏธ๊ฐ ์๊ณ , ๋์ผํ ํน์ฑ์ ๊ฐ์ง ๋ถ๋ถ์ ํน์ ํ ๋ชฉ์ ์ํด ์ ์ฉํ๋ ํธ์ด ์ข์ต๋๋ค. ์ด๋ฌํ ์์
์ ์ ํ๊ธฐ ์ํด์๋ ๊ฒฐ๊ตญ ๋ค์ํ Image์ ๋ค์ํ ๋ฐฉ๋ฒ์ผ๋ก ๋ค์ํ ์ปค๋์ ์ ์ฉํด๋ณด๋ฉด์ ๊ฐ์ ์ก์์ผ ํฉ๋๋ค. Composited\u0026nbsp;Morphological\u0026nbsp;Operations ์์ ์๊ฐํ ๋ Morphology Operation์ ๋ฒ๊ฐ์ ํ ๋ฒ ์ฉ ์ ์ฉํ๋ ์์
๋ํ ์๋นํ ๋น๋ฒํ๊ฒ ์ฌ์ฉ๋ฉ๋๋ค. ํ ๋ฒ ๋ณํํ Mask๋ฅผ ์๋ ํฌ๊ธฐ๋ก ๋๋๋ฆฌ๊ธฐ ์ํด์์ธ๋ฐ, ์ด๋ฌํ ์์
์ ํตํด ์ํ๋ ๋
ธ์ด์ฆ๋ง ์ ๊ฑฐ๋ ๊ฒฐ๊ณผ๋ฅผ ์ป์ ์ ์์ต๋๋ค. ์์
์ ์งํํ๋ ์์์ ๋ฐ๋ผ ์๋ ๋ ๊ฐ์ง๋ก ๋๋ ์ ์์ต๋๋ค. Erosion\u0026rarr;Dilation์ ๊ฒฝ์ฐ Open(์ด๊ธฐ) Dilation์\u0026rarr;Erosion ๊ฒฝ์ฐ Close(๋ซ๊ธฐ) Open์ 1 ๊ฐ์ ๊ฐ๋ ๋
ธ์ด์ฆ๋ฅผ ์ค์ด๊ณ , Close๋ 0๊ฐ์ ๊ฐ๋ ๋
ธ์ด์ฆ๋ฅผ ์ค์ด๋๋ฐ ์ฌ์ฉ๋ฉ๋๋ค. ret, th = cv2.threshold(img, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU) kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (3, 3)) erosion = cv2.erode(th, kernel, iterations=1) dilation = cv2.dilate(th, kernel, iterations=1) opened = cv2.dilate(erosion, kernel, iterations=1) closed = cv2.erode(dilation, kernel, iterations=1) plt.subplot(221) plt.imshow(th, cmap='gray') plt.title('Binary Kitten') plt.subplot(223) plt.imshow(opened, cmap='gray') plt.title('Opened Kitten') plt.subplot(224) plt.imshow(closed, cmap='gray') plt.title('Closed Kitten') plt.suptitle('Binary Kitten with double morphology', size=15) plt.show() Gray Scale Image์๋ ๋์ผํ ์์
์ ์งํํ ์ ์์ต๋๋ค. gray_open = cv2.dilate(gray_erosion, kernel, iterations=2) gray_close = cv2.erode(gray_dilation, kernel, iterations=2) plt.subplot(221) plt.imshow(img, cmap='gray') plt.title('Gray Kitten') plt.subplot(223) plt.imshow(gray_open, cmap='gray') plt.title('Gray opened Kitten') plt.subplot(224) plt.imshow(gray_close, cmap='gray') plt.title('Gray closed Kitten') plt.suptitle('Gray Kitten with double morphology', size=15) plt.show() Conclusion Morphology Operation์ ์ฃผ๋ก Binary Image๋ก ์์ฑํ RoI Mask๋ฅผ ๋ค๋ฃจ๋๋ฐ ๋ง์ด ์ฐ์
๋๋ค. ๊ฐ์ธ์ ์ผ๋ก RoI Mask์ Denoising์ ๋งค์ฐ ์ ์ฉํ๊ฒ ์ฌ์ฉํ๊ณ ์๊ณ , Edge Detection ๋ฑ์ ์ฐ์ฐ๊ณผ ์ฐ๊ณํ๋ ๋ฑ ํ์ฉ ๋ฐฉ์์ด ์์ฃผ ๋ง์ผ๋ ๊ผญ ์ตํ๋์๋ ๊ฒ์ ์ถ์ฒ๋๋ฆฝ๋๋ค. Reference [1] ์ค์ผ์, \u0026ldquo;๋ชจํด๋ก์ง,\u0026rdquo; in ์ปดํจํฐ ๋น์ , vol.4, Republic of Korea:ํ๋น์์นด๋ฐ๋ฏธ, 2014, pp. 97-103 [2] Accessed: \u0026lsquo;Mathematical morphology\u0026rsquo;, Wikipedia. [Online]. Available: https://en.wikipedia.org/wiki/Mathematical_morphology ","date":1593479400,"expirydate":-62135596800,"kind":"page","lang":"en","lastmod":1593479400,"objectID":"db9e772e7f6e9f40621baead20d8c3ab","permalink":"/post/2020-06-30-morphology/","publishdate":"2020-06-30T10:10:00+09:00","relpermalink":"/post/2020-06-30-morphology/","section":"post","summary":"Morphology Operations using OpenCV","tags":[],"title":"[Tutorial] Morphology","type":"post"},{"authors":["young-kim","whi-kwon"],"categories":[],"content":" Basic image operation ์ด๋ฒ ์ฅ ์์๋ ์ด๋ฏธ์ง์ ๋ค์ํ ํจ๊ณผ๋ฅผ ์ค ์ ์๋ ์ด๋ฏธ์ง ์ฐ์ฐ ๋ฐฉ๋ฒ์ ๋ํ์ฌ ์์๋ณด๊ฒ ์ต๋๋ค. ์ด๋ฏธ์ง๋ก ํ ์ ์๋ ๊ธฐ๋ณธ ์ฐ์ฐ์ ์ด ๋ค ๊ฐ์ง๋ก ๋๋์ด์ ์ค๋ช
ํ๊ฒ ์ต๋๋ค. ๊ฐ๊ฐ์ ๊ธฐ๋ณธ ์ฐ์ฐ๋ค์ ์กฐํฉํด์ ํจ์ฌ ๋ ๋ง์ ํจ๊ณผ๋ฅผ ๋ผ ์ ์์ต๋๋ค. ๋ค ๊ฐ์ง ๊ธฐ๋ณธ ์ฐ์ฐ์ ์๋์ ๊ฐ์ต๋๋ค. Dot Operation Area Operation Geometric Operation Interpolation Import Libraries import os import sys import math from platform import python_version import cv2 import matplotlib.pyplot as plt import matplotlib import numpy as np print(\u0026quot;Python version : \u0026quot;, python_version()) print(\u0026quot;Opencv version : \u0026quot;, cv2.__version__) matplotlib.rcParams['figure.figsize'] = (4.0, 4.0) Python version : 3.6.9 Opencv version : 4.1.2 Data load sample_image_path = '../image/' sample_image = 'kitten.jpg' img = cv2.imread(os.path.join(sample_image_path, sample_image), cv2.IMREAD_GRAYSCALE) h, w = img.shape Data description ๋ณธ ์์ ์์ ์ฌ์ฉํ ๋ฐ์ดํฐ๋ ์๋์ ๊ฐ์ต๋๋ค. ๊ท์ฌ์ด ์๊ธฐ ๊ณ ์์ด ์
๋๋ค[7]. plt.imshow(img, cmap='gray') plt.title('Kitten') plt.show() Dot\u0026nbsp;operation Dot Operation์ด๋, Source Image์ Pixel๊ณผ Target Image์ Pixel๊ฐ์ 1:1 ์ฐ์ฐ์ ๋งํฉ๋๋ค. ์ด๊ฒ์ ์์์ผ๋ก๋ ์๋์ ๊ฐ์ด ํํํ ์๋ ์์ต๋๋ค. $pixel(i, j)_{after} = f(pixel(i, j)_{before})$ ์ฌ๊ธฐ์์ ๋ค์ ํจ์ $f$์ ๋ฐ๋ผ Affine[2] , Gamma[3] ์ฐ์ฐ์ผ๋ก ๋๋ ์ ์์ต๋๋ค. ์๋ ์ฝ๋๋ ๋ช ๊ฐ์ง Affine Operation ์์ ์
๋๋ค. bright_img = img + 50 bright_img[img \u0026gt; 155] = 255 dark_img = img - 50 dark_img[img \u0026lt; 100] = 0 reverse_img = 255 - img plt.figure(figsize=(8, 8)) plt.subplot(2, 2, 1) plt.imshow(img, cmap='gray') plt.title('Gray Kitten') plt.subplot(2, 2, 2) plt.imshow(bright_img, cmap='gray') plt.title('Bright Kitten') plt.subplot(2, 2, 3) plt.imshow(dark_img, cmap='gray') plt.title('Dark Kitten') plt.subplot(2, 2, 4) plt.imshow(reverse_img, cmap='gray') plt.title('Reversed Kitten') plt.suptitle('Kitten with affine transform.', size=15) plt.show() ์๋ ์ฝ๋๋ Gamma Correlation Operation ์์ ์
๋๋ค. bright_gamma = 0.5 dark_gamma = 1.5 bright_gamma_image = np.uint8(255 * np.power(img / 255, bright_gamma)) dark_gamma_image = np.uint8(255 * np.power(img / 255, dark_gamma)) plt.figure(figsize=(8, 8)) plt.subplot(2, 2, 1) plt.imshow(img, cmap='gray') plt.title('Gray Kitten') plt.subplot(2, 2, 3) plt.imshow(bright_gamma_image, cmap='gray') plt.title('Gamma Bright Kitten') plt.subplot(2, 2, 4) plt.imshow(dark_gamma_image, cmap='gray') plt.title('Gamma Dark Kitten') plt.suptitle('Kitten with gamma correlation transform.', size=15) plt.show() Gamma Correlation Transform๊ณผ Affine Transform์ด ๊ฐ๊ฐ Image์ ๋ผ์น๋ ์ํฅ์ด ์ด๋ค ์ฐจ์ด๊ฐ ์์๊น์? ๋ณํ๋ ๊ฐ Image์ Histogram์ ํ์ธํด๋ณด๋ฉด ์ฐจ์ด๋ฅผ ํ์คํ ์ ์ ์์ต๋๋ค. def histogram_cv(img): h, w = img.shape[:2] hist = cv2.calcHist([img], [0], None, [256], [0, 256]) hist = hist / (h * w) return hist plt.figure(figsize=(12, 8)) plt.subplot(2, 3, 1) plt.imshow(img, cmap='gray') plt.title('Kitten') plt.subplot(2, 3, 2) plt.imshow(bright_img, cmap='gray') plt.title('Affine bright Kitten') plt.subplot(2, 3, 3) plt.imshow(bright_gamma_image, cmap='gray') plt.title('Gamma bright Kitten ') plt.subplot(2, 3, 4) plt.plot(histogram_cv(img)) plt.title('Kitten Histogram') plt.subplot(2, 3, 5) plt.plot(histogram_cv(bright_img)) plt.title('Affine bright Kitten Histogram') plt.subplot(2, 3, 6) plt.plot(histogram_cv(bright_gamma_image)) plt.title('Gamma bright Kitten Histogram') plt.suptitle('Histogram comparison', size=15) plt.show() ์๋ Image์ ๋ณํ๋ Image๋ค์ Histogram ์
๋๋ค. Affine ๋ณํ์ ๊ฒฝ์ฐ ํฝ์
๊ฐ์ ์์๋ฅผ ๋ํ์ฌ ๋ฐ๊ฒ ๋ง๋ค๊ณ , ํฝ์
๊ฐ์ ์ต๋์น์ธ 255์ ๋๋ฌํ๋ฉด ๊ทธ๋ฅ 255์ ๋๋๋ ๋ฐ๋ฉด, Gamma Correlation ๋ณํ์ ๊ฒฝ์ฐ ํ์คํ ๊ทธ๋จ์ ๋ถํฌ ํํ๋ฅผ ์ด๋ ์ ๋ ์ ์งํ๋ฉฐ ๋ฐ์์ง๋ ๋ชจ์ต์ ํ์ธํ ์ ์์ต๋๋ค. ์ด ๋ ์ฐ์ฐ์ ์ฐจ์ด๋ ๊ทธ๋ฆผ๊ณผ ํ์คํ ๊ทธ๋จ์ ๊ฐ์ด ๋ณผ ๋ ๋ ํฌ๊ฒ ์ฒด๊ฐ์ด ๋ฉ๋๋ค. Affine Operation์ ์ ์ฉํ ๊ฒฝ์ฐ, ๊ฐ์ฅ ๋ฐ์ ๋ถ๋ถ๋ถํฐ ๋ญ๊ฐ์ง๋ ๋ฏํ ๋ชจ์ต์ธ ๋ฐ๋ฉด, Gamma Operation์ ์ ์ฉํ ๊ฒฝ์ฐ ์๋ ํํ๋ฅผ ์ ์งํ๋ฉฐ ๋ฐ์์ง๋ ๋ชจ์ต์
๋๋ค. Area\u0026nbsp;operation Area Operation์ด๋, Target Image์ ํ Pixel๊ฐ์ ๊ฒฐ์ ํ๊ธฐ ์ํด Source Image์ ์ฌ๋ฌ ๊ฐ์ Pixel๊ฐ์ ํ์๋ก ํ๋ ์ฐ์ฐ์ ๋งํฉ๋๋ค. Source Image์ ์ฌ๋ฌ Pixel๊ฐ๋ค์ ํน์ ๊ฐ์ค์น๋ฅผ ๋ถ์ฌํ๊ณ , Source Image์ ๊ฐ์ค์น์ ๊ณฑ์ ํฉ์ ๊ตฌํ์ฌ Target Image๋ฅผ ๊ตฌํ๋ ๋ฐฉ๋ฒ์ด ์ผ๋ฐ์ ์
๋๋ค. ์ฌ๊ธฐ์์ ํน์ ๊ฐ์ค์น๋ฅผ ๊ตฌํ ๋, ์ผ์ ํ ํฌ๊ธฐ์ Mask์๋ง ์ ํจํ ๊ฐ์ ๋ถ์ฌํ๊ณ ๋๋จธ์ง ์์ญ์๋ 0์ ๋ถ์ฌํ๊ณค ํฉ๋๋ค. ์ด๋ฌํ ์ฐ์ฐ์ Correlation, ํน์ Convolution์ด๋ผ๊ณ ํฉ๋๋ค. Correlation๊ณผ Convolution์ ์๋ฐํ ๋งํ๋ฉด ์๋ก ๋ค๋ฅธ ์ฐ์ฐ์ด๋, Image Processing์ ํน์ฑ์ ๊ฑฐ์ ๊ฐ์ ์ฐ์ฐ์ธ ๊ฒ์ผ๋ก ์๊ฐํ๊ณ ๋์ด๊ฐ๊ฒ ์ต๋๋ค. OpenCV์์ \u0026lsquo;cv2.filter2D()\u0026rsquo; ๋ฅผ ํตํด ์ฝ๊ฒ ์ ์ฉํ ์ ์๊ณ , ๋ช๋ช ์์ฃผ ์ฐ์ด๊ฑฐ๋ ํน๋ณํ ์ฐ์ฐ์ ๊ฒฝ์ฐ ๋ฐ๋ก ์ ์๋ ํจ์๊ฐ ์กด์ฌํ๊ธฐ๋ ํฉ๋๋ค. (e.g)Median Filter[4] ๋ \u0026lsquo;cv2.medianBlur(img,kernel)\u0026rsquo; ์ ํตํด ์ ๊ณต๋๋๋ฐ, ์ฃ์ง ์ ๋ณด๋ฅผ ์ ๋จ๊ฒจ๋๋ฉด์ ๋
ธ์ด์ฆ๋ฅผ ์ ๊ฑฐํ๋ ๋ฐฉ๋ฒ์ผ๋ก ์๋ ค์ ธ ์์ต๋๋ค. ์ด๋ ํ Mask๋ฅผ ์ฌ์ฉํ๋๋์ ๋ฐ๋ผ ๊ฒฐ๊ณผ ์์์ ํน์ฑ์ด ์ฒ์ฐจ ๋ง๋ณ๋ก ๋ฌ๋ผ์ง ์ ์์ต๋๋ค. ์๋ ์์์ค ์ํ, ์์ง๋ฐฉํฅ Edge๋ฅผ ๊ฐ๊ฐ ๊ตฌํ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค. ์์์์ ์ฌ์ฉ๋ Mask๊ฐ Sobel Filter์ ์ด๊ธฐ ๋ชจ๋ธ์ด๋ฉฐ, Edge Detection์์ ์์ธํ ๋ค๋ฃจ๊ฒ ์ต๋๋ค. Sharpen์ด๋ผ๋ ๊ธฐ๋ฒ์ ๋ฌผ์ฒด์ Edge๋ฅผ ๊ฐํ๊ฒ ๋๋ฌ๋ด๋ ๋ฐฉ๋ฒ์ค ํ๋ ์
๋๋ค. ์ ์ฐ์ฐ๋ค์ ์์ ๋งํ๋ค์ํผ ์์ ํ ๋ค๋ฅธ ๊ฒฐ๊ณผ๋ฅผ ๋ง๋ค์ง๋ง, ์ ์ฉํ๋ Mask๋ง ๋ค๋ฅผ ๋ฟ ๊ฐ์ ํจ์ ํธ์ถ์ ํตํด ๋ง๋ค์ด๋ธ ๊ฒฐ๊ณผ์์ ์ฃผ๋ชฉํฉ์๋ค. blur_mask = np.ones((3, 3), dtype=np.uint8) / 9 horiz_edge_mask = np.array([[1, 1, 1], [0, 0, 0], [-1, -1, -1]]) vert_edge_mask = np.array([[1, 0, -1], [1, 0, -1], [1, 0, -1]]) sharp_mask = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]]) dst1 = cv2.filter2D(img, -1, blur_mask) dst2 = cv2.filter2D(img, -1, horiz_edge_mask) dst3 = cv2.filter2D(img, -1, vert_edge_mask) dst4 = cv2.filter2D(img, -1, sharp_mask) dst4_blur = cv2.medianBlur(dst4, 3) plt.figure(figsize=(12,8)) plt.subplot(231) plt.imshow(dst1, cmap='gray') plt.title('Blurring') plt.subplot(232) plt.imshow(dst4, cmap='gray') plt.title('Sharpen') plt.subplot(233) plt.imshow(dst4_blur, cmap='gray') plt.title('Sharpen with Median') plt.subplot(234) plt.imshow(dst2, cmap='gray') plt.title('Horizontal edge') plt.subplot(235) plt.imshow(dst3, cmap='gray') plt.title('Vertical edge') plt.suptitle('Kitten with different operation', size=15) plt.show() Geometric\u0026nbsp;operation ์ธ ๋ฒ์งธ Geometric Operation์ ์์์ ์ด๋, ํฌ๊ธฐ, ํ์ , ๊ธฐ์ธ์ ๋ฑ์ ํจ๊ณผ๋ฅผ ์ฃผ๋ ๊ฒ์ ๋งํฉ๋๋ค. ๋ฌผ์ฒด์ ๊ธฐํํ์ ํน์ง์ด ํ๋ ฅ์ ์ผ๋ก ๋ณด์กด๋๋ ๋ณํ์
๋๋ค. ์ฐข๊ฑฐ๋ ๊ตฌ๊ธฐ๊ฑฐ๋ ํ๋ฆฟํ๊ฒ ๋ง๋ค๊ฑฐ๋ ํ์ง ์๊ณ , ๋ ๋๊ฐ ์ฌ์ด์ ์ฝ๊ฐ ์๋ค๋ ๋ฑ์ ํน์ฑ์ด ๊ธฐ์ธ์ด์ง๋ , ํ์ ํ๋ ๊ทธ๋๋ก ์ ์ง๋๋ค๋ ์๋ฏธ๋ก ๋ฐ์๋ค์ด์๋ฉด ๋ฉ๋๋ค. 4๊ฐ์ง ๊ธฐ๋ณธ์ ์ธ ์ฐ์ฐ์ ์์ฐจ์ ์ผ๋ก ์กฐํฉํ์ฌ ์ ๋ง์ ๋ณํ์ ์ํํ ์ ์์ต๋๋ค[5]. e.g. ํน์ ์ ์ ๊ธฐ์ค์ผ๋ก ํ์ , ์ข์ฐ ๋ฐ์ (Flip), ์์ ๋ณํ(Perspective transform) ๋ฑ OpenCV์์ ์ง์ํ๋ \u0026lsquo;cv2.getAffineTransform()\u0026rsquo;, \u0026lsquo;cv2.warpAffine()\u0026rsquo; ํจ์๋ฅผ ํตํด Geometric Operation์ ์ ์ฉํ ์ ์์ต๋๋ค. ์ฌ๊ธฐ์์ ํจ์ ์ด๋ฆ์ ๋ค์ด๊ฐ๋ Affine ๋๋ฌธ์ ํท๊ฐ๋ฆฌ๋ ๊ฒฝ์ฐ๊ฐ ์์ ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค. Dot Operation์์ ์๊ฐํ Affine Operation์ ๊ฐ๋ณ ํฝ์
๊ฐ ํ๋์ ๋ํ Affine์ฐ์ฐ์ด๋ฉฐ, ์ฌ๊ธฐ์์ ๋์จ Affine์ ์๋ฏธ๋ Image์ ์ ์ฒด ํฝ์
๋ค์ ๋ํ์ฌ ์ง์ญ์ ์ผ๋ก ์ ์ฉํ๋ Affine ์ฐ์ฐ์
๋๋ค. ์ด ๋์ ์ฐจ์ด๋, ์ด๋ค ํฝ์
์ ๋ํ์ฌ ๊ทธ \u0026lsquo;๊ฐ\u0026rsquo;์ ๋ฐ๊พธ๋๋, ํน์ ๊ทธ \u0026lsquo;์์น\u0026rsquo;๋ฅผ ๋ฐ๊พธ๋๋์ ๋ฐ๋ผ ๋๋๋ ๊ฒ์ผ๋ก ์๊ฐํ์๋ฉด ๋๊ฒ ์ต๋๋ค. pts1 = np.float32([[50, 50], [200, 50], [50, 200]]) pts2 = np.float32([[10, 100], [200, 50], [100, 250]]) M = cv2.getAffineTransform(pts1, pts2) dst1 = cv2.warpAffine(img, M, (w, h)) M = cv2.getRotationMatrix2D((w / 2, h / 2), -30, 1) dst2 = cv2.warpAffine(img, M, (w, h)) plt.figure(figsize=(12, 4)) plt.subplot(1, 3, 1) plt.imshow(img, cmap='gray') plt.title('Input') plt.subplot(1, 3, 2) plt.imshow(dst1, cmap='gray') plt.title('Affine') plt.subplot(1, 3, 3) plt.imshow(dst2, cmap='gray') plt.title('Rotation') plt.suptitle('Lena with geometric transform') plt.show() ๊ฐ๋จํ๊ฒ ๊ณ ์์ด Image๋ฅผ ๋คํ๊ณ , ํ์ ์์ผ๋ณธ ์์์
๋๋ค. ๊ฐ ํจ์์ ์์ธํ ์ฌ์ฉ๋ฒ์ OpenCV ๊ณต์ ๋ฌธ์[6]์์ ํ์ธํ ์ ์์ต๋๋ค. Interpolation Image์ ํฌ๊ธฐ๋ฅผ ๋ฐ๊พธ๋ ๊ฒฝ์ฐ(ํนํ ํ๋ํ ๋), ์๋ณธ Image์ ํฝ์
๊ณผ ํฝ์
์ฌ์ด์ ์๋ก์ด ๊ฐ์ด ์์ฑ๋๋ ๊ฒ์ด๋ฏ๋ก ์ด ์๋ก์ด ๊ฐ์ ์ด๋ป๊ฒ ์ฑ์์ผ ํ ์ง์ ๋ํ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๊ฒ ๋ฉ๋๋ค. ๋จ์ํ๊ฒ ํ ์ชฝ ํฝ์
๊ฐ์ ๊ทธ๋๋ก ๊ฐ์ ธ๋ค๊ฐ ์ ์ฉํ ๊ฒฝ์ฐ ์์์ด ์ค์ง์ ์ผ๋ก ํด์๋๊ฐ ์ปค์ง๋ ๊ฒ์ด ์๋๋ผ, ๋จ์ํ ํฌ๊ธฐ๋ง ํค์ฐ๋ ๊ฒ ์ด๋ผ๊ณ ๋ณผ ์ ์์ต๋๋ค. ์ด์ ๋ฐ๋๋ก (๋จธ์ ๋ฌ๋ ๋ฑ์ ๋ฐฉ๋ฒ ์์ด)๋ ์ข์ ํด์๋์ Image๋ฅผ ์ป๊ธฐ ์ํ์ฌ Interpolation์ ์ฌ์ฉํฉ๋๋ค. OpenCV๋ ๋ค์ํ Interpolation(๋ณด๊ฐ๋ฒ)์ ์ ๊ณตํ๋๋ฐ, \u0026lsquo;cv2.resize()\u0026rsquo; ํจ์์ ์ธ์ \u0026lsquo;interpolation\u0026rsquo; ์ผ๋ก ์กฐ์ ํ ์ ์์ต๋๋ค. \u0026lsquo;cv2.INTER_NEAREST\u0026rsquo; - ์ต๊ทผ์ ์ด์ ํฝ์
์ ๊ฐ์ ์ฌ์ฉํจ. (size์ ๋จ์ํ ํ๋) \u0026lsquo;cv2.INTER_LINEAR\u0026rsquo; - ์ ์ ํ ๋ณด๊ฐ (default ๊ฐ) \u0026lsquo;cv2.INTER_AREA\u0026rsquo; - ์์ญ์ ๋์ด์ ๊ธฐ๋ฐํ ๋ฐฉ๋ฒ. (์ฌ์ด์ฆ๋ฅผ ์ค์ผ ๋ ์ข์ ์ฑ๋ฅ) \u0026lsquo;cv2.INTER_CUBIC\u0026rsquo; - ์ 3์ฐจ ๋ณด๊ฐ : ์ ์ ํ ๋ณด๊ฐ๋ฒ ๋ณด๋ค 4๋ฐฐ ๋ง์ ์ ๋ณด๋ฅผ ํ์ฉ. \u0026lsquo;cv2.INTER_LANCZOS4\u0026rsquo; - Lanczos ๋ณด๊ฐ : ์ 3์ฐจ ๋ณด๊ฐ๋ฒ ๋ณด๋ค 4๋ฐฐ ๋ง์ ์ ๋ณด๋ฅผ ํ์ฉ. h, w = [int(x) for x in img.shape] face_img = img[h // 2 - 60 : h // 2 + 80, w // 2 - 110 : w // 2 + 30] h, w = [int (x) for x in face_img.shape] dst3 = np.zeros([h * 2, w * 2]) for i in range(h): for j in range(w): dst3[2 * i, 2 * j] = face_img[i, j] dst3[2 * i + 1, 2 * j + 1] = face_img[i, j] dst3[2 * i, 2 * j + 1] = face_img[i, j] dst3[2 * i + 1, 2 * j] = face_img[i, j] dst4 = cv2.resize(face_img, (w * 2, h * 2)) dst5 = cv2.resize(face_img, (w * 2, h * 2), interpolation=cv2.INTER_CUBIC) dst6 = cv2.resize(face_img, (w * 2, h * 2), interpolation=cv2.INTER_LANCZOS4) plt.figure(figsize=(4, 4)) plt.imshow(face_img, cmap='gray') plt.title('original') plt.show() plt.figure(figsize=(16, 16)) plt.subplot(2, 2, 1) plt.imshow(dst3, cmap='gray') plt.title('resize manual') plt.subplot(2, 2, 2) plt.imshow(dst4, cmap='gray') plt.title('resize bilinear') plt.subplot(2, 2, 3) plt.imshow(dst5, cmap='gray') plt.title('resize cubic') plt.subplot(2, 2, 4) plt.imshow(dst6, cmap='gray') plt.title('resize lanczos4') plt.show() ์๊ธฐ ๊ณ ์์ด์ ์ผ๊ตด๋ง ํ๋ํ Image๋ฅผ ํตํด Interpolation ๋ฐฉ๋ฒ์ ๋ฐ๋ฅธ Image ํ์ง ์ฐจ์ด๋ฅผ ํ์ธํด๋ณด๊ฒ ์ต๋๋ค. Manual Resize๋ Image์ Interpolation์ด ์ ์ฉ๋ Image์์ ํ์ง ์ฐจ์ด๋ ํ์คํ ๋๋ฌ๋ฉ๋๋ค. ๋๋จธ์ง Interpolation์ด ์ ์ฉ๋ Image๋ค์ ํ์ง์ ์ฌ๋ฌ๋ถ์ ๋์ผ๋ก๋ ํ์ธ ๊ฐ๋ฅํ์ ๊ฐ์? ์์ธํ ๋ณด์๋ฉด ๋ณด์ผ๊ฒ๋๋ค. Bilinear Interpolation์ ์๋ก์ด ํฝ์
์ ๊ฐ์ ๊ณ์ฐํ ๋ ์ ์์ ๋ ํฝ์
๋ง์ ๊ณ ๋ คํ๊ธฐ ๋๋ฌธ์ ๊ณ์ฐ๋์ด ๋ค์ ์ ์ ํธ ์
๋๋ค. Cubic, Lanczos4 ๋ฑ์ ๋ฐฉ๋ฒ๋ก ์ ๋ ๋ง์ ์ฃผ๋ณ ํฝ์
๋ค์ ๊ณ ๋ คํ๊ธฐ ๋๋ฌธ์ ์ผ๋ฐ์ ์ผ๋ก Bilinear๋ณด๋ค ๋ ๋์ ํ์ง์ ๊ฒฐ๊ณผ๋ฌผ์ ๋ณด์ฌ์ค๋๋ค. ์ฐ์ฐ ํจ์จ์ด ์ค์ํ ๊ฒฝ์ฐ์๋ bilinear interpolation์, ๊ฒฐ๊ณผ๋ฌผ์ ํ์ง์ด ์ค์ํ ๊ฒฝ์ฐ์๋ Cubic์ด๋ Lanczos4์ค์์ ์ ํํ์๋ฉด ๋ฉ๋๋ค. Conclusion Image์ ์ ์ฉํ๋ ๊ธฐ๋ณธ ์ฐ์ฐ๋ค์ ์์๋ณด์์ต๋๋ค. ์ํ๋ ํจ๊ณผ๋ฅผ ๋ด๊ธฐ ์ํด ๋ค์ํ ๋ฐฉ์์ผ๋ก ์ฐ์ฐ์ ์กฐํฉํด์ ๋์ผ๋ก ์ง์ ํ์ธํด๋ณด์๋ฉด ๋ง์ ๋์์ด ๋ ๊ฒ ์
๋๋ค. Reference [1] ์ค์ผ์, \u0026ldquo;์์ ์ฒ๋ฆฌ์ ์ธ ๊ฐ์ง ๊ธฐ๋ณธ ์ฐ์ฐ,\u0026rdquo; in ์ปดํจํฐ ๋น์ , vol.4, Republic of Korea:ํ๋น์์นด๋ฐ๋ฏธ, 2014, pp. 76-92 [2] Accessed: \u0026lsquo;Affine transformation\u0026rsquo;, Wikipedia. 2019 [Online]. Available: https://en.wikipedia.org/wiki/Affine_transformation [3] Accessed: \u0026lsquo;Gamma correction\u0026rsquo;, Wikipedia. 2019 [Online]. Available: https://en.wikipedia.org/wiki/Gamma_correction [4] Accessed: \u0026lsquo;Median filter\u0026rsquo;, Wikipedia. 2019 [Online]. Available: https://en.wikipedia.org/wiki/Median_filter [5] Accessed: \u0026lsquo;DenavitโHartenberg parameters\u0026rsquo;, Wikipedia. 2019 [Online]. Available: https://en.wikipedia.org/wiki/Denavit%E2%80%93Hartenberg_parameters [6] Accessed: \u0026lsquo;Geometric Image Transformations\u0026rsquo;, \u0026lsquo;OpenCV 2.4.13.7 documentation\u0026rsquo;. 2019 [Online]. Available: https://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html [7] Accessed: \u0026lsquo;Free Cat, Kitten Adoptions In Anne Arundel\u0026rsquo;, Patch. 2018 [Online]. Available: https://patch.com/maryland/annearundel/free-cat-kitten-adoptions-anne-arundel ","date":1593478800,"expirydate":-62135596800,"kind":"page","lang":"en","lastmod":1593478800,"objectID":"0795699c344e6fe9679e04ea4e40b01a","permalink":"/post/2020-06-30-basic_image_operation/","publishdate":"2020-06-30T10:00:00+09:00","relpermalink":"/post/2020-06-30-basic_image_operation/","section":"post","summary":"Image Operations using OpenCV","tags":[],"title":"[Tutorial] Basic Image Operation","type":"post"},{"authors":["kyunghwan-kim"],"categories":[],"content":" ๊ฐํํ์ต์ ํ๊ด ์ ํํ ์๋ฆฌ์ฆ ๊ฐํํ์ต์ ํ๊ด ์ ํํ (1) - ๋ก๋ด๊ณผ ์ฌํ๊ด ์ค์ฌ ์์ ๊ฐํํ์ต์ ํ๊ด ์ ํํ (2) - ๊ฐํํ์ต๊ณผ ์ ์ด ์ด๋ก ์ ๋น๊ต ๊ฐํํ์ต์ ํ๊ด ์ ํํ (3) - ์คํํ๊ฒฝ ๊ตฌ์ฑ๊ณผ ๊ฐํํ์ต ์๊ณ ๋ฆฌ์ฆ ์๊ฐ\nIntro ๊ฐํํ์ต์ผ๋ก ํน์ task๋ฅผ ํ์ตํ๊ธฐ ์ํด์๋ ์์ด์ ํธ๊ฐ ๋ ๊ฐํํ์ต ์๊ณ ๋ฆฌ์ฆ์ ์ ์ ํ๊ณ ์์ด์ ํธ๊ฐ ์ํธ์์ฉํ ํ๊ฒฝ์ ๊ตฌ์ฑํด์ผํฉ๋๋ค. ์ด๋ฒ ํฌ์คํธ์์๋ ์ ํฌ๊ฐ ๊ฐํํ์ต์ผ๋ก PCI ๋ก๋ด์ ์ ์ดํ๊ธฐ ์ํด ์ฌ์ฉํ ์๊ณ ๋ฆฌ์ฆ๊ณผ ํ๊ฒฝ์ ๋ํด ์๊ฐํ๊ฒ ์ต๋๋ค.\n ์คํ ํ๊ฒฝ ๊ตฌ์ฑ PCI ์์ ํ๊ฒฝ ํ๊ด ๋ชจํ์ ์ด์ฉํ ์คํ ํ๊ฒฝ ๊ตฌ์ฑ ์๊ณ ๋ฆฌ์ฆ ์ ์ On-policy vs Off-policy Human demo ํ์ฉ ์ vs ๋ฌด Discrete action vs Continuous action ํ์ต ๊ฒฐ๊ณผ ๋ง์น๋ฉฐ \n์คํ ํ๊ฒฝ ๊ตฌ์ฑ ๊ฐํํ์ต ์์ด์ ํธ(Agent)๋ ์๋ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ด ์ํ(state)์์์ ํ๋(action)์ ์ ํํ๊ณ ์ป๋ ๋ณด์(reward)์ ํตํด ํ์ตํฉ๋๋ค. ์ด๋ ์ํ์ ๋ณด์ ๋ฑ์ ์ ๋ณด๋ค์ ํ๊ฒฝ๊ณผ์ ์ํธ์์ฉ์ ํตํด ์ป์ต๋๋ค. ์ด๋ฌํ ํ์ต ํ๋ก์ธ์ค๋ฅผ ๊ทธ๋ฆผ์ผ๋ก ํํํ๋ฉด ์๋ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ต๋๋ค. ํ๊ฒฝ์ด ์ ๋๋ก ๊ตฌ์ฑ๋์ง ์์ผ๋ฉด ์ด๋ค ๊ฐํํ์ต ์๊ณ ๋ฆฌ์ฆ์ ์ฐ๋๋ผ๋ ์ ๋๋ก ํ์ตํ ์ ์์ต๋๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ๊ฐํํ์ต์์ ํ๊ฒฝ์ ์์ฃผ ์ค์ํ ๊ฐ๋
์
๋๋ค. ๊ฐํํ์ต์ ํ๊ฒฝ์ ์ฃผ๋ก ์ฐ๋ฆฌ๊ฐ ํ๊ณ ์ถ์ ๋ฌธ์ ๋ฅผ ์๋ฎฌ๋ ์ดํฐ๋ก ์ ์ํ์ฌ ๊ฐ์ ํ๊ฒฝ์ผ๋ก ๊ตฌ์ฑํ๋ ๋ฐฉ๋ฒ๊ณผ ํด๋น ๋ฌธ์ ๋ฅผ ์ค์ real world์์ ๋ฐ๋ณต ๊ฐ๋ฅํ ํํ๋ก ์คํ ํ๊ฒฝ์ ๊ตฌ์ฑํ๋ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค. ์ ํฌ๋ PCI์์์ ๊ฐ์ด๋์์ด์ด ์ ์ด ๋ฌธ์ ๋ฅผ ํ๊ณ ์ ํ๊ธฐ ๋๋ฌธ์ ์์ ๊ณผ์ ์ ๊ฐํํ์ต ์์ด์ ํธ๊ฐ ์ํธ์์ฉ ๊ฐ๋ฅํ ํ๊ฒฝ์ ํํ๋ก ๋ง๋ค ํ์๊ฐ ์์ต๋๋ค. ์ด๋ฅผ ์ํด PCI์ ๊ณผ์ ์ ์์๋ด
์๋ค.\n\n\nPCI ์์ ํ๊ฒฝ PCI ์์ ์์ ์์ ์๊ฐ ํ์์ ํ๊ด ๋ชจ์๊ณผ ํ์ฌ ๊ฐ์ด๋์์ด์ด์ ์์น๋ฅผ X-ray ์กฐ์ ์์์ ํตํด ๋ด
๋๋ค. ํ์ฌ ๋ณ๋ณ ์์น๊ฐ ์ด๋์ธ์ง, ์ ์ดํ๊ณ ์๋ ๊ฐ์ด๋์์ด์ด์ ๋ชจ์๊ณผ ์์น๊ฐ ์ด๋์ธ์ง ๋ฑ์ ์ ๋ณด๋ฅผ ๋ชจ๋ 2D ์ด๋ฏธ์ง๋ฅผ ํตํด ํ์ธํฉ๋๋ค. ์์ ์๋ ์ด๋ฏธ์ง ์ ๋ณด๋ฅผ ๋ฐํ์ผ๋ก ๊ฐ์ด๋์์ด์ด๋ฅผ ์ด๋ป๊ฒ ์์ง์ฌ์ผ ํ ์ง ํ๋จํฉ๋๋ค. ๊ฐ์ด๋์์ด์ด๋ฅผ ์์ง์ด๋ฉด ๋ค์ ์กฐ์ ์์์ด ๋ฐ๋๊ฒ ๋๊ณ ์์ ์๋ ์์์ ๋ณด๊ณ ๋ค์ ์์ด์ด๋ฅผ ์์ง์
๋๋ค. ์๋ จ๋ ์์ ์๋ ์ด๋ฌํ ๊ณผ์ ์ ๊ต์ฅํ ๋น ๋ฅด๊ฒ ์ํํ์ฌ ํ์์ ๋ณ๋ณ ๋ถ์๋ฅผ ์น๋ฃํฉ๋๋ค. ์ด๋ฐ ํ๋ก์ธ์ค๋ฅผ ์์ ๊ฐํํ์ต ํ๋ก์ธ์ค์ ๋ง๊ฒ ํํํ๋ฉด ๋ค์ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ต๋๋ค [1]. ์์ ์๋ ์์ด์ ํธ, ํ์์ ํ๊ด๊ณผ X-ray ์์ ์ฅ๋น๊ฐ ํ๊ฒฝ, X-ray ์กฐ์ ์์์ด ์ํ, ๊ฐ์ด๋์์ด์ด๋ฅผ ์์ง์ด๋ ๊ฒ์ด ํ๋์ด ๋ฉ๋๋ค.\n PCI ์์ ์ ๋ํ ์์ธํ ๋ด์ฉ์ ์ด์ ํฌ์คํธ์ธ ๊ฐํํ์ต์ ํ๊ด ์ ํํ (1) - ๋ก๋ด๊ณผ ์ฌํ๊ด ์ค์ฌ ์์ ์ ์ฐธ๊ณ ํ์๊ธฐ ๋ฐ๋๋๋ค.\n \n\nํ๊ด ๋ชจํ์ ์ด์ฉํ ์คํ ํ๊ฒฝ ๊ตฌ์ฑ ์ด์ ํฌ์คํธ์์ ์ธ๊ธํ ๊ฒ์ฒ๋ผ PCI ์์ ์ ๊ฐ์ด๋์์ด์ด์ ๋ง์ฐฐ, ์ฌ๋์ ํธํก, ์ฌ์ฅ์ ๋ฐ๋ ๋ฑ์ ์ด์ ๋ก ๋ชจ๋ธ๋ง์ด ๊ต์ฅํ ์ด๋ ต์ต๋๋ค. ๋ชจ๋ธ๋ง์ด ์ด๋ ต๋ค๋ ๊ฒ์ ๋ค์ ๋งํด ์๋ฎฌ๋ ์ดํฐ์ ๊ฐ์ ๊ฐ์ ํ๊ฒฝ์ผ๋ก ์ ์ํ๊ธฐ ์ด๋ ต๋ค๋ ๋ป์
๋๋ค. ๋ฐ๋ผ์ ์ ํฌ๋ ์๋ฎฌ๋ ์ดํฐ๋ณด๋ค๋ ํ๊ด ๋ชจํ์ ์ด์ฉํ real world ์คํ ํ๊ฒฝ์ ๊ตฌ์ฑํ์์ต๋๋ค. ์ค์ ์์ ์์ ์์ฌ๊ฐ X-ray ์ด๋ฏธ์ง๋ฅผ ๋ณด๊ณ ๊ฐ์ด๋์์ด์ด๋ฅผ ์ด๋ป๊ฒ ์ ์ดํ ์ง ํ๋จํ๋ฏ์ด ๊ฐํํ์ต ์์ด์ ํธ๋ 2D ํ๊ด ๋ชจํ์ ์ด๋ฏธ์ง๋ฅผ ๋ณด๊ณ ๊ฒฐ์ ํฉ๋๋ค. ๊ฒฐ์ ํ ์ ์ด ์ ํธ๋ฅผ PCI ๋ก๋ด์ผ๋ก ์ ๋ฌํ์ฌ ์ค์ ๊ฐ์ด๋์์ด์ด๋ฅผ ์ ์ดํ๊ฒ ๋ฉ๋๋ค. ์ด๋ฅผ ์์ ์์ ๊ณผ์ ํ๋ก์ธ์ค์ ๊ฐ์ด ํํํ๋ฉด ์๋ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ต๋๋ค. ๊ฐํํ์ต ์๊ณ ๋ฆฌ์ฆ์ด ์์ด์ ํธ, ๋ก๋ด๊ณผ 2D ํ๊ด ๋ชจํ์ด ํ๊ฒฝ, 2D ํ๊ด ๋ชจํ ์ด๋ฏธ์ง๊ฐ ์ํ, ๊ฐ์ด๋์์ด์ด ์ ์ด ๋ก๋ด์ ์์ง์ด๋ ๊ฒ์ด ํ๋์ด ๋ฉ๋๋ค. \n\n์๊ณ ๋ฆฌ์ฆ ์ ์ ์ด๋ ๊ฒ ๊ฐํํ์ต ์์ด์ ํธ๋ฅผ ํ์ต์ํค๊ธฐ ์ํ ํ๊ฒฝ์ด ์ค๋น๊ฐ ๋์์ต๋๋ค. ์ด์ ์์ด์ ํธ๊ฐ ์ํธ์์ฉํ ํ๊ฒฝ์ด ์ค๋น๊ฐ ๋์์ผ๋ ์ด์ ์ด๋ค ์์ด์ ํธ๋ฅผ ํ์ต์ํฌ ๊ฒ์ธ๊ฐ๋ฅผ ๊ฒฐ์ ํด์ผํฉ๋๋ค. ์ฆ, ์ด๋ค ๊ฐํํ์ต ์๊ณ ๋ฆฌ์ฆ์ ์ธ ์ง ๊ฒฐ์ ํด์ผํฉ๋๋ค. ํ์ฌ๊น์ง๋ ๊ต์ฅํ ๋ง์ ๊ฐํํ์ต ์๊ณ ๋ฆฌ์ฆ๋ค์ด ์ฐ๊ตฌ๋๊ณ ์๊ณ ๊ฐ ์๊ณ ๋ฆฌ์ฆ๋ค๋ง๋ค ํน์ฑ์ด ๋ค๋ฅด๊ณ ์ฅ๋จ์ ์ด ์๊ธฐ ๋๋ฌธ์ ์ ํฌ ํ๊ฒฝ์ ์ ํฉํ๊ณ ์ ํฌ๊ฐ ์คํํ๊ณ ์ ํ๋ ๋ฐฉํฅ๊ณผ ๋ง๋ ์๊ณ ๋ฆฌ์ฆ์ ์ ํํ ํ์๊ฐ ์์์ต๋๋ค. ์ฌ๋ฌ๊ฐ์ง ๊ณ ๋ ค์ฌํญ ์ค ์ ํฌ๊ฐ ํฌ๊ฒ ๊ณ ๋ฏผํ๋ ๋ถ๋ถ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.\n On-policy vs Off-policy Human demo ํ์ฉ ์ vs ๋ฌด Discrete action vs Continuous action \nOn-policy vs Off-policy On-policy์ Off-policy๋ ๊ฐํํ์ต์์ ๋ง์ด ์ธ๊ธ๋๋ ๋ด์ฉ ์ค ํ๋์
๋๋ค. ์ด ๋ ๊ฐ์ง ๊ฐ๋
์ ์ดํดํ๋ ค๋ฉด ๋ช ๊ฐ์ง ๊ฐํํ์ต์ ๊ฐ๋
๋ค์ ์์์ผํฉ๋๋ค.\n ์ ์ฑ
(Policy): ๊ฐํํ์ต์์ ์ ์ฑ
์ ์ด๋ค ์ํ๊ฐ ์ฃผ์ด์ก์๋ ํ๋์ ๋ํ ํ๋ฅ ๋ถํฌ๋ฅผ ๋งํฉ๋๋ค. ์ ์ฑ
์ ํ์ต์ ํตํด ์ฐ๋ฆฌ๊ฐ ์ํ๋ ๋ ์ข์ ์ ์ฑ
์ผ๋ก ๋ง๋ค ์ ์์ต๋๋ค. ๋ง์ฝ ํ์ฌ ์ ์ฑ
์ด ์ต์ ์ ์ ์ฑ
์ด๋ผ๋ฉด ์ด ์ ์ฑ
์ผ๋ก ๋ชจ๋ ์ํ์ ๋ํด์ ํ๋์ ํ์ ๋ ๊ฐ์ฅ ๋์ ๋์ ๋ณด์์ ๋ฐ๊ฒ ๋ฉ๋๋ค. ์๋ ์ด๋ฏธ์ง์์ ์ ์ฑ
์ ์์๋ฅผ ํํํ์์ต๋๋ค. ๊ฐ ๋ค๋ชจ์นธ์ด ์ํ์ด๊ณ ํ์ ๋ค๋ชจ์นธ์ด ๋ณด์์ ๋ฐ๋ ์ํ๋ผ๊ณ ํ๋ค๋ฉด $\\pi_4$๊ฐ ์ต์ ์ ์ ์ฑ
์ด๋ผ ํ ์ ์์ต๋๋ค. \n์๋ ์ด๋ฏธ์ง์์ ์ ์ฑ
์ ๋ค๋ฅธ ์์๋ฅผ ๋ณด์ฌ์ค๋๋ค. ๊ฐ ์ํฉ์์ ์บ๋ฆญํฐ๊ฐ ์ฃฝ์ง ์์ผ๋ ค๋ฉด ์ ํํ๋ ํ๋์ด ๊ฐ์ฅ ํ๋ฅ ์ด ๋์์ผํฉ๋๋ค. \n ์ด ์๋๋ถํฐ๋ ์ ์ฑ
์ด๋ผ๋ ๋จ์ด๋ณด๋ค policy๋ผ๋ ๋จ์ด๋ฅผ ์ฌ์ฉํ๋๋ก ํ๊ฒ ์ต๋๋ค.\n ๊ฒฝํ (Experience): ๊ฐํํ์ต ์๊ณ ๋ฆฌ์ฆ์ ํ์ตํ๊ธฐ ์ํด์๋ ํ๊ฒฝ๊ณผ ์ํธ์์ฉํด์ ์ป์ ์ํ์ ํ๋, ๋ณด์ ๋ฑ์ ๊ฒฝํ(experience)์ ์ป์ด์ผ ํฉ๋๋ค. ์ด๋ฌํ ๊ฒฝํ๋ค์ด ๊ฐํํ์ต์์์ ๋ฐ์ดํฐ๋ผ๊ณ ํ ์ ์์ต๋๋ค. On-policy๋ ํ์ตํ๋ policy์ ํ๋ํ๋ policy๊ฐ ๊ฐ์ ์๊ณ ๋ฆฌ์ฆ์ ๋งํฉ๋๋ค. ์ฆ, On-policy๋ ํ์ฌ ํ์ตํ๋ policy๋ฅผ ํตํด์ ์ป์ ๊ฒฝํ๋ง์ ์ด์ฉํด ํ์ตํ ์ ์์ต๋๋ค. ๋ค๋ฅธ policy๊ฐ ์ป์ ๊ฒฝํ ๋ฟ๋ง ์๋๋ผ ๊ณผ๊ฑฐ์ policy๋ก ์ป์ ๊ฒฝํ ๋ํ ์ฌ์ฉํ ์ ์์ต๋๋ค. Off-policy๋ ์ด์ ๋ฐ๋๋ก ํ์ตํ๋ policy์ ํ๋ํ๋ policy๊ฐ ๋ค๋ฅธ ์๊ณ ๋ฆฌ์ฆ์ ๋งํฉ๋๋ค. ํ์ฌ ํ์ตํ๊ณ ์๋ ์์ด์ ํธ๊ฐ ๊ณผ๊ฑฐ์ ๋ชจ์๋ ๊ฒฝํ ๋ฟ๋ง ์๋๋ผ ์ง๊ธ ํ์ตํ๊ณ ์๋ ์์ด์ ํธ์ ์์ ํ ๋ค๋ฅธ ์์ด์ ํธ๊ฐ ๋ง๋ ๊ฒฝํ๋ค๊น์ง๋ ํ์ต์ ์ฌ์ฉํ ์ ์์ต๋๋ค.\n๋ฅ ๊ฐํํ์ต ์๊ณ ๋ฆฌ์ฆ์์ on-policy์ off-policy๋ experience replay์ ์ฌ์ฉ ์ฌ๋ถ์์ ์ฐจ์ด๊ฐ ๋ฉ๋๋ค. Experience replay๋ ํ๊ฒฝ์ ํตํด ์ป์ ๊ฒฝํ๋ค์ ๋ฒํผ์ ์๊ณ batch ๋จ์๋ก ์ํ๋งํ์ฌ ํ์ตํ๊ธฐ ๋๋ฌธ์ off-policy ๋ฐฉ๋ฒ์ด๋ผ๊ณ ํ ์ ์์ต๋๋ค. ๋ฅ ๊ฐํํ์ต์์ on-policy๋ ๋ํ์ ์ผ๋ก TRPO [2], PPO [3]๊ฐ ์์ผ๋ฉฐ off-policy๋ DQN [4], DDPG [5]๊ฐ ์์ต๋๋ค. ์๋ ์ด๋ฏธ์ง๋ experience replay๋ฅผ ์ฌ์ฉํ๋ off-policy ์๊ณ ๋ฆฌ์ฆ์ ํ์ต ์ฌ์ดํด์ ์ค๋ช
ํฉ๋๋ค.\n\nPPO์ ๊ฐ์ On-policy ์๊ณ ๋ฆฌ์ฆ์ ์ด์ ๊ฒฝํ์ ์ฌ์ฉํ ์ ์๊ธฐ ๋๋ฌธ์ ํ์ฌ ๋ฐ์ดํฐ๋ฅผ ๋ง์ด ๋ชจ์ผ๊ธฐ ์ํด์ ์ฃผ๋ก ํ๊ฒฝ์ ๋ถ์ฐ์ฒ๋ฆฌ์ํค๋ ๋ฐฉ๋ฒ์ ์ฌ์ฉํฉ๋๋ค. ๊ทธ๋ ์ง ์์ผ๋ฉด ๊ณผ๊ฑฐ์ ๋ฐ์ดํฐ๋ฅผ ์ฌ์ฉํ ์ ์๊ธฐ ๋๋ฌธ์ off-policy์ ํ์ต ์๋์์ ์ฐจ์ด๊ฐ ๋๊ฒ ๋ฉ๋๋ค. ํ์ง๋ง ์ ํฌ๊ฐ ๊ตฌ์ถํ ํ๊ฒฝ์ ๊ฐ์ ์๋ฎฌ๋ ์ด์
ํ๊ฒฝ์ด ์๋ real world ํ๊ฒฝ์ด๊ธฐ ๋๋ฌธ์ ๋ถ์ฐ์ฒ๋ฆฌ ํ๊ฒฝ์ ๊ตฌ์ถํ๊ธฐ๊ฐ ์ด๋ ต์ต๋๋ค. 4๊ฐ์ ํ๊ฒฝ์ ๋ถ์ฐ์ฒ๋ฆฌ ํ๋ ค๋ฉด 4๊ฐ์ ๋ก๋ด๊ณผ ํ๊ด ๋ชจํ, ์นด๋ฉ๋ผ ์ธํธ๊ฐ ํ์ํ๊ธฐ ๋๋ฌธ์ด์ฃ . ์ด๋ฌํ ์ด์ ๋ก ์ ํฌ๋ real world ํ๊ฒฝ์์๋ off-policy ์๊ณ ๋ฆฌ์ฆ์ด ์ ํฉํ๋ค๊ณ ์๊ฐํ์์ต๋๋ค.\n\nHuman demo ํ์ฉ ์ vs ๋ฌด Off-policy ์๊ณ ๋ฆฌ์ฆ์ ํ์ฌ ํ์ตํ๊ณ ์๋ ์์ด์ ํธ๊ฐ ๋ชจ์ ๊ฒฝํ ๋ฟ๋ง์๋๋ผ ๋ค๋ฅธ ๊ฒฝํ ๋ํ ํ์ต ๋ฐ์ดํฐ๋ก ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ด๋ ์์ด์ ํธ๊ฐ ์๋ ์ฌ๋์ด ๋ง๋ ๊ฒฝํ๋ ๋ง์ฐฌ๊ฐ์ง์
๋๋ค. ๊ฐํํ์ต ์์ด์ ํธ๋ ํ์ต ์ด๊ธฐ์๋ ํ๊ฒฝ์ ํํํด๋ ๋ฌด์์ ํ๋๊ณผ ๊ฐ์ ์์ค์ ๊ฒฝํ๋ง์ ๋ชจ์ ์ ์์ต๋๋ค. ์ด๋ฌํ ๊ฒฝํ๋ค๋ ๋ฌผ๋ก ํ์ต์ ์ ์ฉํ ๊ฒฝํ๋ค์ด์ง๋ง ๋ฌด์์ ํ๋๋ง์ผ๋ก ํด๋น ํ๊ฒฝ์ ๋ชฉํ(goal)์ ๋๋ฌํ๋ ๊ฒฝํ์ ๋ง์ด ์ป๋ ๋ฐ์๋ ์ค๋ ์๊ฐ์ด ํ์ํฉ๋๋ค. ๊ทธ๋ฐ๋ฐ ๋ง์ฝ ์ด๋ฏธ ์๋ จ๋ ์ฌ๋์ด ๋ง๋ ๊ฒฝํ์ ํ์ต์ ์ฌ์ฉํ ์ ์๋ค๋ฉด ์ด๋จ๊น์? ํน์ ํ๊ฒฝ์ ์๋ จ๋ ์ฌ๋์ด ๋ง๋ ๊ฒฝํ์ ์์ด์ ํธ ์
์ฅ์์๋ ์๋ฒฝํ ์ด์์ ์ธ ๊ฒฝํ์ด ์๋ ์๋ ์์ง๋ง ์ ์ด๋ ํ์ต ์ด๊ธฐ์ ์์ด์ ํธ๋ณด๋ค๋ ํจ์ฌ ์ข์ ๊ฒฝํ์ผ ๊ฒ์
๋๋ค. ๋ํ ํ๊ฒฝ์ ๋ชฉํ(goal)์ ๋๋ฌํ๋ ๊ฒฝํ์ด๊ธฐ ๋๋ฌธ์ ๋ฌด์์๋ก ํํํ ๊ฒฝํ๋ง์ ์ด์ฉํด ํ์ตํ๋ ๊ฒ๋ณด๋ค ํจ์ฌ ๋น ๋ฅด๊ฒ ์์ด์ ํธ๋ฅผ ํ์ต์ํฌ ์ ์์ต๋๋ค. ์ด๋ฐ ์ฌ๋์ด ๋ง๋ ๊ฒฝํ์ human demonstration ์ด๋ผ๊ณ ํฉ๋๋ค.\n๊ฐํํ์ต์ human demo๋ฅผ ์ฌ์ฉํด์ ํ์ต ์ฑ๋ฅ์ ๋ํ๋ ค๋ ์ฐ๊ตฌ๊ฐ ๋ง์ด ๋๊ณ ์์ต๋๋ค [6, 7, 8]. ํนํ ์ ํฌ์ ํ๊ฒฝ์ real world ํ๊ฒฝ์ด๊ธฐ ๋๋ฌธ์ ๊ฐ์ ํ๊ฒฝ์ ๋นํด ํ๊ฒฝ์ ์์ ์ฑ์ ๋ณด์ฅํ๊ธฐ ์ด๋ ต์ต๋๋ค. ์๋ฅผ ๋ค์ด ์ฅ์๊ฐ ํ์ต์ ๋๋ฆฌ๋ค ๋ณด๋ฉด ๋ก๋ด์ ์ด์์ด ์๊ธฐ๊ฑฐ๋ ๊ฐ์ด๋์์ด์ด, ์นดํ
ํฐ์ ๊ฐ์ ์๋ฃ ๋๊ตฌ๋ค์ด ํ์๋์ด ๊ฐ์ ํ๋์ ํด๋ ๊ธฐ์กด๊ณผ๋ ๋ค๋ฅธ ๋์์ด ๋๋ ๊ฒฝ์ฐ๊ฐ ์๊น๋๋ค. ์ด๋ฅผ ๋ฐฉ์งํ๊ธฐ ์ํด์๋ ์ต๋ํ ํ์ต ์๋๋ฅผ ๋น ๋ฅด๊ฒ ํ๋ ๊ฒ์ด ์ค์ํฉ๋๋ค. ๋น ๋ฅธ ํ์ต์ด ํ๊ฒฝ์ ์์ ์ฑ์ ๋ํ๋ ๊ธธ์ธ ๊ฒ์ด์ฃ . ๋ฐ๋ผ์ ์ ํฌ๋ human demo๋ฅผ ํ์ฉํ ์๊ณ ๋ฆฌ์ฆ์ ์ฌ์ฉํ๊ธฐ๋ก ํ์์ต๋๋ค.\n\nDiscrete action vs Continuous action ๊ฐํํ์ต์์์ ํ๋์ Discrete action๊ณผ Continuous action์ผ๋ก ๋๋ ์ ์์ต๋๋ค. ์๊ณ ๋ฆฌ์ฆ์ ๋ฐ๋ผ ํน์ action space๋ ํ์ต์ด ์์ ๋ถ๊ฐ๋ฅํ ๊ฒฝ์ฐ๋ ์๊ธฐ ๋๋ฌธ์ ๊ฐํํ์ต ์๊ณ ๋ฆฌ์ฆ์ ์ ์ ํ ๋ ์ค์ํ ์์ธ ์ค ํ๋์
๋๋ค.\nDiscrete action Discrete ํ๊ฒ ๊ฒฐ์ ๋๋ ํ๋์ ๋งํฉ๋๋ค. ์ฆ, ์ค๊ฐ ๊ฐ์ด ์๊ณ 0 ๋๋ 1์ ๊ฐ์ ๊ฐ์ต๋๋ค. ์๋ฅผ ๋ค์ด, [์ ์ง, ํ์ง, ํ์ ] ์ด๋ผ๋ ํ๋์ด ์์ ๋ ์ ์ง ํ๋์ [1, 0, 0]๊ณผ ๊ฐ์ด ์ ํํฉ๋๋ค. ์ค๊ฐ ๊ฐ์ ์์ผ๋ฉฐ Discrete action์ผ๋ก ๋ค์ํ ํ๋์ ํํํ๋ ค๋ฉด ํ๋์ ๊ฐ์๋ฅผ ๋๋ ค์ผํฉ๋๋ค. ์์: [์ ์ง 1cm, ์ ์ง 2cm, ํ์ง 1cm, ํ์ง 2cm, ํ์ ] ์ฃผ๋ก Q learning๊ณผ ๊ฐ์ value-based ์๊ณ ๋ฆฌ์ฆ์ผ๋ก ํ์ตํฉ๋๋ค. Continuous action Continuous action์ ์ค์ ๊ฐ์ ๊ฐ์ง๋ฉฐ ๊ฐ์ ํฌ๊ธฐ๋ฅผ ํํํ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด, [์ /ํ์ง, ํ์ ] ์ด๋ผ๋ ํ๋์ด ์์ ๋ [0.3, 0.4]๊ณผ ๊ฐ์ด ์ /ํ์ง, ํ์ ๊ฐ์ ์ค์ ๊ฐ์ผ๋ก ์ง์ ํ ์ ์์ต๋๋ค. ํ๋ ๊ฐ์ ๋ฒ์๊ฐ ๋ฌดํํ๊ธฐ ๋๋ฌธ์ action space์ ํฌ๊ธฐ๊ฐ ํฝ๋๋ค. ์ฃผ๋ก Policy gradient์ ๊ฐ์ policy-based ์๊ณ ๋ฆฌ์ฆ์ผ๋ก ํ์ตํฉ๋๋ค. \n์ ํฌ๊ฐ ๊ตฌ์ฑํ ํ๊ด ๋ชจํ ํ๊ฒฝ์์ action space๋ฅผ ๊ฒฐ์ ํ๊ธฐ ์ํด ์ ํฌ๊ฐ ๊ณ ๋ คํ ์ฌํญ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.\n PCI ๋ก๋ด์ ๋์: ๊ธฐ๊ณ ๊ตฌ์กฐ์ ์ ์ง๊ณผ ํ์ ๋์์ ๋์์ ์กฐ์ํ ๊ฒฝ์ฐ ๊ฐ์ด๋์์ด์ด๊ฐ ์ดํํ๊ฑฐ๋ ๊ผฌ์ผ ์ํ์ด ์์. human demo ์ ์์ ์ฉ์ด์ฑ: ํค๋ณด๋ ์
๋ ฅ์ผ๋ก ์์ฝ๊ฒ human demo์ ์์ฑ์ด ๊ฐ๋ฅํด์ผํจ. ์ค๊ฐ ๊ฐ์ ํ์์ฑ: ํ๊ด ๋ชจํ ํ๊ฒฝ์์๋ ์ ์ง๊ณผ ํ์ ๊ฐ์ scale์ ๊ณ ์ ํ๋ ๊ฒ์ด ๋ ์ ๋ฆฌํ๋ค๊ณ ํ๋จํจ. ์ด์ธ์๋ ์ฌ๋ฌ ์ํฉ์ ๊ณ ๋ คํ์ ๋ ํ๊ด ๋ชจํ ํ์ต ํ๊ฒฝ์ discrete action์ผ๋ก ๊ตฌ์ฑํ์ฌ๋ ์ถฉ๋ถํ๋ค๊ณ ํ๋จํ์์ต๋๋ค.\n๋ฐ๋ผ์ off-policy + discrete action์ธ DQN์ ํ์ต ์๊ณ ๋ฆฌ์ฆ์ผ๋ก ์ ์ ํ์์ต๋๋ค. DQN์ ๋ง์ ์ฐ๊ตฌ๋ฅผ ํตํด ๊ธฐ์กด DQN์ ์ฌ๋ฌ ๋จ์ ์ ๋ณด์ํ ๋ค์ํ ๋ณํ DQN๋ค์ด ๋์๋๋ฐ ๊ทธ ์ค state-of-the-art๋ก ์๋ ค์ง Rainbow๋ฅผ ์ฌ์ฉํ๊ธฐ๋ก ํ์์ต๋๋ค. ์ถ๊ฐ๋ก human demo๋ฅผ ์ด์ฉํด ํ์ตํ๋ ์์ด๋์ด์ธ from demonstration(fD) ์๊ณ ๋ฆฌ์ฆ์ ๊ฒฐํฉํ์ฌ RainbowfD๋ก ์ต์ข
๊ฒฐ์ ํ์์ต๋๋ค [9].\n\nํ์ต ๊ฒฐ๊ณผ ์ ํฌ๊ฐ ํ๊ด ๋ชจํ ํ๊ฒฝ์ ๊ตฌ์ฑํ ํ๊ฒฝ๊ณผ ์์ด์ ํธ์ ์ต์ข
๋ชฉํ๋ ๋ก๋ด์ผ๋ก ๊ฐ์ด๋์์ด์ด๋ฅผ ์ ์ดํ์ฌ ์ํ๋ ์์น๊น์ง ์ด๋์ํค๋ ๊ฒ์ด์์ต๋๋ค. ์ด๋ฅผ ํ์ต์ํค๊ธฐ ์ํด ์ํ ์ด๋ฏธ์ง๋ฅผ ๋ค์ํ ์ปดํจํฐ ๋น์ ๊ธฐ์ ์ ์ด์ฉํด ์ ์ฒ๋ฆฌํ์์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ ๋ชฉํ(goal)๋ฅผ ์ํ ์ด๋ฏธ์ง์ ํ์ํด์ฃผ์ด ์์ด์ ํธ๊ฐ ๋ชฉํ๋ฅผ ๋ช
ํํ๊ฒ ์ ์ ์๋๋ก ํด์ฃผ์์ต๋๋ค.\n\n์ด๋ ๊ฒ ๊ตฌ์ฑํ ํ๊ฒฝ์์ ์ ์ ํ RainbowfD ์๊ณ ๋ฆฌ์ฆ์ ํตํด ํ์ต์ํจ ๊ฒฐ๊ณผ ๊ฐ์ด๋์์ด์ด๋ฅผ ์ํ๋ ์์น๊น์ง ์ฑ๊ณต์ ์ผ๋ก ์ ์ดํ์์ต๋๋ค! ํ์ต ๊ฒฐ๊ณผ๋ ์๋ ์์์ ํตํด ํ์ธํ ์ ์์ต๋๋ค.\n ์๋ ์์์ TCT 2019 ํํ์ ํฌ์คํฐ ์ธ์
์์ ๋ฐํํ ์์์
๋๋ค [10].\n \n\n๋ง์น๋ฉฐ ์ด๋ฒ ํฌ์คํธ์์๋ ๊ฐํํ์ต์ผ๋ก PCI์์์ ๊ฐ์ด๋์์ด์ด ์ ์ด๋ฅผ ํ์ตํ๊ธฐ ์ํ ๋ฐฉ๋ฒ์ ๊ตฌ์ฒด์ ์ผ๋ก ์๊ฐํ์์ต๋๋ค. ๊ฐํํ์ต์ผ๋ก ํน์ ๋ฌธ์ ๋ฅผ ํ๊ธฐ ์ํด์๋ ํ๊ฒฝ์ ๊ตฌ์ถํด์ผํ๊ณ , ํ๊ฒฝ๊ณผ ๋ฌธ์ ์ ๋ง๋ ๊ฐํํ์ต ์๊ณ ๋ฆฌ์ฆ์ ์ ํํด์ผํฉ๋๋ค. ์ด๋ฌํ ํ๊ฒฝ ๊ตฌ์ถ๊ณผ ์๊ณ ๋ฆฌ์ฆ ์ ์ ๊ณผ์ ์์ ์ ํฌ๊ฐ ํ๋ ๋ฐฉ์์ ์ค๋ช
ํ์์ต๋๋ค. ๊ฐํํ์ต์ ๋ณดํต ๊ฒ์์ด๋ ๊ฐ์ํ๊ฒฝ์์ ํ์ตํ ์์ ๋ ๋ง์ง๋ง ์ค์ ํ๊ฒฝ์ ์ ์ฉํ ์ฌ๋ก๋ ๋๋ญ
๋๋ค. ๋ค๋ฅธ ํ๊ฒฝ์ ๊ฐํํ์ต์ ์๋ํ๊ณ ์ ํ๋ ๋ถ๋ค์๊ฒ ์ ํฌ๊ฐ ์๋ํ๊ณ ๊ณ ๋ฏผํ๋ ๋ฐฉ์์ด ํ ๊ฐ์ง ์์๋ก์จ ๋ง์ ๋์์ด ๋๊ธฐ๋ฅผ ๋ฐ๋๋๋ค. ์ด๋ฒ ํฌ์คํธ๋ฅผ ๋์ผ๋ก ๊ฐํํ์ต์ ํ๊ด ์ ํํ ์๋ฆฌ์ฆ๋ ๋ง๋ฌด๋ฆฌ๋ฉ๋๋ค. ์ฐจํ ๋ค๋ฅธ ๋ด์ฉ์ผ๋ก ํฌ์คํธ ์ฌ๋ฆฌ๋๋ก ํ๊ฒ ์ต๋๋ค.\n ์ด ํฌ์คํธ๋ 2019๋
์ RL Korea์ ๋ชจ๋์ฝ์์ ๋ฐํํ \u0026ldquo;Rainbow์ ํ๊ด ์ ํํ\u0026rdquo; ๋ฐํ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์์ฑํ์์ต๋๋ค.\n Reference [1] CAG ์ด๋ฏธ์ง ์ถ์ฒ: https://www.researchgate.net/figure/CAG-images-of-the-first-PCI-a-Coronary-stenosis-in-the-proximal-mid-portion-of-LAD_fig1_316498381 [2] TRPO: Schulman, John et al., \u0026ldquo;Trust region policy optimization.\u0026rdquo; In International Conference on Machine Learning (ICML), 2015a. [3] PPO: J. Schulman et al., \u0026ldquo;Proximal Policy Optimization Algorithms.\u0026rdquo; arXiv preprint arXiv:1707.06347, 2017. [4] DQN: V. Mnih et al., \u0026ldquo;Human-level control through deep reinforcement learning.\u0026rdquo; Nature, 518(7540):529โ533, 2015. [5] DDPG: T. P. Lillicrap et al., \u0026ldquo;Continuous control with deep reinforcement learning.\u0026rdquo; arXiv preprint arXiv:1509.02971, 2015. [6] DQfD: T. Hester et al., \u0026ldquo;Deep Q-learning from Demonstrations.\u0026rdquo; arXiv preprint arXiv:1704.03732, 2017. [7] DDPGfD: Mel Vecerik et al., \u0026ldquo;Leveraging Demonstrations for Deep Reinforcement Learning on Robotics Problems with Sparse Rewards.\u0026rdquo; CoRR, 2017. [8] Behavior Cloning: A. Nair et al., \u0026ldquo;Overcoming Exploration in Reinforcement Learning with Demonstrations.\u0026rdquo; arXiv preprint arXiv:1709.10089, 2017. [9] Rainbow: M. Hessel et al., \u0026ldquo;Rainbow: Combining Improvements in Deep Reinforcement Learning.\u0026rdquo; arXiv preprint arXiv:1710.02298, 2017. [10] TCT 2019 Reinforcement learning for guidewire navigation in coronary phantom ํฌ์คํฐ ์๋ฃ: https://www.tctmd.com/slide/reinforcement-learning-guidewire-navigation-coronary-phantom ","date":1590627600,"expirydate":-62135596800,"kind":"page","lang":"en","lastmod":1590627600,"objectID":"7968452e8b7d31c89c6d04df7c0df54a","permalink":"/post/2020-05-28-adventure_of_rl_in_vessel_3/","publishdate":"2020-05-28T10:00:00+09:00","relpermalink":"/post/2020-05-28-adventure_of_rl_in_vessel_3/","section":"post","summary":"Introduction to guide-wire control for PCI by RL (3) - How to apply RL","tags":[],"title":"๊ฐํํ์ต์ ํ๊ด ์ ํํ (3) - ์คํํ๊ฒฝ ๊ตฌ์ฑ๊ณผ ๊ฐํํ์ต ์๊ณ ๋ฆฌ์ฆ ์๊ฐ","type":"post"},{"authors":["chaehyeuk-lee","kyunghwan-kim"],"categories":[],"content":" ๊ฐํํ์ต์ ํ๊ด ์ ํํ ์๋ฆฌ์ฆ ๊ฐํํ์ต์ ํ๊ด ์ ํํ (1) - ๋ก๋ด๊ณผ ์ฌํ๊ด ์ค์ฌ ์์ \n๊ฐํํ์ต์ ํ๊ด ์ ํํ (2) - ๊ฐํํ์ต๊ณผ ์ ์ด ์ด๋ก ์ ๋น๊ต\n๊ฐํํ์ต์ ํ๊ด ์ ํํ (3) - ์คํํ๊ฒฝ ๊ตฌ์ฑ๊ณผ ๊ฐํํ์ต ์๊ณ ๋ฆฌ์ฆ ์๊ฐ\nIntro ์ด๋ฒ ํฌ์คํธ์์๋ ์ ํฌ๊ฐ ์ PCI ๋ก๋ด ์ ์ด ๋ฐฉ๋ฒ์ผ๋ก ๊ฐํํ์ต์ ์ ํํ๊ฒ ๋์๋์ง ์๊ธฐํด๋ณด๊ณ ์ ํฉ๋๋ค. ์ด๋ฏธ ์๋ง์ ํ์์ ์์ง๋์ด๋ค์ด ๋ก๋ด์ ์ํ ํจ์จ์ ์ด๊ณ ๋ฐ์ด๋ ์ ์ด ์ด๋ก ๋ค์ ๊ฐ๋ฐํด์์ต๋๋ค. ์ด๋ฌํ ์ ์ด ์ด๋ก ๋ค์ด ์ด๋ ํ ์ ์์ ๊ฐํํ์ต๊ณผ ๋ค๋ฅธ์ง ์ดํด๋ณด๊ฒ ์ต๋๋ค. ๋จผ์ , ์ ์ด ์ด๋ก ์ค ๊ฐ์ฅ ๋ณดํธ์ ์ด๊ณ ๋๋ฆฌ ์ฐ์ด๋ PID ์ ์ด์์ ๋น๊ต๋ก ์์ํ๊ฒ ์ต๋๋ค.\n PID Control PID Control? Problem in PID Control Reinforcement Learning PID Control vs RL Optimal Control Optimal Control vs RL Model-free๋ฅผ ํฅํด Conclusion \nPID Control \nPID Control? PID ์ ์ด๋ Proportional-Integral-Derivative Control์ ์ฝ์์
๋๋ค. ํ์ฌ ์ฐ์
ํ์ฅ์ 80~90% ์ด์์ ์ ์ด๊ธฐ๋ ์ด PID์ ์ด ์ด๋ก ์ ์ด์ฉํ์ฌ ๋์์ ์ํํฉ๋๋ค. ๊ทธ ๋งํผ ์ด PID ์ ์ด์๋ ์ฅ์ ์ด ๋ง์ต๋๋ค. ๋จผ์ ์๊ณ ๋ฆฌ์ฆ์ด ์ฝ๋ 10์ค ์์ ๋๋ ์ ๋๋ก ๊ฐ๋ณ๊ณ , ์ฌ์ฉํ๊ธฐ ์ฌ์ฐ๋ฉฐ, ์ ์ด ์ฑ๋ฅ์ด ๋ฐ์ด๋ฉ๋๋ค. ํ์ง๋ง ์ด PID ์ ์ด๋ ๋จ์ํ ๋งํผ ํ๊ฐ์ง ๋ฌธ์ ์๋ง ์ง์คํฉ๋๋ค. ๋ฐ๋ก Tracking ๋ฌธ์ ์
๋๋ค.\n์๋ ์์ PID ์ ์ด๋ฅผ ํํํ๋ ๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ ์์
๋๋ค. ์๋ ์์ ์ดํด๋ณด๋ฉด, ์๊ฐ $t$์์์ ์ต์ข
์ถ๋ ฅ ${u}_t$๋ ๋ชฉํ ์ํ ${x}_g$์ ํ์ฌ ์ํ ${x}_t$์ ์ฐจ์ด, ${e}_t$์ ์ํด์ ๊ฒฐ์ ๋๋ ๊ฒ์ ์ ์ ์์ต๋๋ค. ์ฆ, PID ์ ์ด๋ ๋ชฉํ ์ํ์ ํ์ฌ ์ํ๋ฅผ ๊ฐ์ฅ ์ต๋จ๊ฑฐ๋ฆฌ๋ก ์๋ ๊ฒฝ๋ก ์์์๋ง ๋์ํฉ๋๋ค [1]. $${u}_t = {K}_p {e}_t + {K}_i \\int_0^t {e}_t dt + {K}_d d{e}_t/dt$$\n๊ทธ๋ฆผ๊ณผ ํจ๊ป ์ข ๋ ์์ธํ ์ด์ผ๊ธฐํด๋ณด๊ฒ ์ต๋๋ค. ์๋ ๊ทธ๋ฆผ์ ๋ชฉํ ์์น ${x}_g$์ ํ์ฌ ์์น ${x}_t$๊ฐ ์์ต๋๋ค. PID์ ์ด๋ฅผ ์ด์ฉํ๋ฉด, ${l}_1$๊ณผ ๊ฐ์ ๊ฒฝ๋ก๋ก ํ์ฌ ์ํ๊ฐ ์ด๋ํ๊ฒ ๋ฉ๋๋ค. ์ ์ด๊ธฐ ์ค๊ณ์ ๋ฐ๋ผ์ ์๋๊ฐ ๋๋ ค์ง๊ฑฐ๋ ๋นจ๋ผ์ง ์๋, ๋ชฉํ ์ง์ ์ ๋์ด๊ฐ ์๋ ์์ต๋๋ค. ํ์ง๋ง ์ง์ ${l}_1$์์ ๋ฒ์ด๋์ง๋ ์์ต๋๋ค. ์์ธก ๋ถ๊ฐ๋ฅํ ์ธ๋์ผ๋ก ์ธํด ${x}_2$๋ ${x}_3$์ ๊ฐ์ด ๊ฒฝ๋ก์์ ๋ฒ์ด๋ ์ ์์ต๋๋ค. ํ์ง๋ง PID ์ ์ด๊ธฐ๋ ๊ทธ ๊ฒฝ๋ก์์ ๋ฒ์ด๋ ํ์ฌ ์ํ๋ก๋ถํฐ ๋ค์ ์ง์ ${l}_2$์ ๋ง๋ค๊ณ , ๊ทธ ์ง์ ์ ๋ฐ๋ผ ์์ง์ด๋ ค๊ณ ํฉ๋๋ค. ์ฆ ๋ชฉํ ์ง์ ์ด ๋ฐ๋์ง ์๋ ํ, ํ์ฌ ์ํ๊ฐ ์์ง์ด๋ ๊ฒฝ๋ก๋ ๋ฐ๋์ง ์์ต๋๋ค. \n๋ฐ๋ผ์ PID์ ์ด๋ฅผ ์ด์ฉํ์ฌ ๋ณต์กํ ์์คํ
์ ์ ์ดํ๊ธฐ ์ํด์๋, ์ํ์ ๋ฐ๋ผ ๋ชฉํ ์ง์ ์ ๋ณ๊ฒฝํด์ฃผ๋ ์๊ณ ๋ฆฌ์ฆ, ์ฆ ๊ฒฝ๋ก๋ฅผ ์์ฑํด์ฃผ๋ ์๊ณ ๋ฆฌ์ฆ์ด ์ถ๊ฐ๋ก ํ์ํฉ๋๋ค. ํ๋์ ์๋ก ์๋์ ๊ฐ์ ๋จ์ํ ๋ก๋ดํ์ ์๊ฐํด๋ณด๊ฒ ์ต๋๋ค. ๋ก๋ดํ์ด ๋ชฉํ ์ง์ ์ ํฅํด ์์ง์ผ ๋, ๋ก๋ด ํธ๋๊ฐ ์ง์ ์ผ๋ก ์์ง์ด๋ ค๋ฉด 1๋ฒ ์ถ๊ณผ 2๋ฒ ์ถ์ ์๋ก ๋ค๋ฅธ ๋ฐฉํฅ์ผ๋ก ์์ง์ฌ์ผํฉ๋๋ค. ์ด ๊ฐ ์ถ์ ์์ง์ด๋ ๋ฐฉํฅ๊ณผ ์๋, ์ฆ ์ต์ ๊ฒฝ๋ก๋ ๊ธฐ๊ตฌํ์ด๋ผ๋ ์ถ๊ฐ์ ์ธ ์๊ณ ๋ฆฌ์ฆ์ ์ด์ฉํ์ฌ ์์ฑํด์ผ ํฉ๋๋ค. \n\nProblem in PID Control ์ด์ฒ๋ผ PID ์ ์ด๋ฅผ ์ ์ฉํ๊ธฐ ์ํด์๋, ๊ฒฝ๋ก๋ฅผ ์ฐพ๋ ๋ฌธ์ ๋ฅผ ๋จผ์ ํ์ด์ผํฉ๋๋ค. ๋ฌธ์ ๋ ๊ฐ์ด๋์์ด์ด์ ์ต์ ๊ฒฝ๋ก๋ฅผ ์ฐพ๋ ์ผ์ด ๋งค์ฐ ์ด๋ ต๋ค๋ ๊ฒ์
๋๋ค.\n๊ฐ์ด๋์์ด์ด ๋ก๋ด ์ ์ด์ ๊ฐ์ฅ ํฐ ๋ฌธ์ ์ค ํ๋๋, ๊ฐ์ด๋์์ด์ด๊ฐ ์ด๋ ํ ๊ฒฝ๋ก๋ก ์์ง์ฌ์ผ ๋ชฉํ ์ง์ ๊น์ง ๋๋ฌํ ์ ์๋์ง ์ง๊ด์ ์ผ๋ก ์๊ธฐ ์ด๋ ต๋ค๋ ๊ฒ์
๋๋ค. ๋จ์ํ๊ฒ ์๊ฐํ๋ฉด ๊ฐ์ด๋์์ด์ด๊ฐ ํ๊ด์ ์ค์ฌ์ ์ ๋ฐ๋ผ ์์ง์ด๋ฉด ๋๋ ๊ฒ์ฒ๋ผ ๋ณด์
๋๋ค. ํ์ง๋ง ์ค์ ๋ก๋ ๊ฐ์ด๋์์ด์ด์ ์นด๋ฐํฐ ์ฌ์ด์ ๋ง์ฐฐ, ํ๊ด ๋ด๋ฒฝ๊ณผ์ ๋ง์ฐฐ ๋ฑ์ผ๋ก ์ธํด ์ค์ฌ์ ๋ง ๋ฐ๋ผ๊ฐ์๋ ๋ชฉํ๊น์ง ๋๋ฌํ ์ ์์ต๋๋ค.\n์๋ ๊ทธ๋ฆผ์ ์ ํฌ๊ฐ ์ํํ ์คํ ์ค ํ๋๋ก, ํ ๊ฐ์ ๋ถ์ง ํ๊ด์ ํต๊ณผํ๊ธฐ ์ํด ๊ฐ์ด๋์์ด์ด๊ฐ ์ ํํ ๊ฒฝ๋ก๋ฅผ ๋ณด์ฌ์ค๋๋ค [2]. ๊ทธ๋ฆผ์ ๋ณด์๋ฉด ๊ฐ์ด๋์์ด์ด์ ๊ฒฝ๋ก๋ ์ค์ฌ์ ์ด ์๋๋ผ, ๋๋ถ๋ถ ํ๊ด ๋ฒฝ์์ ๋ฒฝ์ผ๋ก ์ด๋ํ๋ฉฐ ์๋น ๋ถ๋ถ ๋ง์ฐฐ๋ ฅ์ ์ด์ฉํด ์์ง์ด๋ ๊ฒ์ ์ ์ ์์ต๋๋ค. ์ด๋ฌํ ๊ฒฝ๋ก๋ ์ํ์ ์ธ ๋ฐฉ๋ฒ์ด๋ ์ง๊ด์ผ๋ก ๊ตฌํด๋ด๊ธฐ ๋งค์ฐ ์ด๋ ต์ต๋๋ค. ๋ฐ๋ผ์ ์ต์ ๊ฒฝ๋ก๋ฅผ ์ฝ๊ฒ ๋ง๋ค์ด๋ผ ์ ์๊ณ , ์ต์ ๊ฒฝ๋ก๋ฅผ ์ป์ด๋ผ ์ ์๋ค๋ฉด PID ์ ์ด๋ฅผ ์ ์ฉํ๊ธฐ ์ด๋ ต์ต๋๋ค. \n\nReinforcement Learning ๊ฐํํ์ต์ ์ด๋ฌํ ๋ฌธ์ ๋ฅผ ํธ๋๋ฐ ์ต์ ํ๋์ด ์์ต๋๋ค. ์ฌ์ค ๊ฐํํ์ต๊ณผ PID ์ ์ด๋ ๋์ผ์ ์์์ ๋น๊ตํ๋ ๊ฒ์ด ๋ถ๊ณตํํ ์๋ ์์ต๋๋ค. ๋ ์๊ณ ๋ฆฌ์ฆ์ด ๊ฐ๊ฐ ๋ชฉํํ๋ ๋ฐ๊ฐ ๋ค๋ฅด๊ธฐ ๋๋ฌธ์
๋๋ค. PID ์ ์ด๋ ์์์ ๋ง์๋๋ ธ๋ฏ์ด Tracking์ ์ต์ ํ๋์ด ์๊ณ , ๊ฐํํ์ต์ ์ต์ ๊ฒฝ๋ก๋ฅผ ์ฐพ๋ ๊ฒ์ ์ต์ ํ๋์ด ์์ต๋๋ค.\n๊ฐํํ์ต์ด ๋ชฉํ๋ก ํ๋ ๊ฒ์ agent๊ฐ ๊ฐ ์ํ(state)์์ ๋ณด์(reward)์ ์ต๋๋ก ํ๋ ํ๋(action)์ ํ๋ ๊ฒ์
๋๋ค. ์ด๋ฌํ ๋ชฉํ๋ฅผ ๋ฌ์ฑํ๊ธฐ ์ํด ๊ฐ ์ํ์์ ์ด๋ค ํ๋์ ์ ํํ๋ ๊ฒ์ด ์ข์์ง ๊ฒฝํ์ ํตํด ํ๋จํฉ๋๋ค. ์ด๋ฌํ ๊ฒฝํ์ ํตํ ํ๋จ์ ์ ์ฑ
(policy)์ด๋ผ๊ณ ํ๋ฉฐ, agent๋ ํ๊ฒฝ๊ณผ ์ํธ์์ฉํ๋ฉฐ ์ป๋ ๋ณด์์ ์ต๋๋ก ํ๋ ๋ฐฉํฅ์ผ๋ก ์ ์ฑ
์ ์
๋ฐ์ดํธ ํด๋๊ฐ๋๋ค. ์ฆ ๊ฐํํ์ต agent๋ ๋ฌธ์ ์ ๋ํ ์ต์ ์ ์ ์ฑ
์ ์ฐพ๊ฒ ๋๊ณ ์ด๋ ๊ณง ์ต์ ๊ฒฝ๋ก๋ฅผ ์ฐพ๋ ๊ฒ๊ณผ ๊ฐ์ต๋๋ค.\n\nPID Control vs RL ์ง๊ธ๊น์ง ์ PID ์ ์ด๋ก๋ PCI ๋ก๋ด์ ์ ์ดํ๊ธฐ ์ด๋ ค์ด์ง ์์๋ณด์์ต๋๋ค. ์ด ๋ ์๊ณ ๋ฆฌ์ฆ์ ์ฐจ์ด๋ ๊ฒฐ๊ตญ ์ต์ ๊ฒฝ๋ก๋ฅผ ๋ง๋ค์ด๋ผ ์ ์๋๊ฐ ์๋๊ฐ์ ์ฐจ์ด์
๋๋ค. ๊ฐํํ์ต์ ๋ณ๋ณ๋ถ์๊น์ง ๊ฐ์ด๋์์ด์ด๋ฅผ ์ด๋์ํค๋ ์ต์ ์ ๊ฒฝ๋ก๋ฅผ ์ฐพ๋ ๊ฒ์ด ๊ฐ๋ฅํ์ง๋ง, PID ์ ์ด๋ก๋ ๊ทธ ๊ฒฝ๋ก๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค. ๊ทธ์ ๊ฒฝ๋ก๋ฅผ ๋ฐ๋ผ๊ฐ ๋ฟ์
๋๋ค.\nํ์ง๋ง ๋
์๋ถ๋ค๊ป์๋ ์ฌ๊ธฐ์ ์๋ฌธ์ ์ ๊ธฐํ์ค ์ ์์ต๋๋ค. ์๋ํ๋ฉด ๊ธฐ์กด ์ ์ด์ด๋ก ์๋ ์ต์ ๊ฒฝ๋ก๋ฅผ ์ฐพ๋ ์๊ณ ๋ฆฌ์ฆ์ด ์๊ธฐ ๋๋ฌธ์
๋๋ค. ์ด๋ ์ต์ ์ ์ด (Optimal Control)์ด๋ผ๋ ์ด๋ก ์
๋๋ค. ์๋๋ถํฐ๋ ์ด ์ต์ ์ ์ด ์ด๋ก ์ด ๊ฐํํ์ต๊ณผ ์ด๋ป๊ฒ ๋ค๋ฅธ์ง, ์ ์ ํฌ๋ ์ต์ ๊ฒฝ๋ก๋ฅผ ์ํ ๋ ์๊ณ ๋ฆฌ์ฆ ์ค์์๋ ๊ฐํํ์ต์ ์ ํํ๊ฒ ๋์๋์ง ์ด์ผ๊ธฐํด๋ณด๊ฒ ์ต๋๋ค.\n\nOptimal Control \nOptimal Control vs RL ๊ฐํํ์ต๊ณผ ์ต์ ์ ์ด๋ ๋ชจ๋ ์ต์ ๊ฒฝ๋ก๋ฅผ ์ฐพ๊ธฐ ์ํ ์๊ณ ๋ฆฌ์ฆ์
๋๋ค. ๋ชฉ์ ์ด ๊ฐ์ ๋งํผ ๋ ์๊ณ ๋ฆฌ์ฆ์ ๋ง์ ๋ฉด์์ ์ ์ฌํ ๋ชจ์ต์ ๋ณด์
๋๋ค. ์ค์ ๋ก ๊ฐํํ์ต์ ์๋ฒ์ง๋ผ๊ณ ๋ถ๋ฆฌ๋ Richard S. Sutton ๊ต์๋ ์ต์ ์ ์ด์ ํ ๋ถ๋ถ์ผ๋ก์ ๊ฐํํ์ต์ ํ์ฉํ๋ ๊ฒ์ ์ ์ํ๊ธฐ๋ ํ์ต๋๋ค [3].\n๋จผ์ ๊ฐํํ์ต๊ณผ ์ต์ ์ ์ด์ ๊ณตํต์ ๋ถํฐ ์ดํด๋ณด๊ฒ ์ต๋๋ค. ๊ฐํํ์ต๊ณผ ์ต์ ์ ์ด ๋ชจ๋ ๋ค์ํ ์ด๋ก ๋ค์ด ์๊ฐ๋์ด ์์ต๋๋ค. ์ด ๊ธ์์๋ ๊ฐํํ์ต์ ๊ธฐ์ด ์ด๋ก ์ค ํ๋์ธ Dynamic Programming๊ณผ, ๊ฐ์ฅ ๋ํ์ ์ธ ์ต์ ์ ์ด์ด๋ก ์ค ํ๋์ธ LQR Control (Linear Quadratic Regulator)์ ๋น๊ตํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค [4][5]. ๊ฐํํ์ต๊ณผ ์ต์ ์ ์ด๋ ์ฉ์ด์ ๊ณ์ฐํ๋ ๊ณผ์ ๋ง ์กฐ๊ธ ์ฐจ์ด๊ฐ ์์ ๋ฟ, ๊ฑฐ์ ๋์ผํ ๊ฐ๋
๊ณผ ๊ตฌ์กฐ๋ฅผ ๊ฐ๊ณ ์์ต๋๋ค. ๋ ๋ฐฉ๋ฒ ๋ชจ๋ 1) ๋ชจ๋ธ๋ง, 2) ๋ชฉ์ ํจ์ ๊ฒฐ์ , 3) ์ ์ฑ
๊ฒฐ์ , 4) ์ต์ ํด ๊ณ์ฐ์ 4๊ฐ ๋จ๊ณ๋ฅผ ์ด์ฉํ์ฌ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํฉ๋๋ค.\n์์๋ฅผ ์ํด ์๋ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ ๋ฌธ์ ๋ฅผ ๊ฐ์ ํ๊ฒ ์ต๋๋ค. ์๋์ฐจ๊ฐ ๋ชฉ์ ์ง Goal๊น์ง ์ฅ์ ๋ฌผ์ ํผํ์ฌ ์ต๋ํ ๋นจ๋ฆฌ ๋๋ฌํ๋ ๊ฒ์ด ๋ชฉํ์
๋๋ค. \nStep 1. ๋ชจ๋ธ๋ง ๋ชจ๋ธ์ ๋ก๋ด ํน์ agent๊ฐ ์ด๋ ํ ๋์์ ์ทจํ์ ๋, agent์ ์ํ๋ ํ๊ฒฝ์ด ์ด๋ป๊ฒ ๋ณํ๊ณ ๋ฐ์ํ ์ง๋ฅผ ์ํ์ ์ผ๋ก ๋ํ๋ธ ๊ฒ์
๋๋ค. ์ต์ ๊ฒฝ๋ก ํ์์ ์ ํํ๋ฉด์๋ ํด๋ฅผ ์ฐพ์ ์ ์๋ ๋ชจ๋ธ์ ๋ง๋๋ ๊ฒ์์๋ถํฐ ์์ํฉ๋๋ค.\n Dynamic Programming : ๋ณธ ๊ธ์์๋ ํธ์๋ฅผ ์ํ์ฌ Dynamic Programming์์๋ Grid ํ๊ฒฝ์ ๊ฐ์ ํฉ๋๋ค. Grid ํ๊ฒฝ์์๋ ์ธ์ ํ Grid ๊ฐ์ ์ด๋ํ๋ฅ ์ธ ์ํ์ ์ดํ๋ฅ $p$๋ก ํ๊ฒฝ์ด ๋ชจ๋ธ๋ง ๋ ์ ์์ต๋๋ค. ํ์ฌ ์ํ๊ฐ $s$์ด๊ณ , ์ฌ๊ธฐ์ ํ๋ $a$๋ฅผ ์ทจํ์ ๋, ์ํ์ ์ดํ๋ฅ $p$์ ์ํด ๋ค์ ์ํ $s\u0026rsquo;$๊ฐ ๊ฒฐ์ ๋ฉ๋๋ค. ์ด ๋ ๋ฐ์ํ๋ ๋ณด์(reward) $r$ ๋ํ ๋ชจ๋ธ์ ์ํด ์ ์๋ฉ๋๋ค. $$ p(s\u0026rsquo;,r|s,a) = Pr({S}_t=s\u0026rsquo;, {R}_t = r | {S}_{t-1}=s, {A}_{t-1}=a) $$ \n LQR Control : LQR ์ ์ด์์๋ ์๋์ ๊ฐ์ ์ํ ๊ณต๊ฐ ๋ฐฉ์ ์์ด๋ผ๋ ๋ฐฉ๋ฒ์ ์ด์ฉํ์ฌ ํ๊ฒฝ์ ๋ชจ๋ธ๋ง ํฉ๋๋ค. ์ํ ๊ณต๊ฐ ๋ฐฉ์ ์์ ์ฃผ๋ก ๋์ญํ ํด์์ ํตํด ์ด๋ฃจ์ด์ง๋๋ค. $x$๋ ์๋์ฐจ์ ์ํ๋ฅผ ํํํ๊ณ , $u$ ์๋์ฐจ์ ํ๋, ์ฆ ์ ์ด ์
๋ ฅ์ ์๋ฏธํฉ๋๋ค. $A$๋ ํ๊ฒฝ์ ๊ด์ฑ, ๋ง์ฐฐ ๋ฑ ์๋์ฐจ์ ํ๊ฒฝ์ ๋์ญํ ํน์ฑ์ ๋ํ๋
๋๋ค. $B$๋ ์ ์ด ์
๋ ฅ์ด ์ด๋ป๊ฒ ์์คํ
์ ์ ์ฉ๋๋์ง ํํํฉ๋๋ค. ์ฐ๊ณผ ๊ฐ์ ์ฅ์ ๋ฌผ์ ๊ฐ๊น์ด ๊ฐ์ ๋ ์ค๋ ฅ์ ์ํฅ์ด ์ปค์ง๋ ํํ๋ก ๋ชจ๋ธ๋งํ๊ฑฐ๋, ์์ ์ฐ์ ์์น์ ๋๋ฌํ์ง ๋ชปํ๋๋ก constraint ์กฐ๊ฑด $[{x}_{m,1}, {x}_{m,2}]$์ ์ด์ฉํ์ฌ ํํํ ์ ์์ต๋๋ค. $ \\dot{x} = Ax + Bu $ subject to $ 0\u0026lt;x\u0026lt;{x}_{m,1}, \\ \\ {x}_{m,2}\u0026lt;x $ \n Step 2. ๋ชฉ์ ํจ์ ๊ฒฐ์ ๋ชฉ์ ํจ์๋ ๋ก๋ด ํน์ agent๊ฐ ์ด๋ ํ ๊ฒฝ๋ก๋ฅผ ์ ํํ์ ๋, ๊ทธ ๊ฒฝ๋ก๋ฅผ ์์น์ ์ผ๋ก ํ๊ฐํ ์ ์๊ฒ ํด์ฃผ๋ ์์
๋๋ค. ์ต์ ์ ์ด์์๋ Performance measure๋ผ๊ณ ํํํฉ๋๋ค. agent๋ ์์ ์ด ํ๋์ ์ทจํ๊ณ ์ํ๊ฐ ๋ณํ ๋๋ง๋ค, ์ํ ์ ์ด๋ก ์ธํด ์ป์ด์ง๋ ๋ณํ๋ค์ ๋ชจ๋ ์ ์ฅํฉ๋๋ค. ์ด๋ฌํ ์ ๋ณด๋ฅผ ์ด์ฉํ์ฌ ๊ฒฝ๋ก ํ๋๋ฅผ ๋ง์ณค์ ๋ ๊ทธ ๊ฒฝ๋ก์ ๋ํ ํ๊ฐ๋ฅผ ์งํํ๊ฒ ๋ฉ๋๋ค.\n Dynamic Programming : ๊ฐํํ์ต์์๋ ๊ฐ ์ํ(state)์์์ ๋ณด์(reward) $R$๋ฅผ ์ด์ฉํ์ฌ ๋ชฉ์ ํจ์ $G$๋ฅผ ๊ณ์ฐํฉ๋๋ค. ๊ฐ๋จํ๊ฒ๋ ๋จ์ํ ์ง๊ธ๊น์ง ์ป์ ๋ชจ๋ ๋ณด์(reward)์ ๋ํ์ฌ ์ป์ต๋๋ค. ์ด๋ฌํ ๊ฒฝ์ฐ ๋ชฉ์ ํจ์์ ์ถ๋ ฅ์ด ๋ฌดํํ ์ปค์ง๋ ๋ฌธ์ ๊ฐ ์๋๋ฐ, ๊ณผ๊ฑฐ์ ๋ณด์(reward)์ ๋น์จ์ ์ ์ ์ค์ด๋ ๋ฐฉ๋ฒ์ ํตํด (๊ฐ๊ฐ์จ(discount rate), $\\gamma$) ์ด๋ฅผ ํด๊ฒฐํ๊ธฐ๋ ํฉ๋๋ค. ๊ฐํํ์ต์ ์ด ๋ชฉ์ ํจ์๋ฅผ ์ต๋ํํ๋ ๊ฒ์ ๋ชฉํ๋ก ํฉ๋๋ค. $${G}_t = {R}_{t+1} + \\gamma {R}_{t+2} + \\gamma^2 {R}_{t+3} + \u0026hellip; = \\sum_{k=0}^{\\infty} \\gamma^k {R}_{t+k+1}$$\n LQR Control : ์๋ ์์ ๊ฐ์ฅ ์ผ๋ฐ์ ์ผ๋ก ์ฌ์ฉ๋๋ performance measure $J$์
๋๋ค. LQR ์ ์ด๋ ์ด $J$๋ฅผ ์ต์ํํ๋ ๊ฒ์ ๋ชฉํ๋ก ํฉ๋๋ค. $x$๊ฐ ์๋ ์ฒซ๋ฒ์งธ ํญ์ ์๋์ฐจ๊ฐ ์ผ๋ง๋ ๋นจ๋ฆฌ ๋ชฉํ ์ํ๋ก ๋๋ฌํ๋์ง ํ๊ฐํ๋ ์์ด๊ณ , $u$๊ฐ ํฌํจ๋ ๋๋ฒ์งธ ํญ์ ์ผ๋ง๋ ํจ์จ์ ์ผ๋ก (์ต์ํ์ ์
๋ ฅ $u$๋ฅผ ์ด์ฉํ์ฌ) ๋ชฉํ๊น์ง ๋๋ฌํ๋์ง๋ฅผ ํ๊ฐํฉ๋๋ค. $Q$์ $R$์ $x$์ $u$์ ์ค์๋ ๋น์จ์ ๋ฐํ๋
๋๋ค. $$ J = \\int_0^\\infty (x^T Q x + u^T R u) dt $$\n Step 3. ์ ์ฑ
๊ฒฐ์ Dynamic Programming : ์ต๋ state value $v(s)$๋ฅผ ์ซ์๊ฐ๋๋ก ์ ์ฑ
(policy) $\\pi$๋ฅผ ์ค์ ํฉ๋๋ค. State value๋ ๊ฐ ์ํ(state)์์ ๋ฏธ๋์ ์ป์ ์ ์๋ ์ด ๋ณด์(reward)์ ํ๊ท , ์ฆ ๋ชฉ์ ํจ์ $G$์ ๊ธฐ๋๊ฐ์
๋๋ค. ${v}_\\pi(s) = {\\mathbb{E}}_\\pi[{G}_t|{S}_t=s] $ $\\pi = \\underset{a}{\\arg\\max}\\ \\ v(s,a) $\n LQR Control : Performance measure $J$์ $Q$์ $R$์ ๊ฐ์ ์ค์ ํ์ฌ ์ด๋ ํ ์์์ ๊ฐ์ค์น๋ฅผ ๋ ์ง ๊ฒฐ์ ํฉ๋๋ค.\n Step 4. ์ต์ ํด ๊ณ์ฐ Step 1์ ๋ชจ๋ธ, Step 2์ ๋ชฉ์ ํจ์, Step 3์ ์ ์ฑ
์ ์ด์ฉํ์ฌ, ๋ชฉ์ ํจ์๊ฐ ์ต๋๊ฐ ๋๋ ๊ฒฝ๋ก๋ฅผ ์ฐพ์ต๋๋ค. ๊ฐํํ์ต์์๋ ์ฃผ๋ก ๋ชฉ์ ํจ์์ ์ต๋๊ฐ์ ์ฐพ๊ณ , ์ต์ ์ ์ด์์๋ ์ต์๊ฐ์ ์ฐพ์ต๋๋ค๋ง, ๊ธฐ๋ณธ ์๋ฆฌ๋ ๋์ผํฉ๋๋ค.\n Dynamic Programming : Bellman Equation๊ณผ value iteration์ ์ด์ฉํ์ฌ ๊ฐ ์ํ(state)์์์ value๋ฅผ ๊ณ์ฐํฉ๋๋ค. Iteration ํ์๊ฐ ๋ง์์ง์๋ก state value๋ ์ ํํด์ง๊ณ , ์ด๋ฅผ ๋ฌดํ๋๋ก ์ํํ๋ฉด ๊ฒฐ๊ตญ ํ๋์ ๊ฐ์ ์๋ ดํ๊ฒ ๋ฉ๋๋ค. ์๋ ๊ทธ๋ฆผ์ iteration์ ๋ฐ๋ผ ๋ณํํ๋ state value๋ฅผ ๋ณด์ฌ์ค๋๋ค. State value๊ฐ ํด์๋ก ์งํ ์์ผ๋ก ํํ๋ฉ๋๋ค. ${v}_{k+1}(s) = \\underset{a}{\\max} \\sum_{s\u0026rsquo;,r} p(s\u0026rsquo;,r|s,a) [r + \\gamma{v}_k(s\u0026rsquo;)]$ \n LQR Control : ์ต์ ์ ์ด์์๋ Step 1 ๋ชจ๋ธ์ $A$, $B$์ ๊ฐ์ ์์ ํ๋ ฌ์ ์ด์ฉํ์ฌ performance measure $J$๊ฐ ์ต์๊ฐ ๋๋ u๋ฅผ ๊ณ์ฐํฉ๋๋ค. u๋ ์๋ ๋๋ฒ์งธ ์๊ณผ ๊ฐ์ด ์ํ $x$์ ๋ํ ์์ผ๋ก ํํ๋ฉ๋๋ค. ์ด ํด๋ Riccati Equation ๋ฑ์ ํ์ฉํ์ฌ ๊ตฌํ๊ฒ ๋๋๋ฐ, ์ด๋ ๋ณธ ๊ธ์ ๋ฒ์์์ ๋ฒ์ด๋๋ฏ๋ก ์ ์ธํฉ๋๋ค. minimize $ \\int_0^\\infty (x^T Q x + u^T R u) dt$ $$u = Kx$$\n \nModel-free๋ฅผ ํฅํด ์์ ๋ ์๊ณ ๋ฆฌ์ฆ์ ๊ตฌ์กฐ๋ฅผ ๋ณด๋ฉด, ๋ชจ๋ธ์ ํํ์ ์ฌ์ฉํ๋ ๋ชฉ์ ํจ์( or performance measure)๋ง ๋ค๋ฅผ ๋ฟ, ๊ทธ ๊ตฌ์กฐ๋ ์์ ํ ๋์ผํ๋ค๊ณ ํด๋ ๋ฌด๋ฐฉํฉ๋๋ค. Dynamic Programming, LQR Control ๋ ๋ฐฉ๋ฒ ๋ชจ๋ ๋ชจ๋ธ์ด ์๋ค๋ ๊ฒ์ ๊ฐ์ ํ๊ณ ๋ฌธ์ ๋ฅผ ํ์ด๋๊ฐ๋๋ค. ์ต์ ์ ์ด์์๋ ์ํ ๊ณต๊ฐ ๋ฐฉ์ ์์ ์ด์ฉํด ๋ชจ๋ธ์ ํํํ๊ณ , ๊ฐํํ์ต์์๋ ์ํ, ํ๋, ์ํ ์ ์ด ํ๋ฅ ๋ก ๋ชจ๋ธ์ ํํํฉ๋๋ค. ์ด ๋ชจ๋ธ์ ์ด์ฉํ์ฌ ๋ชฉ์ ํจ์์ ์ต์ ํด๋ฅผ ๊ณ์ฐํ๊ณ , ๊ทธ ๊ฒฐ๊ณผ์ ๋ฐ๋ผ ๋ก๋ด์ ์ ์ฉ๋๋ ์
๋ ฅ์ ๊ฒฐ์ ํฉ๋๋ค.\n๊ทธ๋ฐ๋ฐ, ๋ง์ฝ ์ ํฌ๊ฐ ์ด ๋ชจ๋ธ์ ๊ตฌํ ์ ์๋ ์ํฉ์ด ๋๋ฉด ์ด๋ป๊ฒ ๋ ๊น์? ๋จ์ํ ํ๋ผ๋ฏธํฐ์ ๊ฐ์ด ์กฐ๊ธ ํ๋ฆฐ ์ ๋๊ฐ ์๋๋ผ, ๋ชจ๋ธ์ ์ํฅ์ ๋ฏธ์น๋ ์์๊ฐ ๋๋ฌด ๋ง์ ๋ชจ๋ธ์ ๋ค ๋ด์ ์ ์๋ค๋ฉด? ์ค์ ํ๊ฒฝ์ ์ ์ฝ์ผ๋ก ์ธํด ๊ทธ ์์๋ค์ ๋ชจ๋ ์ธก์ ํ ์ ์๋ ์ํฉ์์๋ ์ด๋ ํ ๋ฐฉ๋ฒ์ ์จ์ผ ํ ๊น์?\n๊ฐํํ์ต์ ์ด ๋ฌธ์ ๋ฅผ trial \u0026amp; error, ์ฆ ๊ฒฝํ์ ์ด์ฉํ ๋ฐฉ๋ฒ์ผ๋ก ํ์ด๋
๋๋ค. Dynamic Programming ์ดํ์ ๊ฐํํ์ต ์ด๋ก , Monte-Carlo, Q-learning ๋ฑ์ด ๊ทธ ์์
๋๋ค. ์ค์ ๊ฒฝํ์ ์ด์ฉํด ๊ฐ ์ํ์์ ๋ชฉ์ ํจ์์ ์ธก์ ๊ฐ์ ์์งํ ํ์, ๋ชฉ์ ํจ์์ ์์ธก๊ฐ๊ณผ ์ค์ ์ธก์ ๊ฐ์ด ๊ฐ์์ง๋๋ก ๋ชฉ์ ํจ์๋ฅผ ์
๋ฐ์ดํธ ํฉ๋๋ค. ๋ชฉ์ ํจ์๋ฅผ ๊ณ์ฐํ๋๋ฐ ํ๊ฒฝ ๋ชจ๋ธ์ ์ฌ์ฉํ์ง ์์ต๋๋ค. ์ฆ, Model-free ์กฐ๊ฑด์์ ๋ฌธ์ ๋ฅผ ํธ๋ ๋ฐฉ๋ฒ์
๋๋ค [6]. \nPCI ๋ก๋ด ์ ์ด๋ ์ด๋ฌํ Model-free ๋ฐฉ๋ฒ์ด ํ์ํฉ๋๋ค. ๋ชจ๋ธ์ ๋ง๋๋ ค๋ฉด ๊ฐ์ด๋์์ด์ด์ ์์ฉํ๋ ํ ์์๋ค์ ๋ชจ๋ ์์์ผ ํ๋๋ฐ, ๊ฐ์ด๋์์ด์ด์ ์ด๋ ๋ถ๋ถ์ด ํ์ด์ ธ์๋์ง, ์ด๋ ๋ถ๋ถ์ด ํ๊ด๊ณผ ์นด๋ฐํฐ์ ๋ฟ์์๋์ง, ๊ฐ์ด๋์์ด์ด์ ํ๊ด ์ฌ์ด ๋ง์ฐฐ๋ ฅ์ ์ผ๋ง๋ ๊ฐํ์ง ๋ฑ์ ๋ชจ๋ ์์์ผํฉ๋๋ค. ์ด๋ฅผ ๋ชจ๋ ์ธก์ ํ ์ ์์ผ๋ฉด ์ข๊ฒ ์ง๋ง, ์์ฝ๊ฒ๋ ํ์ฌ ํ๋งค ์ค์ธ ๊ฐ์ด๋์์ด์ด ์ค ๊ทธ ๋ชจ๋ ๊ฒ์ ์ธก์ ํ ์ ์๋ ์ ํ์ ์์ต๋๋ค. ์ฌ์ง์ด ์ด ์์๋ค์ ์๊ฐ์ ๋ฐ๋ผ ๋ถ๊ท์นํ๊ฒ ๋ณํ๋, time-variant ํน์ฑ์ ๊ฐ๊ณ ์๊ณ , ๊ทธ ๋ณํ ํญ์ด ์ปค ๋ชจ๋ธ๋ก ํํํ๊ธฐ๊ฐ ๋๋์ฑ ์ด๋ ต์ต๋๋ค. ๊ฒฐ๊ตญ ์ด๋ฌํ ์์๋ค์ ๊ฒฝํ์ ํตํด์ ์์๋ด์ผ ํ๋ค๋ ๊ฒฐ๋ก ์ ์ ํฌ๋ ๋๋ฌํ์ต๋๋ค.\n\nConclusion ์ ์ด์ด๋ก ๊ณผ ๊ฐํํ์ต ์ค ์ ํฌ๊ฐ ์ ๊ฐํํ์ต์ ์ ํํ๋์ง ์ด์ผ๊ธฐํด๋ณด์์ต๋๋ค. ์ต์ ๊ฒฝ๋ก ํ์, Model-free ์ ๊ทผ์ด ๊ฐ๋ฅํ๋ค๋ ๊ฒ์ด ์ ํฌ๊ฐ PCI ๋ก๋ด์ ๊ฐํํ์ต์ ์ ์ฉํ ๊ฐ์ฅ ํฐ ์ด์ ์
๋๋ค. ๋ค์ ๊ธ์์๋ ์ ํฌ๊ฐ ๊ฐํํ์ต์ ์ค์ ๋ก ์ด๋ป๊ฒ PCI ๋ก๋ด์ ์ ์ฉํ๋์ง ์ด์ผ๊ธฐํด๋ณด๊ฒ ์ต๋๋ค.\nReference [1] Wikipedia (PID Controller) https://en.wikipedia.org/wiki/PID_controller [2] J. Kweon, H. Kwon, J. Park and Y. Kim, \u0026ldquo;Reinforcement Learning for Guidewire Navigation in Coronary Phantom\u0026rdquo;, TCT 2019, San Francisco, Sep 2019. [3] R.S. Sutton, A.G. Barto and R.J. Williams, \u0026ldquo;Reinforcement Learning is Direct Adaptive Optimal Control\u0026rdquo;, American Control Conference, Boston, June 1991. [4] R.S. Sutton and A.G. Barto, \u0026ldquo;Reinforcement Learning: An Introduction 2nd Edition\u0026rdquo;, The MIT Press, Cambridge, 2018. [5] D.E Kirk, \u0026ldquo;Optimal Control Theory: An Introduction\u0026rdquo;, Dover Publication, New York, 2004. [6] C.B. Black and D.C. Rucker, \u0026ldquo;Parallel Continuum Robots: Modeling, Analysis, and Actuation-Based Force Sensing\u0026rdquo;, IEEE Transactions on Robotics, vol.34, no.1, Feb 2018.\n","date":1574730000,"expirydate":-62135596800,"kind":"page","lang":"en","lastmod":1574730000,"objectID":"2a6c2ac190143e1a1c52f1c1c2991524","permalink":"/post/2019-11-26-adventure_of_rl_in_vessel_2/","publishdate":"2019-11-26T10:00:00+09:00","relpermalink":"/post/2019-11-26-adventure_of_rl_in_vessel_2/","section":"post","summary":"Introduction to guide-wire control for PCI by RL (2) - RL vs Control Theory","tags":[],"title":"๊ฐํํ์ต์ ํ๊ด ์ ํํ (2) - ๊ฐํํ์ต๊ณผ ์ ์ด ์ด๋ก ์ ๋น๊ต","type":"post"},{"authors":["kyunghwan-kim","chaehyeuk-lee"],"categories":[],"content":" ๊ฐํํ์ต์ ํ๊ด ์ ํํ ์๋ฆฌ์ฆ ๊ฐํํ์ต์ ํ๊ด ์ ํํ (1) - ๋ก๋ด๊ณผ ์ฌํ๊ด ์ค์ฌ ์์ \n๊ฐํํ์ต์ ํ๊ด ์ ํํ (2) - ๊ฐํํ์ต๊ณผ ์ ์ด ์ด๋ก ์ ๋น๊ต ๊ฐํํ์ต์ ํ๊ด ์ ํํ (3) - ์คํํ๊ฒฝ ๊ตฌ์ฑ๊ณผ ๊ฐํํ์ต ์๊ณ ๋ฆฌ์ฆ ์๊ฐ\nIntro ์ด๋ฒ ํฌ์คํธ์์๋ ์ ํฌ๊ฐ ์ฐ๊ตฌ ์ค์ธ ๊ฐํํ์ต์ ์ด์ฉํ ์ฌํ๊ด ์ค์ฌ์์ ๋ก๋ด ์ ์ด์ ๋ํด ์๊ฐํ๋ ค๊ณ ํฉ๋๋ค. ์ฒ์ ์ด ์ฃผ์ ์ ๋ํด ๋ค์ผ์๋ฉด \u0026ldquo;์ฌํ๊ด ์ค์ฌ์์ ์ด ๋ญ์ง?\u0026rdquo;, \u0026ldquo;์ ๋ก๋ด์ ์ ์ด๋ฅผ ํ๋๋ฐ ๊ฐํํ์ต์ ์ฐ์ง?\u0026rdquo; ์ ๊ฐ์ด ์ฌ๋ฌ ๊ถ๊ธ์ฆ์ด ๋จผ์ ์๊ธฐ์ค ๊ฒ์
๋๋ค. ๊ทธ๋์ ํฌ์คํธ๋ฅผ ํตํด ์ด๋ฐ ๊ถ๊ธ์ฆ์ ํด์ํ๋ ์๊ฐ์ ๊ฐ์ง๋ ค ํฉ๋๋ค.\n ์ฌํ๊ด ์ค์ฌ์์ ? ํํ์ฑ ์ฌ์ฅ ์งํ ๊ด์๋๋งฅ ์ค์ฌ์์ (PCI) ์ฌํ๊ด ์ค์ฌ์์ ์๋ํ์ ํ์์ฑ ๊ฐ์ด๋์์ด์ด ์ ์ด ๋ง์น๋ฉฐ \n์ฌํ๊ด ์ค์ฌ์์ ? ์ ํฌ๋ ์ฌํ๊ด ์งํ์ ์ง๋จ ๋ฐ ์น๋ฃ๋ฅผ ๋๋ ์๋ฃจ์
์ ์ฐ๊ตฌ ๊ฐ๋ฐ ํ๊ณ ์์ต๋๋ค. ์ฌํ๊ด ์งํ์๋ ์ฌ๋ฌ ์ข
๋ฅ๊ฐ ์๊ณ ๊ทธ์ ๋ฐ๋ฅธ ์น๋ฃ๋ฐฉ๋ฒ๋ ๋ค์ํฉ๋๋ค. ๊ทธ ์ค ํ์ฌ ์ ํฌ๊ฐ ์ฐ๊ตฌํ๋ ๋ด์ฉ๊ณผ ๊ฐ์ฅ ์ฐ๊ด์ด ์๋ ํํ์ฑ ์ฌ์ฅ ์งํ๊ณผ ์ด๋ฅผ ์น๋ฃํ๊ธฐ ์ํ ์ฌํ๊ด ์ค์ฌ์์ ์ ๋ํด ์ค๋ช
ํ๋ ค ํฉ๋๋ค.\n\nํํ์ฑ ์ฌ์ฅ ์งํ ์ฌ์ฅ์ ์ฐ๋ฆฌ ๋ชธ ์ ์ฒด์ ํ์ก์ ๋ณด๋ด๋ ํํ ์ญํ ์ ํ๊ณ ์์ต๋๋ค. ํ์ก์ ํตํด ์ฐ์์ ์์์๋ฅผ ๊ณต๊ธํ์ฌ ์ฐ๋ฆฌ ๋ชธ์ด ์๋์ง๋ฅผ ๋ง๋ค๊ณ ์ํ์ ํ ์ ์๋๋ก ํฉ๋๋ค. ์ฌ์ฅ์ด ํํ ์ญํ ์ ์ํํ๋ ค๋ฉด ์ฌ์ฅ์ ์ด๋ฃจ๊ณ ์๋ ์ฌ๊ทผ์๋ ์ฐ์์ ์์์๋ฅผ ๊ณต๊ธํด์ฃผ์ด์ผ ํฉ๋๋ค. ์ด๋ฅผ ์ํด ์ฌ๊ทผ์ ํ์ก์ ๊ณต๊ธํ๋ ํ๊ด์ด ๊ด์๋๋งฅ์
๋๋ค [1].\n\nํํ์ฑ ์ฌ์ฅ ์งํ์ ์ฌ์ฅ์ ํ์ก์ ๊ณต๊ธํด์ฃผ๋ ํ๊ด์ธ ๊ด์๋๋งฅ์ ์ง๋ฐฉ์ง, ์ฝ๋ ์คํ
๋กค, ์นผ์ ๋ฑ์ด ์์ฌ ํ๊ด์ด ์ข์์ง๊ฑฐ๋ ๋งํ ์ฌ์ฅ๊ทผ์ก์ ์ผ๋ถ์ ํ์ก ๊ณต๊ธ์ด ๋ถ์กฑํ์ฌ ๋ฐ์ํ๋ ์งํ์
๋๋ค [2]. ํํ์ฑ ์ฌ์ฅ ์งํ์ ๊ตญ๋ด ์ฌ๋ง ์์ธ ํต๊ณ๋ฅผ ๋ณด๋ฉด ์์ ์ด์ด 2์๋ฅผ ์ฐจ์งํ๊ณ ์์ผ๋ฉฐ ์ ์ธ๊ณ ํต๊ณ์์๋ 1์๋ฅผ ์ฐจ์งํ๊ณ ์์ต๋๋ค [3]. ๊ทธ๋งํผ ๋ง์ ์ฌ๋๋ค์ด ์ด ์งํ์ ๊ฒช๊ณ ์์ผ๋ฉฐ ์ฌ๋ง์ ์ด๋ฅผ ์ ๋๋ก ์ํํ ์งํ์ด๋ผ๋ ๊ฒ์ ์ ์ ์์ต๋๋ค. ํํ์ฑ ์ฌ์ฅ ์งํ์๋ ํ์ฌ์ฆ, ์ฌ๊ทผ๊ฒฝ์ ๋ฑ์ด ์์ต๋๋ค. ์๋ ์ด๋ฏธ์ง๋ ์ฌํ๊ด ์งํ์ ์์์
๋๋ค [4].\n\n\n๊ด์๋๋งฅ ์ค์ฌ์์ (PCI) ๊ด์๋๋งฅ ์ค์ฌ์์ (PCI; Percutaneous Coronary Intervention)์ ํํ์ฑ ์ฌํ๊ด ์งํ์์ ํฐ ๋น์ค์ ์ฐจ์งํ๊ณ ์์ต๋๋ค. PCI๋ ํ์ด๋ ๋ค๋ฆฌ์ ํ๊ด์ ํตํ์ฌ ์ฌ์ฅ๊น์ง ๋ค์ด๊ฐ ๋ค์, ๋งํ๊ฑฐ๋ ์ข์์ง ์ฌ์ฅ ํ๊ด์ ๋ํ๋ ์์ ์
๋๋ค [5]. ๊ฐ์ด์ ์ ๊ฐํ๋ ์์ ์ด ์๋๊ธฐ ๋๋ฌธ์ ์ ์ ๋ง์ทจ๊ฐ ํ์์๊ณ ๊ฐ์ด์ ํํฐ๋ฅผ ๋จ๊ธฐ์ง ์์ ๋น๊ต์ ํ์์ ๋ถ๋ด์ด ๋ํ ์น๋ฃ๋ฐฉ๋ฒ์
๋๋ค. ์คํ
ํธ๋ผ๋ ์์ ๋๊ตฌ๋ก ๋ณ๋ณ์ ์น๋ฃํ๊ธฐ ๋๋ฌธ์ ์ผ๋ฐ์ ์ผ๋ก ์คํ
ํธ ์์ ์ด๋ผ๋ ์ด๋ฆ์ผ๋ก ๋ง์ด ์๋ ค์ ธ ์์ต๋๋ค. ์์ ๋ฐฉ๋ฒ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค [6].\n ํ๋ฒ
์ง ์์ชฝ ๋๋ ํ์ ๋๋งฅ ํ๊ด์ ํตํด ๊ฐ์ด๋์์ด์ด๋ฅผ ๋ฃ์ด ๊ด์๋๋งฅ์ ๋ณ๋ณ๋ถ์์ ์ ๊ทผ. ๊ฐ์ด๋์์ด์ด๋ฅผ ํตํด ๋ค๋ฅธ ์์ ๋๊ตฌ๋ค์ ๋ณ๋ณ ๋ถ์๊น์ง ์ด๋. ๋ฒ๋ฃฌ์ผ๋ก ๋งํ ํ๊ด ๋ถ๋ถ์ ๋ํ๊ณ , ๋ณ๋ณ์ ๋ฐ๋ผ ์คํ
ํธ๋ผ๋ ๊ทธ๋ฌผ๋ง์ผ๋ก ๊ณ ์ \n์ด ๋, ์์ ์๋ ์กฐ์์ ์ X-ray๋ฅผ ์ด์ฉํ ํ๊ด์กฐ์์์์ ์ด์ฉํด ๋ณ๋ณ์ ํ์ธํ๊ณ ์์ ์์น๋ฅผ ํ์
ํฉ๋๋ค. ์์ ์ด ์งํ๋๋ ๋์ค์๋ ๊ณ์ํด์ ํ๊ด์กฐ์์์์ ํ์ธํ์ฌ ์ ํํ ์์ ์ ์งํํฉ๋๋ค. ์๋๋ ํ๊ด์กฐ์์์์ ์ผ๋ถ์
๋๋ค [7].\n\n\n์ฌํ๊ด ์ค์ฌ์์ ์๋ํ์ ํ์์ฑ PCI๋ ํํ์ฑ ์ฌ์ฅ ์งํ์ ํจ๊ณผ์ ์ผ๋ก ์น๋ฃํ ์ ์๋ ์์ ๋ฐฉ๋ฒ์ด์ง๋ง ๊ฐ์ ํด์ผํ ๋ถ๋ถ๋ ์์ต๋๋ค.\n ์๋ฃ์ง์ ๋ฐฉ์ฌ๋ฅ ํผํญ\n PCI๋ ํ๊ด์ ๋ชจ์๊ณผ ํ์ฌ ์์ ๋๊ตฌ์ ์์น๋ฅผ ํ์ธํ๊ธฐ ์ํด ์์ ์ค ํ๊ด์กฐ์์์์ ๊ณ์ํด์ ์ดฌ์ํด์ผํฉ๋๋ค. ์ดฌ์ ๊ธฐ๊ธฐ ์์ ๋ฐฉ์ฌ์ ๊ฐ๋ฆผ๋ง์ ๋๊ธฐ๋ ํ์ง๋ง ๋งค์ผ ์์ ์ ์งํํ๋ ์๋ฃ์ง๋ค์ ๋ง์ ์์ ๋ฐฉ์ฌ๋ฅ์ ๋
ธ์ถ๋ ์ ๋ฐ์ ์์ต๋๋ค. ๊ธด ์์ ์๊ฐ\n PCI๋ ์ผ๋ฐ์ ์ผ๋ก 1์๊ฐ ์ ๋์ ์์ ์๊ฐ์ด ์์๋ฉ๋๋ค. ํ์ง๋ง ๋ณ๋ณ ๋ถ์์ ๋์ด๋์ ๋ฐ๋ผ ์์ ์๊ฐ์ด 2์๊ฐ์์ ๋ง๊ฒ๋ 4์๊ฐ ์ด์ ๊ฑธ๋ฆฌ๊ธฐ๋ ํฉ๋๋ค. ์์ ์๊ฐ์ด ๊ธธ์ด์ง์๋ก ์์ ์ ๋ฟ๋ง ์๋๋ผ ํ์์๊ฒ๋ ๋ง์ ๋ถ๋ด์ด ๋ฉ๋๋ค. ํ์์ ๊ฒฝ์ฐ ํ๊ด์กฐ์์์ ์ดฌ์์ ํ์์ ํ๊ด์ ํฌ์
๋๋ ์กฐ์์ ์ ์์ด ๋์ด๋๊ฒ ๋๊ณ ์ด๋ ๊ฐ๋ ค์์ฆ, ๊ตฌํ ์ ๊ฐ์ ๊ณผ๋ฏผ๋ฐ์์ ์ผ์ผํฌ ์ ์์ต๋๋ค. ์๋ จ๋์ ๋ฐ๋ฅธ ์ฐจ์ด\n PCI๋ ์์ ์์ ์๋ จ๋์ ๋ฐ๋ผ ์์ ์๋๋ ๋๊ตฌ ์ฌ์ฉ๋ ๋ฑ์์ ํธ์ฐจ๊ฐ ์์ต๋๋ค. ํนํ PCI์ ์์ ๋๊ตฌ๋ค์ 1ํ์ฉ ์๋ชจํ์ธ ๊ฒ์ ๋นํด ๊ณ ๊ฐ์ ๋๊ตฌ๋ค์ด ๋ง์ต๋๋ค. ์๋ จ๋ ์์ ์๋ผ๋ฉด ๊ฒฝํ์ ํตํด ๋ณ๋ณ ๋ถ์๋ ํ์์ ์ํ๋ฅผ ๋ณด๊ณ ํ๋ฒ์ ์ ํฉํ ์์ ๋๊ตฌ๋ก ์์ ์ ์งํํ ์ ์์ง๋ง ๋น์๋ จ์๋ ์ฌ๋ฌ ๋ฒ์ ์ํ์ฐฉ์ค๋ฅผ ํตํด ๋๊ตฌ๋ฅผ ์ ํํ๊ฒ ๋ฉ๋๋ค. ์ด ๋๋ฌธ์ ์์ฐ์ค๋ฝ๊ฒ ์์ ์๊ฐ์ด ๊ธธ์ด์ง๊ฒ ๋์ด ํ์๋ ์์ ์์๊ฒ ๋ถ๋ด์ ์ฃผ๊ฒ ๋ฉ๋๋ค. ์์ ๊ฐ์ ์ ๋ค์ ๊ฐ์ ํ๊ธฐ ์ํด PCI ๋ก๋ด์ ๋ํ ์ฐ๊ตฌ๊ฐ ์งํ๋๊ณ ์์ต๋๋ค. ๋ํ์ ์ผ๋ก Corindus์ ์์ ๋ก๋ด์ด ์์ต๋๋ค [8]. ์ ํฌ๋ ์ด๋ณด๋ค ๋ ๋์๊ฐ ์ธ๊ณต์ง๋ฅ์ผ๋ก ๋ก๋ด์ ์ ์ดํ์ฌ ์์ ์ ์๋ํํ๋ ์ฐ๊ตฌ๋ฅผ ์งํํ๊ณ ์์ต๋๋ค. PCI์ ์๋ํ๋ฅผ ํตํด ํ์์ ์์ ์ ๋ชจ๋์ ๋ถ๋ด์ ์ค์ด๊ฒ ๋๋ฉฐ, ํนํ ์ด์์ ์ผ๋ก ์๋ํ๊ฐ ๋๋ค๋ฉด ์์ ์ ์๋ จ๋์ ๋ฐ๋ฅธ ์ฐจ์ด๋ฅผ ์์จ ์ ์์ต๋๋ค.\n\n๊ฐ์ด๋์์ด์ด ์ ์ด ์์ ์๋ํ์ ์ฒซ ๋จ๊ณ๋ก ๋ก๋ด์ ์ด์ฉํ ๊ฐ์ด๋์์ด์ด์ ์๋์ ์ด๋ฅผ ์ฐ๊ตฌํ๊ณ ์์ต๋๋ค. PCI๋ ์์ ์์ ๊ณผ์ ์์ ์ค๋ช
๋๋ฆฐ ๊ฒ์ฒ๋ผ ๊ฐ์ด๋์์ด์ด๋ฅผ ๋ณ๋ณ ๋ถ์๊น์ง ์์น์ํจ ํ ์ด ๊ฐ์ด๋์์ด์ด๋ฅผ ์ด์ฉํด ๋ค๋ฅธ ์์ ๋๊ตฌ๋ค์ ์ด๋์ํต๋๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ๊ฐ์ด๋์์ด์ด๋ฅผ ๋ณ๋ณ ๋ถ์๊น์ง ์ ๋๋ฌ์ํค๋ ๊ฒ์ด ์์ ์ ๊ฐ์ฅ ์ค์ํ ๋ถ๋ถ์
๋๋ค. ํ์ง๋ง ํ๊ด์กฐ์์์์ผ๋ก๋ ์ ํํ ์ ์ ์๋ ํ๊ด์ ๊ตฌ์กฐ์ ๋ชจ์, ์์ด์ด ์ด๋ ์ ์๊ธฐ๋ ํ๊ด์ ์ํ ๋ง์ฐฐ, ์์ ์ค ํ์์ ํธํก๊ณผ ๋ฐ๋, ํ๊ด์ ๋ค์ด๊ฐ๊ธฐ ์ํด ์๊ณ ๋ถ๋๋ฝ๊ฒ ์ ์๋์ด ์ ์ด๊ฐ ์ด๋ ค์ด ์์ด์ด ๋ฑ ๊ฐ์ด๋์์ด์ด๋ฅผ ์ ์ดํ๋๋ฐ ๋ง์ ์ด๋ ค์์ด ์์ต๋๋ค. ์ค์ ์์ฌ๋ค์ ์๋ฃ ์ง์์ ํตํ ํ๊ด ๋ชจ์ ์์ธก, ์์ ๊ฐ๊ฐ๊ณผ ๊ฒฝํ์ ํตํ ๋ฏธ์ธํ ์กฐ์ข
์ผ๋ก ๊ฐ์ด๋์์ด์ด๋ฅผ ์ด๋์์ผ ์์ ํฉ๋๋ค. ์ ํฌ๋ ๊ฐ์ด๋์์ด์ด ์ ์ด ๋ฌธ์ ๋ฅผ ๋ก๋ด๊ณผ ์ธ๊ณต์ง๋ฅ์ ๊ฒฐํฉํ์ฌ ํด๊ฒฐํ๋ ค ํฉ๋๋ค.\n\n์ ์ด๋ฏธ์ง [9]์์ ์์ฌ๊ฐ ๊ฐ์ด๋์์ด์ด๋ฅผ ์กฐ์ํ๋ ๋ชจ์ต๊ณผ ๋ก๋ด(Manipulator)๋ฅผ ์ด์ฉํด ๊ฐ์ด๋์์ด์ด๋ฅผ ์กฐ์ํ๋ ๋ชจ์ต์ ๋ณผ ์ ์์ต๋๋ค. ์ค์ ์์ ์์ ์์ ์๋ ๊ฐ์ด๋์์ด์ด๋ฅผ ๋ณ๋ณ ๋ถ์๋ก ์ด๋์ํค๊ธฐ ์ํด ํ์ (rotation)๊ณผ ์ ํ์ง(translation) ๋์์ ํฉ๋๋ค. ์ ํฌ๊ฐ ์ด์ฉํ๋ ๋ก๋ด๋ ์ด๋ฌํ ๋ ๊ฐ์ง ๋์์ ์ฌํํ ์ ์๋๋ก ์ค๊ณ๋์์ต๋๋ค. ๊ฐ์ด๋์์ด์ด์ ์ํ์ ๋ฐ๋ผ ๋ ๊ฐ์ง ๋์ ์ค ์ด๋ค ๋์์ ํ ์ง ์ ํํ๋ ๊ฒ์ด ์ธ๊ณต์ง๋ฅ์ ์ญํ ์
๋๋ค.\n\n๋ง์น๋ฉฐ ์ด๋ฒ ํฌ์คํธ์์๋ ์ฌํ๊ด ์ค์ฌ์์ ๊ณผ ์ ํฌ๊ฐ ์งํํ๊ณ ์๋ ์ฐ๊ตฌ ์ฃผ์ ์ธ ์ฌํ๊ด ์ค์ฌ์์ ์๋ํ์ ํ์์ฑ์ ๋ํด ์ค๋ช
๋๋ ธ์ต๋๋ค. ๋ค์ ํฌ์คํธ์์๋ PCI๋ฅผ ์๋ํํ๋ ๋ฐฉ๋ฒ์ผ๋ก ์ธ๊ณต์ง๋ฅ ๊ธฐ๋ฒ ์ค ๊ฐํํ์ต์ ์ ํํ ์ด์ ์ ๋ํด์ ํฌ์คํ
ํ๋๋ก ํ๊ฒ ์ต๋๋ค.\nReference [1] ์ฌ์ฅ ์ด๋ฏธ์ง (wiki): https://ko.wikipedia.org/wiki/%EA%B4%80%EC%83%81%EB%8F%99%EB%A7%A5 [2] ํํ์ฑ ์ฌ์งํ ์ค๋ช
(์์ธ์์ฐ๋ณ์): http://www.amc.seoul.kr/asan/healthinfo/disease/diseaseDetail.do?contentId=30275 [3] ์ฐ๋๋ณ ๊ตญ๋ด ์ฌ๋ง ์์ธ ํต๊ณ(e-๋๋ผ์งํ), ์ธ๊ณ ์ฌ๋ง ์์ธ(WHO): http://www.index.go.kr/potal/stts/idxMain/selectPoSttsIdxMainPrint.do?idx_cd=1012\u0026amp;board_cd=INDX_001, https://www.who.int/news-room/fact-sheets/detail/the-top-10-causes-of-death [4] ์ฌํ๊ด์งํ์ ์ข
๋ฅ ์ด๋ฏธ์ง(์์คํผ๋ฆฐํ๋กํ
ํธ): http://www.aspirinprotect.co.kr/ko/disease-and-prevention/cardiovascular-diseases/#tab_tab0 [5] ๊ด์๋๋งฅ ์ค์ฌ์์ ์ ์ดํด(์์ธ์์ฐ๋ณ์ ์ฌ์ฅ๋ณ์): http://heart.amc.seoul.kr/asan/depts/heart/K/bbsDetail.do?menuId=4634\u0026amp;contentId=264501 [6] ์ฌ๋ ๋ชธ๊ณผ ํ๊ด ์ด๋ฏธ์ง: http://www.secondscount.org/image.axd?id=c8a00122-bb66-46c6-8ab7-333a9a0cd46a\u0026amp;t=635566481777430000, https://www.mcvs.co.nz/wp-content/uploads/2017/05/stent-balloon-angioplasty.png [7] ๊ด์๋๋งฅ ์กฐ์์ ์ด๋ฏธ์ง (๊ฐ๋จ์ธ๋ธ๋์ค๋ณ์): http://gs.iseverance.com/dept_clinic/department/cardiology/treatment/view.asp?con_no=82261 [8] Corindus: https://www.corindus.com/ [9] ์๊ธฐ ์์ ๊ณผ ๋ก๋ด ์ด๋ฏธ์ง: ์์ฐ๋ฉ๋์ปฌ์ผํฐ ","date":1571965200,"expirydate":-62135596800,"kind":"page","lang":"en","lastmod":1571965200,"objectID":"67962c312824919fd36425bec73b8a48","permalink":"/post/2019-10-25-adventure_of_rl_in_vessel_1/","publishdate":"2019-10-25T10:00:00+09:00","relpermalink":"/post/2019-10-25-adventure_of_rl_in_vessel_1/","section":"post","summary":"Introduction to guide-wire control for PCI by RL - PCI aided by Robot","tags":[],"title":"๊ฐํํ์ต์ ํ๊ด ์ ํํ (1) - ๋ก๋ด๊ณผ ์ฌํ๊ด ์ค์ฌ ์์ ","type":"post"},{"authors":["kyunghwan-kim","curt-park"],"categories":[],"content":" ์ด๋ฒ ํฌ์คํธ์์๋ ๊ฐํํ์ต์์ reward shaping์ ๊ธฐ๋ฐ์ด ๋๋ ๋
ผ๋ฌธ์ธ \u0026ldquo;Policy invariance under reward transformation: Theory and application to reward shaping\u0026rdquo; (A. Y. Ng et al., 1999) [1]์ ์ฝ๊ณ ์ ๋ฆฌํ ๋ด์ฉ์ ๊ณต์ ํฉ๋๋ค.\n ๊ธ์ด์ด์ ์๊ฒฌ์ด๋ ๋ถ์ฐ ์ค๋ช
์ ์ด ๋ฌธ์ฅ๊ณผ ๊ฐ์ด ๋ธ๋ก์ผ๋ก ํ์ํฉ๋๋ค.\n Introduction ๊ฐํํ์ต์์ task๋ Reward function์ ํตํด ํํ๋ฉ๋๋ค. ์ด reward function์ ๋ณํ๋ฅผ ์ฃผ๋ ๊ฒ์ผ๋ก ํ์ต์ ์ฑ๋ฅ์ ํฅ์์ํฌ ์ ์์ต๋๋ค. ์ด๋ฅผ Reward shaping ์ด๋ผ๊ณ ํฉ๋๋ค. ํ์ง๋ง reward function์ ๊ต์ฅํ ๋ฏผ๊ฐํ๊ธฐ ๋๋ฌธ์ reward shaping์ ๋ฐฉ๋ฒ์ ๋ฐ๋ผ agent๋ ์๋์ ๋ค๋ฅธ ํ๋์ ํ๊ธฐ๋ ํฉ๋๋ค. ๋ณธ ๋
ผ๋ฌธ์์๋ ์ด๋ฐ ์๋ํ์ง ์์ ํ์ต ๊ฒฐ๊ณผ๋ฅผ bug๋ผ๊ณ ํํํ๋ฉฐ ๊ทธ ์์๋ก ๋ ๊ฐ์ง ๊ฒฝ์ฐ๋ฅผ ์ค๋ช
ํฉ๋๋ค.\n ์์ ๊ฑฐ ์ฃผํ agent๋ฅผ ๋นจ๋ฆฌ ํ์ต์ํค๊ธฐ ์ํด goal ๋ฐฉํฅ์ผ๋ก ๊ฐ๋ positive reward๋ฅผ ์ฃผ์๋๋ ์์ ์ง์ ์ ์ค์ฌ์ผ๋ก ์์ ๊ทธ๋ฆฌ๋ฉฐ ๋๋ agent๊ฐ ๋์๋ค. ์ด์ ๋ goal์์ ๋ฉ์ด์ง๋ penalty๋ฅผ ์์ฃผ์๊ธฐ ๋๋ฌธ์ ๊ณ์ ๋๊ธฐ๋ง ํด๋ goal์ ๊ฐ๊น์์ง๋ ๋ฐ์ positive reward๊ฐ ๋ฌดํํ ์์ด๊ธฐ ๋๋ฌธ์ด๋ค. ์ถ๊ตฌ ๋ก๋ด์ ํ์ตํ ๋ ๊ณต์ ๊ณ์ ์ ์ ํ๊ณ ์๋ ๊ฒ์ด ์ค์ํ๋ค. ๊ทธ๋์ ๊ณต์ ๊ฑด๋๋ฆด ๋ reward๋ฅผ ์ฃผ์๋๋ ๊ณต ๋ฐ๋ก ์์์ ์ง๋ํ๋ agent๊ฐ ๋์๋ค. ๊ณต์ ๊ณ์ ๊ฑด๋๋ ค์ reward๋ฅผ ๋ฐ๋ณต์ ์ผ๋ก ๋ฐ์ ์ ์๊ธฐ ๋๋ฌธ์ด๋ค. ์์ ์์์์ ์ฐ๋ฆฌ๊ฐ ๋ฐ๋ผ๋ ๊ฒ์ ์์ ๊ฑฐ ์ฃผํ agent๋ goal์ ๋์ฐฉํ๋ ๊ฒ์ด๊ณ ์ถ๊ตฌ ๋ก๋ด์ ๊ณต์ ์๋ ๊ณจ๋์ ๋ฃ๋ ๊ฒ์
๋๋ค. ํ์ง๋ง ์๋ชป๋ reward shaping์ผ๋ก ์ ํ ๋ค๋ฅธ ๋ชฉํ๋ฅผ ๋ฌ์ฑํ๋ agent๋ฅผ ํ์ต์ํค๊ฒ ๋์์ต๋๋ค. ์ด์ฒ๋ผ reward shaping์ ๊ฐํํ์ต์ ์ฑ๋ฅ ํฅ์์ ์ํด ํจ๊ณผ์ ์ธ ๋ฐฉ๋ฒ์ด์ง๋ง ์๋ํ ๋ฐฉํฅ์ผ๋ก shaping ํ๋ ๊ฒ์ ์ด๋ ต์ต๋๋ค. ํนํ ์์ ๊ฐ์ด positive reward๊ฐ ๊ณ์ํด์ ์์ด๋ ๊ฒ์ positive reward cycle ์ด๋ผ๊ณ ๋
ผ๋ฌธ์์ ํํํฉ๋๋ค.\n์ด๋ฐ ํ์์ด ๋ฐ์ํ๋ ์ด์ ๋ reward function์ ๋ฐ๋ผ agent๊ฐ ํ์ตํ๊ณ ์ ํ๋ optimal policy๊ฐ ์๋ suboptimal๋ก ์๋ชป ํ์ตํ๊ธฐ ๋๋ฌธ์
๋๋ค. ๋ณธ ๋
ผ๋ฌธ์์ optimal policy๋ ์ฐ๋ฆฌ๊ฐ ํด๋น ๋ฌธ์ ์ ๋ํด agent์๊ฒ ํ์ต์ํค๊ณ ์ ํ๋ ์ ์ฑ
์ด๊ณ suboptimal์ ์ฐ๋ฆฌ๊ฐ ์ํ๋ policy๋ ์๋์ง๋ง ๋์ reward๋ฅผ ๋ฐ์ ์ ์๋ ์ ์ฑ
์ ๋งํฉ๋๋ค. reward function์ ๋ณํ๊ฐ ํ์ตํ๊ณ ์ ํ๋ policy์๋ ์ํฅ์ ์ฃผ์ด reward๋ฅผ ์ต๋๋ก ๋ฐ๋ ๋ฐฉํฅ์ผ๋ก ํ์ตํ์ฌ๋ ์ฐ๋ฆฌ๊ฐ ์ํ์ง ์๋ ๋ฐฉํฅ์ผ๋ก ํ๋ํ๋ agent๋ก ํ์ต๋๋ ๊ฒ์
๋๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ์ฐ๋ฆฌ๋ reward function์ ๋ณํ๋ฅผ ์ฃผ์ด๋ optimal policy๊ฐ ๋ณํ์ง ์๋ reward function์ ํํ๊ฐ ํ์ํฉ๋๋ค. ์ด๋ฐ ์ฑ์ง์ ๋ณธ ๋
ผ๋ฌธ์์ Policy invariance์ด๋ผ๊ณ ํํํฉ๋๋ค.\n๋ณธ ๋
ผ๋ฌธ์์๋ reward function์ด ๋ณํ์ ๋ํด policy invariance๋ฅผ ๋ณด์ฅํ๋, ํนํ positive reward cycle์ ๋ฐฉ์งํ๋ reward function์ ํํ๋ฅผ ์ ์ํฉ๋๋ค.\nPreliminaries Definitions (finite-state) Markov decision process (MDP) $M$ : $(S, A, T, \\gamma, R) $\n $S$ : a finite set of states $A$ : a set of actions $T$ : the next state transition probabilities $\\gamma$ : discount factor $R$ : reward function, $R: S \\times A \\times S \\mapsto \\mathbb{R}$ with $R(s, a, s\u0026rsquo;)$\n $\\pi$ : policy over set of states $S$ is any function $\\pi : S \\mapsto A$\n Value function : $ V^{\\pi}_{M}(s) = E[r_1 + \\gamma r_2 + \u0026hellip;; \\pi, s๋ง] $\n Q-function : $ Q^{\\pi}_{M}(s, a) = E_{s\u0026rsquo; \\sim P_{sa}(\\cdot)}[R(s, a, s\u0026rsquo;) + \\gamma V^{\\pi}_{M}(s\u0026rsquo;) ] $\n $\\textbf s_0โ$: ๋ณธ ๋
ผ๋ฌธ์์๋ $s_0$๋ฅผ absorbing state๋ผ ํ๋ฉฐ, undiscounted MDP($\\gammaโ$ = 1) ์ผ ๋ ๋์ด์ reward๋ฅผ ์ฃผ์ง ์๋ state๋ฅผ ํํํฉ๋๋ค. ์ด๋ episodic task๋ฅผ continuing task๋ก ์ผ๋ฐํํ ๋ terminal state์ ๊ฐ์ ์ญํ ์ ํฉ๋๋ค. $s_0โ$์์๋ ๋ชจ๋ action์ด $s_0โ$๋ก์ state transition (์ํ ์ ์ด) ๋ง์ ๋ฐ์์ํต๋๋ค. ์๋ ๊ทธ๋ฆผ์ด ํ๋์ ์์์
๋๋ค. (๋ณธ ๋
ผ๋ฌธ์ figure 3)[2] \n ์ผ๋ฐ์ ์ผ๋ก $s_0$๋ episode์ ๊ฐ์ฅ ์ฒซ๋ฒ์งธ state๋ฅผ ํํํ์ง๋ง ๋ณธ ๋
ผ๋ฌธ์์๋ absorbing state๋ฅผ ๋ปํฉ๋๋ค.\n Shaping Rewards ๋ณธ ๋
ผ๋ฌธ์์๋ reward shaping function์ ์ถ๊ฐํ ์๋ก์ด reward function ํํ๋ฅผ ์ ์ํฉ๋๋ค.\n$$ R\u0026rsquo; = R + F $$\n$$ F : S \\times A \\times S \\mapsto \\mathbb{R} $$\n๊ทธ๋ฆฌ๊ณ $R\u0026rsquo;$ ์ ์ด์ฉํด MDP๋ฅผ ์๋กญ๊ฒ ์ ์ํฉ๋๋ค.\n$$ M\u0026rsquo; = (S, A, T, \\gamma, R\u0026rsquo;) $$\n$F$ ๋ shaping reward function ๋ผ๊ณ ํฉ๋๋ค. $F$๋ฅผ ์ด์ฉํด ์ํ๋ shaping term์ ์ถ๊ฐํ ์ ์์ต๋๋ค. ์๋ฅผ๋ค์ด agent๊ฐ goal์ ๊ฐ๊น์์ง๋๋ก reward shaping์ ํ๊ณ ์ถ๋ค๋ฉด ๋ค์๊ณผ ๊ฐ์ด $F$๋ฅผ ์ ์ํ ์ ์์ต๋๋ค.\n$$ F(s, a , s\u0026rsquo;) = \\begin{cases} r, \u0026amp; \\mbox{if } s\u0026rsquo; \\ closer \\ to \\ the \\ goal \\ than \\ s. \\\\\\ 0, \u0026amp; \\mbox{otherwise} \\end{cases} \\text{, where } r \\text{ is some positive reward.}$$\n$M\u0026rsquo;$์ $M$๊ณผ ๊ฐ์ state, action, transition probablities, discount factor๋ฅผ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ ๊ฐํํ์ต ์๊ณ ๋ฆฌ์ฆ์ ๋์ผํ๊ฒ ์ ์ฉํ ์ ์์ต๋๋ค.\n์ฐ๋ฆฌ์ ๋ชฉํ๋ ์ ์ํ MDP ๋ชจ๋ธ๊ณผ ๊ฐํํ์ต ์๊ณ ๋ฆฌ์ฆ์ ์ด์ฉํด ์ต์ ์ policy๋ฅผ ์ฐพ์๋ด๋ ๊ฒ์
๋๋ค. ๊ทธ๋ฌ๊ธฐ ์ํด์๋ ๋ค์์ ์ง๋ฌธ๋ค์ ๋๋ตํ ํ์๊ฐ ์์ต๋๋ค.\n ์ด๋ค ํํ์ $F$ ๋ฅผ ์ฌ์ฉํด์ผ $M\u0026rsquo;$ ์์์ optimal policy๊ฐ $M$์์๋ ๋์ผํ๊ฒ optimal policy๋ผ๋ ๊ฒ์ ๋ณด์ฅํ ์ ์์์ง? ์ด ๋์ $M\u0026rsquo;$๋ positive reward cycle์ ๋ฐฉ์งํ ์ ์๋์ง? Main results ์ด๋ฒ ์ ์์๋ ์ด๋ค ํํ์ $F$๊ฐ policy invariance๋ฅผ ๋ณด์ฅํ๋์ง ์์๋ด
์๋ค.\n์์ Introduction์์ ์์ ๊ฑฐ ๋ฌธ์ ๋ฅผ ์์๋ก ๋ค์์ต๋๋ค. ์ด ๋ฌธ์ ์์ ๋จ์ํ goal๋ก ๊ฐ๊น์์ง๋ ์ถ๊ฐ์ ์ธ reward๋ฅผ ๋ฐ์์์ผฐ๊ณ , ์ด๋ก ์ธํด ์์์ง์ ์ ๊ธฐ์ค์ผ๋ก ์์ ๊ทธ๋ฆฌ๋ฉฐ ๊ณ์ํด์ ํ์ ํ๋ policy๊ฐ ํ์ต๋์์ต๋๋ค. ์ด๋ฐ ํ์์ด ๋ฐ์ํ๋ ์ด์ ๋ agent๊ฐ ํน์ state๋ฅผ ์ํ($ s_1 \\rightarrow s_2 \\rightarrow \u0026hellip; \\rightarrow s_n \\rightarrow s_1 \\rightarrow \u0026hellip; $)ํ๋ ๊ฒฝ์ฐ์ $F$์ ์ดํฉ์ด 0๋ณด๋ค ํฐ ๊ฐ์ ๊ฐ๊ฒ ๋๊ธฐ ๋๋ฌธ์
๋๋ค.\n$$F(s_1, a_1, s_2) + F(s_2, a_2, s_3) + \u0026hellip; + F(s_n, a_n, s_1) \u0026gt; 0$$\nGoal์ ๋๋ฌํ๋ agent๋ฅผ ํ์ต์ํค๊ธฐ ์ํด์๋ ๋ชฉ์ ์ ์ฑ์ทจ(goal์ ๋๋ฌ)ํ๋ ๊ฒฝ์ฐ์ ๋ํด์๋ง positive reward๋ฅผ ๋ฐ์์์ผ์ผ ํฉ๋๋ค. ํ๋, ์์ ๊ฒฝ์ฐ $F$์ ์ํด ํน์ state๋ค์ ์ํํ๋ ๊ฒ์ผ๋ก๋ reward๊ฐ ์ฆ๊ฐํ๊ฒ ๋๊ณ , ๊ทธ๋ก ์ธํด agent๋ ํน์ ๊ตฌ๊ฐ์ ์ํํ๋ suboptimal policy๋ฅผ ํ์ตํ๊ฒ ๋ฉ๋๋ค. ์ด๋ฌํ positive reward cycle ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด ๋ณธ ๋
ผ๋ฌธ์์๋ ๋ค์๊ณผ ๊ฐ์ ํํ์ $F$๋ฅผ ์ ์ํฉ๋๋ค.\n$$ F(s,a,s\u0026rsquo;) = \\Phi (s\u0026rsquo;) - \\Phi (s) $$\n์ฌ๊ธฐ์ $\\Phi$ ๋ฅผ potential function ์ด๋ผ ํ๋ฉฐ $F$ ๋ฅผ potential-based shaping function ์ด๋ผ๊ณ ํฉ๋๋ค. $F$ ๊ฐ ๋ค์ state์ ํ์ฌ state์ ๋ํ ํจ์์ ์ฐจ์ด๋ก ์ ์๋์๊ธฐ ๋๋ฌธ์ ์์ ์์์ฒ๋ผ cycle์ด ๋ฐ์ํ๋๋ผ๋ reward๊ฐ ๊ณ์ํด์ ์ฆ๊ฐํ์ง ์์ต๋๋ค.\n$$F(s_1, a_1, s_2) + F(s_2, a_2, s_3) + \u0026hellip; + F(s_n, a_n, s_1) = 0 $$\n๋ ๋์๊ฐ ๋ณธ ๋
ผ๋ฌธ์์๋ transition probablity์ reward function์ด prior knowledge๋ก ์ฃผ์ด์ง์ง ์์์ ๋, potential-based shaping function $F$๊ฐ policy invariance๋ฅผ ๋ณด์ฅํ๋ ์ ์ผํ $F$์์ ์ฆ๋ช
ํฉ๋๋ค.\nTheorem 1 ์์์ $Sโ$, $Aโ$, $\\gammaโ$์ ๋ํด ์์์ shaping reward function๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.\n$$F:S\\times A \\times S \\mapsto \\mathbb{R} $$\n์ด๋, ๋ชจ๋ $s \\in S - {s_0}, a \\in A, s\u0026rsquo; \\in Sโ$์ ๋ํด ์๋ ์์ ๋ง์กฑํ๋ real-valued function $\\Phi: S \\mapsto \\mathbb{R}โ$ ๊ฐ ์กด์ฌํ๋ฉด $Fโ$๋ฅผ potential-based shaping function ์ด๋ผ๊ณ ํฉ๋๋ค.\n$$ F(s,a,s\u0026rsquo;) = \\gamma\\Phi(s\u0026rsquo;) - \\Phi(s), \\text{where} \\ S - {s_0} = S \\ \\text{if} \\ \\gamma \u0026lt; 1. $$\n๊ทธ๋ฆฌ๊ณ potential-based shaping function $ F $ ๋ optimal policy consistency๋ฅผ ๋ณด์ฅํ๊ธฐ ์ํ ํ์์ถฉ๋ถ ์กฐ๊ฑด์
๋๋ค.\n (์ถฉ๋ถ์กฐ๊ฑด) $F$ ๊ฐ potential-based shaping function ์ด๋ฉด $M\u0026rsquo;$์์์ ๋ชจ๋ optimal policy๋ $M$์์๋ optimal์ด๋ค. (ํ์์กฐ๊ฑด) $F$ ๊ฐ potential-based shaping function์ด ์๋๋ผ๋ฉด $M\u0026rsquo;$์์์ optimal policy๊ฐ $M$์์๋ optimal์์ ๋ง์กฑํ๋ transition๊ณผ reward function์ด ์กด์ฌํ์ง ์๋๋ค. Theorem 1์ ๋ฐ๋ฅด๋ฉด ์์์ ์ธ๊ธํ optimal policy consistency๋ฅผ ๋ง์กฑํ๋ shaping function $F$๊ฐ ์ (2)์ ํํ์ด๊ณ , ์ด ํํ๊ฐ optimal policy consistency๋ฅผ ๋ง์กฑํ๋ ์ ์ผํ $F$์
๋๋ค.\nProof: ์ถฉ๋ถ์กฐ๊ฑด MDP $Mโ$์ ๋ํ optimal Q-function $Q^{*}_{M}(s,a)โ$๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.\n$$ Q^{*}_{M}(s,a) = E_{s\u0026rsquo; \\sim P_{sa}(\\cdot)} \\bigg[R(s,a,s\u0026rsquo;) + \\gamma \\underset{a\u0026rsquo; \\in A}{\\max} Q^{*}_{M} (s\u0026rsquo;, a\u0026rsquo;)\\bigg]โ $$\n์ด ์์ $\\Phi$์ ์ถ๊ฐํด์ ์ ๊ฐํฉ๋๋ค.\n$$ \\begin{align} Q^{*}_{M}(s,a) - \\Phi(s) \u0026amp;= E_{s\u0026rsquo; \\sim P_{sa}(\\cdot)} \\bigg[R(s,a,s\u0026rsquo;) + \\gamma \\big(\\underset{a\u0026rsquo; \\in A}{\\max} Q^{*}_{M} (s\u0026rsquo;, a\u0026rsquo;) + \\Phi(s\u0026rsquo;) - \\Phi(s\u0026rsquo;)\\big)\\bigg] - \\Phi(s)โ \\\\\n\u0026amp;= E_{s\u0026rsquo; \\sim P_{sa}(\\cdot)} \\bigg[R(s,a,s\u0026rsquo;) + \\gamma \\Phi(s\u0026rsquo;) - \\Phi(s) + \\gamma \\big(\\underset{a\u0026rsquo; \\in A}{\\max} Q^{*}_{M} (s\u0026rsquo;, a\u0026rsquo;) - \\Phi(s\u0026rsquo;)\\big)\\bigg] \\\\\n\\end{align} $$\n์ฌ๊ธฐ์ $ \\hat Q_{M\u0026rsquo;} (s,a) \\triangleq Q^{*}_{M}(s,a) - \\Phi(s)โ $ ๋ผ ์ ์ํ๊ณ $F(s,a,s\u0026rsquo;) = \\gamma \\Phi(s\u0026rsquo;) - \\Phi(s)โ$ ๋ก ์นํํฉ๋๋ค.\n$$ \\begin{align} \\hat Q_{M\u0026rsquo;} \u0026amp;= E_{s\u0026rsquo; \\sim P_{sa}(\\cdot)} \\bigg[R(s,a,s\u0026rsquo;) + F(s,a,s\u0026rsquo;) + \\gamma \\underset{a\u0026rsquo; \\in A}{\\max} \\hat Q_{M\u0026rsquo;} (s\u0026rsquo;, a\u0026rsquo;)\\bigg] \\\\\n\u0026amp;= E_{s\u0026rsquo; \\sim P_{sa}(\\cdot)} \\bigg[R\u0026rsquo;(s,a,s\u0026rsquo;) + \\gamma \\underset{a\u0026rsquo; \\in A}{\\max} \\hat Q_{M\u0026rsquo;} (s\u0026rsquo;, a\u0026rsquo;)\\bigg] \\\\\n\\end{align} $$\n์ ์์ ๋ฐ๋ฅด๋ฉด $ \\hat Q_{M\u0026rsquo;} (s,a) $๋ ๊ฒฐ๊ตญ MDP $ M\u0026rsquo;(S, A, T, R\u0026rsquo;, \\gamma) $ ์์์ Q function $ Q_{M\u0026rsquo;} (s,a)$ ์ ๊ฐ์ ํํ๊ฐ ๋ฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ $M\u0026rsquo;$์ด undiscounted case ($ \\gamma = 1 $)์ด๊ณ $\\Phi(s_0) = 0 $์ด๋ผ ๊ฐ์ ํ์ ๋ $$ \\hat Q_{M\u0026rsquo;}(s_0, a) = Q^{*}_{M}(s_0,a) - \\Phi(s_0) = 0 - 0 = 0 $$ ์ ๋ง์กฑํ๊ฒ ๋ฉ๋๋ค. ๋ฐ๋ผ์ $\\hat{Q}_{M\u0026rsquo;} (s,a)โ$๋ Bellman equation์ ๋ง์กฑํ๋ฉฐ unique optimal Q-function์ ๋ฐ๋์ ๊ฐ๊ฒ ๋ฉ๋๋ค.\n๊ทธ๋ฌ๋ฏ๋ก $M\u0026rsquo;โ$์์์ optimal policy $\\pi^*_{M\u0026rsquo;}(s)โ$๋ ๋ค์ ์์ ๋ง์กฑํฉ๋๋ค.\n$$ \\begin{align} \\pi^*_{M\u0026rsquo;}(s) \u0026amp;\\in \\underset{a\\in A}{\\arg\\max} Q^*_{M\u0026rsquo;}(s,a) \\\\\n\u0026amp;= \\underset{a\\in A}{\\arg\\max} Q^*_{M}(s,a) - \\Phi(s) \\\\\n\u0026amp;= \\underset{a\\in A}{\\arg\\max} Q^*_{M}(s,a) \\end{align} $$\n์ฆ, $M\u0026rsquo;$์์์ optimal policy $\\pi^*_{M\u0026rsquo;}(s)$๋ $M$์์ ๋ํ optimal policy์์ ์ ์ ์์ต๋๋ค.\n ํ์์กฐ๊ฑด์ ์ฆ๋ช
์ ๋
ผ๋ฌธ์ Appendix A๋ฅผ ์ฐธ๊ณ ํ์๊ธฐ ๋ฐ๋๋๋ค.\n ์์ Theorem 1์ ํ์์ถฉ๋ถ ์กฐ๊ฑด์ ๋ํ ์ฆ๋ช
์ ํตํด potential-based shaping function์ด policy invariance๋ฅผ ๋ณด์ฅํ๋ ์ ์ผํ $F$์์ ์ฆ๋ช
ํ์์ต๋๋ค. ๊ทธ๋ ๋ค๋ฉด potential-based shaping function์ $\\Phi$๋ ์ด๋ค ์์ผ๋ก ์ ์ํด์ผํ ๊น์? ๋
ผ๋ฌธ์์๋ Corollary 2๋ฅผ ํตํด $\\Phiโ$๋ฅผ ๊ตฌํ๋ ํ๊ฐ์ง ๋ฐฉ๋ฒ์ ์์ ํฉ๋๋ค.\n Corollary(๋ฐ๋ฆ ์ ๋ฆฌ)๋ Theorem์ผ๋ก๋ถํฐ ๋ฐ๋ก ์ฆ๋ช
ํ ์ ์๋ ์ฐธ์ธ ๋ช
์ ๋ฅผ ๋งํฉ๋๋ค.\n Corollary 2 $ F(s,a,s\u0026rsquo;) = \\gamma \\Phi(s\u0026rsquo;) - \\Phi(s) $ ์ด๊ณ $ \\gamma = 1 $ ์ผ ๋ $ \\Phi(s_0) = 0 $๋ฅผ ๊ฐ์ ํ๋ฉด, ๋ชจ๋ $ s \\in S, a \\in A $ ๋ํด ๋ค์ ์์ ๋ง์กฑํฉ๋๋ค.\n$$ Q^*_{M\u0026rsquo;}(s,a) = Q^*_{M}(s,a) - \\Phi(s), \\\\\nV^*_{M\u0026rsquo;}(s) = V^*_{M}(s) - \\Phi(s). $$\nProof: Corollary 2 ์ (3)์ Theorem 1์ ์ถฉ๋ถ์กฐ๊ฑด์ ์ฆ๋ช
๊ณผ์ ์ ํตํด ์ฆ๋ช
๋์์ต๋๋ค. $ V^*(s) = \\underset{a \\in A}{\\max}Q^*(s,a) $ ์ด๊ธฐ ๋๋ฌธ์ ์ (3)์ ๋ง์กฑํ๋ฉด ์ (4)๋ ๋ง์กฑํฉ๋๋ค.\nCorollary 2๋ฅผ ํตํด $ V^*_{M\u0026rsquo;}(s) = V^*_{M}(s) - \\Phi(s) $์ด ์ฐธ์์ ์๊ฒ ๋์์ต๋๋ค. ๋
ผ๋ฌธ์์๋ (4)๋ฅผ ํตํด $ \\Phi โ$์ ๊ฐ์ฅ ์ฌ์ด ํํ๋ฅผ ์ ์ํฉ๋๋ค.\npotential-based function ์ค์ ํ๊ฒฝ์์ $ \\Phi $๋ฅผ ์ ์ํ๊ธฐ ์ํด์๋ domain์ ๋ํ expert knowledge๊ฐ ํ์ํฉ๋๋ค. ๋ง์ฝ domain knowledge (MDP $M$)๋ฅผ ์ถฉ๋ถํ ์๊ณ ์๋ค๋ฉด $\\Phi$๋ฅผ ๋ค์๊ณผ ๊ฐ์ด ๊ฐ์ ํ ์ ์์ต๋๋ค.\n$$ \\Phi(s) = V^*_{M}(s) $$\n$\\Phi$๋ฅผ ์์ ๊ฐ์ด ๊ฐ์ ํ๋ฉด Corollary 2์ (4)์ ๋ฐ๋ผ $M\u0026rsquo;$์ ๋ํ value function์ $V^*_{M\u0026rsquo;}(s) \\equiv 0$์
๋๋ค. ๋
ผ๋ฌธ์์๋ ์ด๋ฐ ํํ์ value function์ด ํ์ต์ ์ฉ์ดํ๋ค๊ณ ํฉ๋๋ค. ๋ํ ์์ ๋ค๋ฅธ ํํ์ $\\Phi$๋ฅผ ์ด์ฉํด๋ ์ถฉ๋ถํ policy invariance๋ฅผ ๋ณด์ฅํ๋ค๊ณ ์ฃผ์ฅํฉ๋๋ค.\n $M\u0026rsquo;$์์์ (near-) optimal policy๊ฐ $M$์์๋ (near-) optimal policy์์ ๋ณด์ฅํ๋ค ๋ผ๊ณ ์์ ํ๋ฉฐ Remark 1 ์ ํตํด optimal์ด ์๋ near optimal ์์๋ Theorem 1์ด ์ฑ๋ฆฝํจ์ ์ธ๊ธํฉ๋๋ค. Experiments Experiments ์ ์์๋ ๋ ๊ฐ์ง grid world ํ๊ฒฝ์์ potential-based shaping function์ ๋ณํ๋ฅผ ์ฃผ๋ฉฐ ๋น๊ต ์คํํ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์ฌ์ค๋๋ค. ๋ณธ ๋
ผ๋ฌธ์์๋ ์ด ์คํ์ ํตํด ํ์ต ์๋ ํฅ์์ ์ํ ํฉ๋ฆฌ์ ์ธ $\\Phi$๋ฅผ ์ ํ๋ ๋ฐฉํฅ์ ์ค๋ช
ํ๋ ๊ฒ์ด ๋ชฉ์ ์ด๋ผ๊ณ ๋งํฉ๋๋ค.\n10 x 10 grid world 10 x 10 grid world ํ๊ฒฝ์ no discount setting ($ \\gamma = 1 $)์ด๋ฉฐ ๋งค step ๋น -1์ reward(penalty)๋ฅผ ๋ฐ์ต๋๋ค. 1 step action์ ํ ๋ 80% ํ๋ฅ ๋ก exploitation ํ๊ณ 20% ํ๋ฅ ๋ก exploration (random action) ํฉ๋๋ค. ์ ์๋ค์ ์ด์ ์ ์์ ์ข์ shaping potential $ \\Phi(s) = V^*_{M}(s) $ ๋ฅผ ์ ์ํ์ต๋๋ค. ์ด ์คํํ๊ฒฝ์์์ $ V^*_{M} $ ์ ํ์ฌ state์์ Goal ๊น์ง์ Manhattan distance๋ก ๋ณผ ์ ์์ต๋๋ค. ์ฌ๊ธฐ์ 80%์ ํ๋ฅ ๋ก exploitationํ๋ ๊ฒ์ ๊ฐ์ํ์ฌ $V^*_{M}$์ ๊ฐ๊น์ด $\\Phiโ$ ๋ฅผ ๋ค์๊ณผ ๊ฐ์ด ์ ์ํฉ๋๋ค.\n$$ \\Phi_0(s) = \\hat{V}_M(s) = - {MANHATTAN}(s, GOAL) / 0.8 $$\n ์ฐธ๊ณ : Manhattan distance wiki\n ๊ทธ๋ฆฌ๊ณ $V^*_{M}$์ ์ข ๋ ๋จผ $\\Phiโ$ ์ ๋ํด์๋ shaping potential์ด ์ ๋์ํ๋ ๊ฒ์ ๋ณด์ด๊ธฐ ์ํด $ \\Phi(s) = 0.5 \\Phi_0(s) = 0.5 \\hat{V}_M(s) โ$ ์ ๋ํด์๋ ์คํํฉ๋๋ค. ์คํ ๊ฒฐ๊ณผ๋ ์๋์ ๊ฐ์ต๋๋ค.\n์ ๊ทธ๋ํ๋ฅผ ํตํด $0.5 \\Phi_0(s)$์ $\\Phi_0(s)$๋ฅผ shaping potential๋ก ์ฌ์ฉํ์๋, shaping์ ์ฌ์ฉํ์ง ์์ ๊ฒฝ์ฐ์ ๋นํด ํ์ต์ด ๋น ๋ฅธ ์๋๋ก ์๋ ดํจ์ ํ์ธ ํ ์ ์์ต๋๋ค. ๋ํ $0.5\\Phi_0(s)$๋ฅผ ์ฌ์ฉํ๋๋ผ๋ $\\Phi_0(s)$๋ฅผ ์ฌ์ฉํ์ ๋์ ๊ฑฐ์ ์ ์ฌํ๊ฒ ํ์ต ์๋๊ฐ ํฅ์๋จ์ ๋ณด์ฌ์ค๋๋ค. ๋์๊ฐ ์กฐ๊ธ ๋ ํฐ ํ๊ฒฝ์ธ 50 x 50 grid world ํ๊ฒฝ์์๋ potential-based shaping reward๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ์ ์ฑ๋ฅ์ด ๋ ๋น ๋ฅด๊ฒ ํฅ์๋จ์ ํ์ธ ํ ์ ์์ต๋๋ค.\n5 x 5 grid world with subgoals ์ด๋ฒ ์คํ์์๋ subgoal์ด ์๋ ํ๊ฒฝ์์๋ potential-based shaping reward์ด ์ ์๋ํ๋์ง ํ์ธํฉ๋๋ค.\nAction๊ณผ reward function์ ์ค์ ์ ์ด์ 10 x 10 grid world ํ๊ฒฝ๊ณผ ๋์ผํฉ๋๋ค. ์ ๊ทธ๋ฆผ์ grid ๋ด๋ถ์ ํ์๋ ์ซ์๋ ๊ฐ๊ฐ flag๋ฅผ ์๋ฏธํ๊ณ , agent๋ ๋ชจ๋ flag๋ฅผ ์์๋๋ก (์ค๋ฆ์ฐจ์) ํ๋ํ ๋ค goal์ ๋์ฐฉํด์ผํฉ๋๋ค. ์ด ํ๊ฒฝ์ ๋ํ potential-function์ ์ ์ํด๋ด
์๋ค. ๋ง์ฝ subgoal์ ์์น๋ฅผ ๋ชจ๋ ์๊ณ ์๊ณ ์ด์ ํ๊ฒฝ๊ณผ ๋์ผํ๊ฒ 80%์ exploitation์ ํ๋ค๋ฉด ์ฐ๋ฆฌ๋ goal์ ๋์ฐฉํ๊ธฐ๊น์ง์ timestep t๋ฅผ ์์ธกํ ์ ์์ต๋๋ค. ์ด ํ๊ฒฝ์์๋ ์ด์ subgoal์์ ๋ค์ subgoal๋ก ๊ฐ๊ธฐ๊น์ง ํ์ํ step์ ๊ฐฏ์๊ฐ ๋ชจ๋ ์ ์ฌํ๊ธฐ ๋๋ฌธ์ n๋ฒ์งธ subgoal์ ๋๋ฌํ๊ธฐ ์ํ step์ $((5-n_s)/5)t$ step์ด๋ผ๊ณ ํ ์ ์์ต๋๋ค. ์ด๋ $n_s$๋ $s$ ์ผ๋ ํต๊ณผํ subgoal์ ์๊ฐ ๋ฉ๋๋ค.\n์์์ ๋์ถํ ์์ ์ด์ฉํ์ฌ potential-function์ ๋ค์๊ณผ ๊ฐ์ด ์ ์ํฉ๋๋ค. $$ \\Phi_0(s) = -((5 - n_s - 0.5)/5 )t $$\n 0.5๋ ์ผ๋ฐ์ ์ผ๋ก agent๊ฐ n๋ฒ์งธ subgoal๊ณผ n+1๋ฒ์งธ subgoal ์ค๊ฐ์ ์๊ธฐ ๋๋ฌธ์ ์ด๋ฅผ ๋ณด์ ํด์ฃผ๊ธฐ ์ํ ๊ฐ์
๋๋ค.\n ๋ ๋ค๋ฅธ potential-function์ผ๋ก 10 x 10 grid world ํ๊ฒฝ์์ ์ฌ์ฉํ๋ $\\hat{V}_M(s)โ$๋ฅผ ์ฌ์ฉํฉ๋๋ค. $$ \\Phi_1(s) = \\hat{V}_M(s) = - {MANHATTAN}(s, GOAL) / 0.8 $$ ์ด๋ ๊ฒ ์ ์ํ potential function์ ํตํด ์คํํ ๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.\n์ ๊ทธ๋ํ๋ ์์์ ๋ถํฐ no shaping, $\\Phi = \\Phi_0(s)$, $\\Phi = \\Phi_1(s)$์ ํด๋นํฉ๋๋ค. ์ด์ ์คํ์์ ์ ์ํ $\\Phi_1$ ๋ฟ๋ง ์๋๋ผ ์๋ก ์ ์ํ $\\Phi_0$์ ์ฌ์ฉํ์์๋์๋ ๋ง์ฐฌ๊ฐ์ง๋ก shaping์ ์ฌ์ฉํ์ง ์์ ๊ฒฝ์ฐ๋ณด๋ค ํ์ต์๋๊ฐ ํฅ์๋์์์ ํ์ธ ํ ์ ์์ต๋๋ค.\nDiscussion and Conclusions ์ด๋ฒ ๋
ผ๋ฌธ์์๋ reward shaping์ ์ํ function $F$๋ฅผ ์ ์ํ์์ต๋๋ค. $F$๋ potential-based shaping reward $\\gamma \\Phi(s\u0026rsquo;) - \\Phi$๋ก ์ ์ํ๋ฉฐ ์ด๊ฒ์ด (near-) optimal์ ์ ์งํ๋ shaping reward์์ ์ฆ๋ช
ํ์์ต๋๋ค. ๋ํ ์คํ์ ํตํด distance-based ํ๊ฒฝ๊ณผ subgoal-based ํ๊ฒฝ์์ potential function์ ์ ์ํด๋ณด๊ณ ์ฑ๋ฅ์ด ํฅ์๋จ์ ํ์ธํ์์ต๋๋ค. ์ด๋ฒ ๋
ผ๋ฌธ์์ ์์๋ณธ potential-based shaping function์ ํํ๋ ์ถํ IRL๊ณผ ์ดํ์ reward shaping ๋
ผ๋ฌธ์์ ๊ณ์ํด์ ์ฌ์ฉ๋๊ณ ์ธ์ฉ๋ฉ๋๋ค.\nReference [1] A. Y. Ng et al., \u0026ldquo;Policy invariance under reward transformation: Therory and application to reward shaping.\u0026rdquo; Proceedings of the Sixteenth International Conference on Machine Learning(pp.278-287), 1999.\n [2] Sutton, R. and Barto, A., \u0026ldquo;3.4 Unified Notation for Episodic and Continuing,\u0026rdquo; in Reinforcement Learning: An Introduction, 2nd ed., MIT Press, 2018.\n","date":1561522500,"expirydate":-62135596800,"kind":"page","lang":"en","lastmod":1561522500,"objectID":"3b66bdea0d4ebb65aa1c834d85d9b250","permalink":"/post/2019-06-26-policy-invariance-under-reward-transformation_theory-and-application-to-reward-shaping/","publishdate":"2019-06-26T13:15:00+09:00","relpermalink":"/post/2019-06-26-policy-invariance-under-reward-transformation_theory-and-application-to-reward-shaping/","section":"post","summary":"Reward shaping method to assure policy invaraiance in RL","tags":[],"title":"[Paper Study] Policy invariance under reward transformation","type":"post"},{"authors":["young-kim","whi-kwon"],"categories":[],"content":" Introduction SOTA ์ฑ๋ฅ์ ๋ด๋ ๋ง์ detector์์ anchor๋ฅผ ํ์ฉํด์ BBox coordination์ ํ์ตํฉ๋๋ค. ์ด๋ฒ ๊ธ์์๋ anchor๊ฐ ๋ฌด์์ธ์ง, ์ด๋ป๊ฒ one-stage, two-stage detector์์ ์ฌ์ฉ๋๋์ง์ ๊ดํด ์ดํด๋ณด๊ฒ ์ต๋๋ค.\n์ด ๊ธ์ ์ฌ์ฉ๋ script ๋ฐ jupyter notebook์ medipixel repository์ ์
๋ก๋ ๋์ด ์์ผ๋ ์ฐธ๊ณ ํ์๊ธฐ ๋ฐ๋๋๋ค.\n์ฝ๋ ์์ฃผ๋ก ์๊ฐํ๊ธฐ ๋๋ฌธ์ object detection, anchor๊ฐ ์ต์ํ์ง ์์ผ์ ๋ถ๊ป์๋ Andrew Ng ๊ต์๋์ด ์๊ฐํ์๋ ์์๊ณผ Jonathan Hui์ object detection ์๊ฐ ์๋ฃ๋ฅผ ๋ณด์๋ฉด ์ดํด์ ๋์์ด ๋์ค๊ฒ๋๋ค.\nImport Libraries ์ฝ๋๋ mmdet.v0.6rc0์ ๊ธฐ์ค์ผ๋ก ์ฐธ๊ณ ํ์ฌ ์ ์ํ์์ต๋๋ค.\nimport cv2 import numpy as np import matplotlib.pyplot as plt import matplotlib.ticker as plticker import torch import torch.nn.functional as F from matplotlib.lines import Line2D from matplotlib.patches import Patch from anchor_generator import (gen_base_anchors, get_anchors, grid_anchors, meshgrid) from assigner import assign_wrt_overlaps, bbox_overlaps from loss import binary_cross_entropy, smooth_l1_loss from prediction import predict_anchors from transforms import bbox2delta, delta2bbox from visualize import (draw_anchor_gt_overlaps, draw_anchor_samples_on_image, draw_base_anchor_on_grid, draw_pos_assigned_bboxes) What is Anchor? ์ฒซ ๋ฑ์ฅ: anchor๋ผ๋ ๊ฐ๋
์ Faster R-CNN์์ ์ฒ์์ผ๋ก ์ ์๋์์ต๋๋ค. ์ฃผ์ ์ฌ์ฉ์ฒ: anchor๋ ๋๋ถ๋ถ์ one-stage, two-stage detector์์ ์ฌ์ฉํ๋ฉฐ ๋ํ์ ์ผ๋ก๋ RetinaNet(one-stage)์ Faster R-CNN(two-stage)๊ฐ ์กด์ฌํฉ๋๋ค. [1] anchor๋ฅผ ์ฌ์ฉํ๋ ๋ชฉ์ object detection ๋ฌธ์ ์์ ์ฐ๋ฆฌ๋ ์ด๋ฏธ์ง ์์ ๋ฌผ์ฒด (object)๊ฐ ์๋ ์์ญ์ ์์ธกํ์ฌ Bounding Box(BBox)๋ฅผ ๊ทธ๋ ค์ผ ํฉ๋๋ค. ์ด ๋์, ์ด๋ฏธ์ง ์ ์ฒด๋ฅผ ํ๊บผ๋ฒ์ ๋ณด๊ณ ํน์ ์์น๋ฅผ ์์ธกํ๋ ๊ฒ๋ณด๋ค ํน์ ์์ญ BBox๋ง์ ๋ณด๊ณ ์ด ์์ ๋ฌผ์ฒด๊ฐ ์๋์ง๋ฅผ ์์ธกํ๋ ํธ์ด ๋ ์ฝ์ต๋๋ค. ๋ฐ๋ผ์ ์ด๋ฏธ์ง ์์ ๊ท ์ผํ๊ฒ ๋ง์ BBox(์ฆ, anchor)๋ฅผ ๊ทธ๋ฆฐ ๋ค์ ์ด anchor๋ค ์ค gt์ ์๋ก ๊ฒน์น๋ ์์ญ์ ๋์ด๋ฅผ ๊ธฐ์ค์ผ๋ก ์ ๋ณ๋ Anchor๋ฅผ ํ์ต์ ํ์ฉํ๊ฒ ๋ฉ๋๋ค. ๊ฐ object detector ๋ชจ๋ธ์ ์ ๊ณผ์ ์ ํตํด ์ ๋ณ๋ anchor๋ฅผ ์ด์ฉํ์ฌ anchor์ ์ ๋ต(ground-truth)๊ณผ์ ์ฐจ์ด์ ๋ํด์ ์์ธกํ๋๋ก ํ์ตํ๊ฒ ๋ฉ๋๋ค. (BBox regression) (์ด ๋, anchor์ ํฌ๊ธฐ๊ฐ ์ ์ ํ์ง ๋ชปํ ๊ฒฝ์ฐ์๋ ์ฐจ์ด์ ํธ์ฐจ๊ฐ ์ปค์ง๊ฒ ๋ ๊ฒ์ด๋ฏ๋ก ํ์ต์ด ์ด๋ ค์์ง ์ ์์ด์ ์ ์ ํ ํฌ๊ธฐ๋ฅผ ์ ์ ํ๋๊ฒ ์ค์ํฉ๋๋ค.) anchor๋ ๊ท ์ผํ ๊ฐ๊ฒฉ, ์ผ์ ํ ๊ท์น์ผ๋ก ์์ฑ ํ์ฌ, ๋ฌผ์ฒด๊ฐ ํน์ ์์น์ ์กด์ฌํ ๋๋ง ํ์ง๊ฐ ์ ๋๊ฑฐ๋, ํน์ ํน์ ์์น์์๋ ํ์ง๊ฐ ์ ๋์ง ์๋ ํ์์ ์ค์
๋๋ค. ์ด๋ฌํ ํน์ฑ์ translation-Invariance๋ผ๊ณ ํ๋ฉฐ, ๋๋ถ๋ถ์ object detector ๋ชจ๋ธ์ด ๊ฐ์ ํ๋ ค๊ณ ๋
ธ๋ ฅํ๋ ํน์ง์
๋๋ค. [2] Parameters ์ค๋ช
scale: feature map์์์ anchor ํฌ๊ธฐ(scale)์
๋๋ค. ratio: feature map์์์ anchor ๋น์จ(ratio)์
๋๋ค. stride: ์ด๋ฏธ์ง๋ฅผ ๊ธฐ์ค์ผ๋ก ์ด๋ ์ ๋ ๊ฐ๊ฒฉ์ผ๋ก anchor๋ฅผ ์์ฑํ ๊ฒ์ธ์ง ๋ํ๋ด๋ ๊ฐ์
๋๋ค.(์ฃผ๋ก ์ด๋ฏธ์ง์ feature map ํฌ๊ธฐ์ ๋น์จ ๊ฐ์ ์ฌ์ฉํฉ๋๋ค.) scale๊ณผ ratio๊ฐ feature map ๋ด์์์ anchor_base_size๋ฅผ ๋ง๋ค๊ฒ ๋ฉ๋๋ค. feature map์ ํฌ๊ธฐ๋ ์ด๋ฏธ์ง์ ๋๋น, ๋์ด๋ฅผ stride๋ก ๋๋ ๊ฐ์ด๊ธฐ ๋๋ฌธ์ ์ด๊ฒ ๋ฐ์๋ ์ด๋ฏธ์ง์์์ anchor ํฌ๊ธฐ๋ anchor_base_size * stride ์
๋๋ค. How to draw grid anchors ์ด์ ๋ถํฐ anchor๋ฅผ ์ด๋ฏธ์ง ์์ ๊ทธ๋ฆฌ๊ธฐ ์ํ์ฌ base_anchor์ stride์ ๋ํ์ฌ ์์๋ณด๊ฒ ์ต๋๋ค.\n base_anchor\n ํ๋์ anchor bbox๋ left top, right bottom์ x, y ์ขํ๋ฅผ ๊ฐ๊ฐ ๋ฐ์ [x1, y1, x2, y2]๋ก ํํํ ์ ์์ต๋๋ค. ํ ์ด๋ฏธ์ง ์์ ๊ทธ๋ ค์ง anchor์ ์งํฉ์ ๋ปํ๋ grid_anchor๋ feature map์ ์์ธก ๊ฐ์ ๋งค์นญ๋์ด์ผ ํ๊ธฐ ๋๋ฌธ์ feature map๊ณผ ๋์ผํ width, height๋ฅผ ๊ฐ์ง๋ฉฐ channel์ 4๋ก ๊ฐ์ต๋๋ค. base_anchor๋ scale, ratio 2๊ฐ parameter๋ก ๊ฒฐ์ ๋๋ anchor์ ์์ ์งํฉ์ด๋ฉฐ ๋ชจ๋ bbox๊ฐ ๊ฐ์ ์ค์ฌ์ ๊ฐ์ต๋๋ค. ํฌ๊ธฐ ๋จ์๋ 1 anchor_base_size ์
๋๋ค. [3] RetinaNet์ ๊ฒฝ์ฐ Octave scale์ ์ฌ์ฉํ์์ต๋๋ค. Faster R-CNN์์ ์ฌ์ฉํ, $2,4,6$ ๋ฑ $n$๋ฐฐ๋ก ์ฌ๋ผ๊ฐ๋ scale ๊ฐ๊ฒฉ ๋์ $2^0, 2^{\\frac 1 3}, 2^{\\frac 2 3}$๊ณผ ๊ฐ์ด (base scale)^(octave scale)์ ์ฌ์ฉํ์์ต๋๋ค. [4] anchor_base_size๋ ์ฃผ๋ก feature map์ ์ด๋ฏธ์ง ๋๋น stride ๊ฐ์ผ๋ก ๋ง์ด ์ฌ์ฉํ๋ฉฐ ์ด๋ฐ ๊ฒฝ์ฐ, feature map์ด ์์ ๊ฒฝ์ฐ stride๊ฐ ์ปค์ง๊ณ anchor bbox๋ ์ปค์ ธ์ ํฐ ๋ฌผ์ฒด๋ฅผ ๊ฒ์ถํ๊ธฐ์ ์ ํฉํด์ง๋๋ค. ๋ฐ๋์ ๊ฒฝ์ฐ์ ์์ ๋ฌผ์ฒด๋ฅผ ๊ฒ์ถํ๊ธฐ์ ์ ํฉํฉ๋๋ค. ํต์์ ์ผ๋ก CNN์ด ์์ feature map์ด high-level ์ ๋ณด๋ฅผ ์ ๋ํ๋ด์ด ํฐ ๋ฌผ์ฒด ์ ๋ณด๋ฅผ ์ ๋ค๋ฃจ๊ธฐ ๋๋ฌธ์ anchor_base_size๋ฅผ stride๋ก ์ฌ์ฉํ๋ ๊ฒ์ด ํฉ๋ฆฌ์ ์
๋๋ค. ๋ฐ๋์ ๊ฒฝ์ฐ์ ์์ ๋ฌผ์ฒด ์ ๋ณด๋ฅผ ์ ๋ค๋ฃจ๊ธฐ ๋๋ฌธ์ ๋ง์ฐฌ๊ฐ์ง๋ก anchor_base_size๋ฅผ stride๋ก ๋ค๋ฃจ๋ ๊ฒ์ด ํฉ๋ฆฌ์ ์
๋๋ค. stride\n feature map ์์์ grid cell์ ๊ฐ๊ฒฉ์ ์ค์ ์ด๋ฏธ์ง ์์์ 1 stride (image_width(height) // feature_map_width(height)) ์
๋๋ค. ์ฆ, ์ด๋ฏธ์ง ์์์ ์๊ฐํ๋ฉด anchor์ ์ค์ฌ ์ขํ๊ฐ stride ๋งํผ ๋จ์ด์ ธ์ ์กด์ฌํ๊ณ ๊ทธ ์์ base_anchor๊ฐ ๊ทธ๋ ค์ง๋ค๊ณ ๋ณผ ์ ์์ต๋๋ค. ์ด๋ ๊ฒ ์ด๋ฏธ์ง ์์ ๊ทธ๋ ค์ง ๊ฒ์ ๊ฐ์ ํ anchors๋ ๊ฐ bbox ๋ค์ ์กด์ฌํ๋(ํน์ ์กด์ฌํ์ง ์๋) ๋ฌผ์ฒด๋ฅผ ์์ธกํ๋๋ก ํ์ตํ ๋ ์ฌ์ฉ๋ฉ๋๋ค. Settings anchor๋ฅผ ๊ทธ๋ฆฌ๊ธฐ ์ํ hyperparameter๋ค์ ์ค์ ํ๊ฒ ์ต๋๋ค.\n gt_bboxes_list: ์์ธกํ๊ณ ์ ํ๋ ์ ๋ต์ธ gt์ bbox ๋ชฉ๋ก์
๋๋ค. gt bbox ํฌ๊ธฐ๋ฅผ ํฌ๊ฒ ์ก์ผ๋ฉด ๋ค์ํ positive anchor ํ๋ณด๋ค์ด ์๊ธฐ๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค. scales, ratios: base_anchor์ ํฌ๊ธฐ๋ฅผ ์กฐ์ ํด์ฃผ๋ ๊ฐ์
๋๋ค. ์ด ๊ฐ๋ค์ ์กฐ์ ํ๋ฉด anchor bbox์ ํํ๋ฅผ ํธํฅ๋๊ฒ ๋ง๋ค ์ ์์ต๋๋ค. anchor_base_size: feature map ์์ ์กด์ฌํ๋ anchor๊ฐ ์ด๋ฏธ์ง ์์์ ์กด์ฌํ ๋์ ํฌ๊ธฐ๋ฅผ ๊ฒฐ์ ํด์ฃผ๋ ๋น์จ ๊ฐ์
๋๋ค. anchor_stride(image_size // featmap_size)์ ๊ฐ์ ์ฃผ๋ก ๊ฐ์ต๋๋ค. ์ด ์๋ฃ์์๋ anchor_base_size == anchor_stride == image_size // featmap_size๋ฅผ ๊ฐ์ ํ๊ฒ ์ต๋๋ค. ์ด๋ฒ ์๋ฃ์์๋ 1๊ฐ feature map์ ๋ํด์๋ง anchor ๋ถ์์ ์งํํ๊ฒ ์ต๋๋ค. multi-level feature map(FPN ๋ฑ)์ด ์ฌ์ฉ๋๋ ๊ฒฝ์ฐ๋ ํ์ ์๋ฃ์์ ์ดํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.\nanchor_base_size = anchor_stride = 32 scales = torch.Tensor([2, 4, 8]) ratios = torch.Tensor([0.5, 1.0, 2.0]) featmap_size = [16, 16] device = 'cpu' image_shape = [256, 256, 3] anchors_per_grid = len(scales) * len(ratios) # x1y1x2y2 gt_bboxes_list = torch.FloatTensor([[32, 32, 32*3, 32*3]]).to(device) Base Anchor ๊ฐ๋จํ base_anchor๋ฅผ ์์ฑํ์ฌ feature map์ ์ฒซ ๋ฒ์งธ grid cell ์์น์ ํด๋นํ๋ ์ด๋ฏธ์ง ์์ ์ขํ์ ๊ทธ๋ ค๋ณด๊ฒ ์ต๋๋ค. ์ด base_anchor๊ฐ ์ค์ ์คํ์์๋ scales * ratios์ ๊ฐ์๋งํผ ์์ฑ๋๋ฉฐ feature map ์ ๊ฐ grid cell์ ์์น์ ์กด์ฌํ๊ฒ ๋ฉ๋๋ค.\n ๊ฐ feature map์ grid cell์ ์๋์ ์ด๋ฏธ์ง๋ฅผ ๊ธฐ์ค์ผ๋ก ํ๋ ์ขํ๋ฅผ ๊ฐ์ง๊ณ ์์ต๋๋ค. ์ด ์ขํ๋ค๋ง๋ค base_anchor๋ฅผ ์์น์ํค๋ฉด (feature map ๊ธฐ์ค ๊ฐ grid cell์ base_anchor๊ฐ ์กด์ฌํ๊ฒ ๋๋ฉด) ์ด๋ฏธ์ง ๊ธฐ์ค์ผ๋ก stride ๋งํผ ๋์๋์ base_anchor๊ฐ ์กด์ฌํ๋ ๋ชจ์ต์ ๋ณผ ์ ์์ต๋๋ค. base_anchor = gen_base_anchors(anchor_base_size, ratios, scales[:1]) draw_base_anchor_on_grid(base_anchor, anchor_base_size) ๊ฐ ์ขํ์ ์์นํ base_anchor๋ฅผ ํ ๋ฒ์ ๊ทธ๋ฆฌ๋ฉด ๋์ ํ ์์๋ณผ ์ ์์ ์ ๋๋ก ๋นฝ๋นฝํ ์ฌ๊ฐํ๋ค์ด ๋ง๋ค์ด์ง๊ธฐ ๋๋ฌธ์ ๋ช ๊ฐ์ ์ํ๋ง์ ์๊ฐํํ๊ณ ์ค์ ์ด๋ฏธ์ง ์์์ ์ด๋ค ๊ท์น์ผ๋ก anchor๋ฅผ ๊ทธ๋ ค๋ด๋์ง ํ์ธํด๋ณด๊ฒ ์ต๋๋ค.\n์๋ ๊ทธ๋ฆผ์์ ๊ฐ๊ฐ์ anchor๋ค์ด ์ผ์ ํ ๊ฑฐ๋ฆฌ(shifts)๋ฅผ ๊ฐ๊ฒฉ์ผ๋ก ํ์ฌ ๋ง๋ค์ด์ง๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค.\ndraw_anchor_samples_on_image(image_shape, anchor_base_size, featmap_size, scales, ratios) get_anchors๋ gen_base_anchor๋ก base_anchor๋ฅผ ๋ง๋ค๊ณ , feature map์ ์์น๋ฅผ ๋ํ๋ด๋ grid์ base_anchor๋ฅผ ๋ํ๊ณ ๊ฐ anchor์ valid ์ฌ๋ถ๋ฅผ ๊ณ์ฐํด์ anchors, flags๋ฅผ ๋ฐํํ๋ ํจ์์
๋๋ค. ๊ฐ step ๋ณ ์์ธํ ๋ด์ฉ์ ์ฝ๋๋ฅผ ์ฐธ๊ณ ํด์ฃผ์๊ธฐ ๋ฐ๋๋๋ค.\n flags์ anchor๊ฐ ์ด๋ฏธ์ง๋ฅผ ๋ฒ์ด๋ ๋ ํ์ต์์ ๋ฐฐ์ ํ๊ธฐ ์ํ flag ์
๋๋ค. anchors, flags = get_anchors(image_shape, featmap_size, anchor_base_size, anchor_stride, scales, ratios, device) # feature map 32x32 ๊ฐ pixel์ 9๊ฐ์ anchors assert anchors.shape[0] == featmap_size[0] * featmap_size[1] * 9 # anchor๋ฅผ ์ฌ์ฉํ ์ง ๋ง์ง ๊ฒฐ์ ํ๋ flags์ anchors์ ๊ฐ์๋ ๊ฐ์์ผ ํฉ๋๋ค. assert len(flags) == len(anchors) Anchor Selection ๊ฐ anchor๋ค์ gt์์ overlap ์ ๋์ ๋ฐ๋ผ positive, negative๋ก ๋๋๊ณ ๊ฐ๊ฐ์ ์ํ๋งํด์ ํ์ต์ ํ์ฉํฉ๋๋ค.\n one-stage์์๋ positive anchor์ 1, negative anchor์ 0์ ๋ฐฐ์ ํด์ RPNHead๋ฅผ ํ์ตํฉ๋๋ค. two-stage์์๋ positive anchor์ ๊ฐ์ฅ overlap์ด ํฐ gt์ class๋ฅผ ๋ฐฐ์ ํ๊ณ negative anchor์ 0์ ๋ฐฐ์ ํด์ BBoxHead๋ฅผ ํ์ตํฉ๋๋ค. positive anchor๋ classification, regression ํ์ต ๋ชจ๋์ ํ์ฉ๋ฉ๋๋ค. ๊ทธ๋์ผ ํน์ BBox์ ๋ํด์ object์ class์ BBox ์ขํ์ ์์ธกํ ์ ์๊ฒ ๋ฉ๋๋ค. negative anchor๋ classification์๋ง ํ์ฉ๋ฉ๋๋ค. ๊ทธ ์ด์ ๋ negative์ ๊ฒฝ์ฐ background๋ผ๋ ์ ๋ณด๋ ๊ฐ์ง๊ณ ์์ง๋ง, ์ด๋ ์์น์ ๋ฌผ์ฒด๊ฐ ์๋ค๋ ์ ๋ณด๋ ๊ฐ์ง๊ณ ์์ง ์๊ธฐ ๋๋ฌธ์
๋๋ค. [5] overlap์ IoU(Intersection over Union)๋ฅผ ํตํด ๊ณ์ฐํฉ๋๋ค. overlaps = bbox_overlaps(gt_bboxes_list, anchors) assert overlaps.shape == (len(gt_bboxes_list), anchors.shape[0]) anchor์ gt์ bbox overlaps์ธ IoU ๊ฐ์ feature map์ ๋ํ๋ด๋ณด๊ฒ ์ต๋๋ค. ํ๋์ box๋ gt์ ์์น๋ฅผ ๋ํ๋ด๋ฉฐ gt์ ๊ฐ๊น์ธ ์๋ก IoU ๊ฐ์ด ์ปค์ง๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค.\ndraw_anchor_gt_overlaps(overlaps, gt_bboxes_list, featmap_size, anchors_per_grid, anchor_stride=anchor_stride, draw_gt=True) ์ ๊ทธ๋ฆผ์์ gt๋ฅผ ์ ๊ฑฐํ๊ณ overlaps์ธ IoU ๊ฐ์ ์์น ๋ณ๋ก heatmap์ผ๋ก ๋ํ๋ด์์ต๋๋ค. ์ญ์๋, gt์ ๊ฐ๊น์์ง ์๋ก IoU ๊ฐ์ด ์ปค์ง๋ ๊ฒ์ ์ ์ ์์ต๋๋ค.\ndraw_anchor_gt_overlaps(overlaps, gt_bboxes_list, featmap_size, anchors_per_grid, anchor_stride) ์๋ ์ฝ๋์์๋ overlaps๋ฅผ ์ด์ฉํ์ฌ ๊ฐ anchor๋ฅผ postive sample ๋๋ negative sample๋ก ํ ๋นํฉ๋๋ค. gt์์ IoU๊ฐ ๋์ anchor๋ฅผ positive sample๋ก ์ผ๊ณ , IoU๊ฐ ๋ฎ์ anchor๋ฅผ ๋ฌด์์๋ก positive sample ๊ฐ์๋งํผ ๋ฝ์ negative sample๋ก ์ฌ์ฉํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ ํ์ต์ ํ๊ธฐ ์ํด์ classification, regression์ label์ ๊ตฌ์ฑํฉ๋๋ค.(pos_neg_cls_label, pos_gt_bboxes)\n# gt์์ `overlaps`์ ๋ฐ๋ผ pos, negative๋ฅผ ๋ฐฐ์ ํฉ๋๋ค. num_gts, assigned_gt_inds, max_overlaps = assign_wrt_overlaps(overlaps) # positive indices pos_inds = torch.nonzero(assigned_gt_inds \u0026gt; 0).squeeze(-1).unique() # negative indices neg_inds = torch.nonzero(assigned_gt_inds == 0).squeeze(-1).unique() # positive์ 1:1 ๋น์จ๋ก ํ์ต์ ์ฌ์ฉํ negative sample์ ์ป์ต๋๋ค. sampled_neg_inds = neg_inds[torch.randint(0, len(neg_inds), size=(len(pos_inds),))] # positive, negative์ label์ 0, 1๋ก ๊ตฌ์ฑํฉ๋๋ค. pos_neg_cls_label = torch.cat([torch.ones(len(pos_inds)), torch.zeros(len(sampled_neg_inds))]) bboxes = anchors # bboxes pos_bboxes = bboxes[pos_inds] # positive boxes pos_assigned_gt_inds = assigned_gt_inds[pos_inds] - 1 pos_gt_bboxes = gt_bboxes_list[pos_assigned_gt_inds, :] Anchor as a Target ์์ ์ธ๊ธํ ๊ฒ ์ฒ๋ผ anchor๋ฅผ ํ์ต์ ์ฌ์ฉํ๊ธฐ ์ํ์ฌ gt-anchor ์ฐจ์ด๋ฅผ ๊ณ์ฐํฉ๋๋ค. ์ด ๊ณผ์ ์ [6] anchor bbox๋ฅผ coordination([x1, y1, x2, y2]) ํํ์์ target(target_delta)์ผ๋ก ๋ณํํด์ฃผ๋ ๊ณผ์ ์ ์๋ฏธํฉ๋๋ค.(bbox2delta)\ntarget_deltas = bbox2delta(pos_bboxes, pos_gt_bboxes) # ๋ณํ์ด ์ ๋๋ก ๋์๋์ง ํ์ธํฉ๋๋ค. bboxes_reversed = delta2bbox(pos_bboxes, target_deltas) assert torch.equal(bboxes_reversed[0], gt_bboxes_list[0]) Train anchor anchor target์ ๋ง๋ค์๋ค๋ฉด ์์์ ๋์จ feature๋ฅผ network(anchor_head)๋ฅผ ํต๊ณผ์์ผ \u0026ensp; \u0026ensp; 1) regression ์์ธก ๊ฐ(reg_pred)์ผ๋ก delta๋ฅผ ์์ธก \u0026ensp; \u0026ensp; 2) class ์์ธก ๊ฐ(cls_pred)์ผ๋ก ์ค์ class๋ฅผ ์์ธก \u0026ensp; \u0026ensp; ํ๋๋ก ํ์ต์ํค๋ฉด ๋ชจ๋ธ์ด anchor๋ฅผ ๊ธฐ๋ฐ์ผ๋ก object์ class์ ์์น ์ ๋ณด๋ฅผ ์์ธกํ ์ ์๊ฒ ๋ฉ๋๋ค.\n loss๋ one/two-stage network ๋ง๋ค ๋ค๋ฅด๊ฒ ์ ์ฉ๋๋ ๊ณตํต์ ์ผ๋ก regression์ smooth-l1๋ฅผ, classification์ cross entropy๋ฅผ ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉํฉ๋๋ค. loss ๊ณ์ฐ์๋ positive, negative sample์ ๋ชจ๋ ๋ค ์ฌ์ฉํ ์๋ ์์ง๋ง, positive sample์ ๋นํด negative sample์ ๊ฐ์๊ฐ ์๋์ ์ผ๋ก ๋ง์ผ๋ฏ๋ก, ์ผ๋ถ ์ ํด์ง ์ซ์ ๋งํผ๋ง์ sample์ ์ ์ ํ์ฌ ํ์ต์ ์ฌ์ฉํฉ๋๋ค. (e.g. positive:negative=1:1.) [7] ์ด๋ ๊ฒ anchor prediction์ ๊ตฌํ๊ณ ๊ทธ ์ค์ neg_inds, pos_inds์ ํด๋นํ๋ ๊ฒฐ๊ณผ๋ง ๊ฐ์ ธ์ค๋ ๊ณผ์ ์ ๊ฑฐ์ณ ์ต์ข
์์ธก๊ฒฐ๊ณผ์ธ pos_neg_cls_pred, pos_delta_pred๋ฅผ ๊ตฌํฉ๋๋ค. loss๋ฅผ ๊ตฌํ ๋ค์ gradient descent ํ๋ ๊ณผ์ ์ ์๋ตํ๊ฒ ์ต๋๋ค. pos_neg_cls_pred, pos_delta_pred = predict_anchors(anchors.shape, target_deltas, sampled_neg_inds) # regression, class loss๋ฅผ ๊ฐ๊ฐ ๊ณ์ฐํฉ๋๋ค. reg_loss = smooth_l1_loss(pos_delta_pred, target_deltas, beta=1.0) print(\u0026quot;reg_loss:\u0026quot;, reg_loss) cls_loss = binary_cross_entropy(pos_neg_cls_pred, pos_neg_cls_label) print(\u0026quot;cls_loss:\u0026quot;, cls_loss) reg_loss: tensor(0.0795) cls_loss: tensor(2.7997) Test feature map์ ๋ฐ์ bbox์ cls_pred, delta_pred๋ฅผ ์์ธกํ ๋ delta๋ฅผ ์์ธกํ๊ธฐ ๋๋ฌธ์, delta๋ฅผ bbox๋ก ๋ณํํด์ฃผ๋ ๊ณผ์ ์ด ํ์ํฉ๋๋ค.(delta2bbox) delta๋ gt-anchor์ ์ฐจ์ด๋ผ๋ ์ ์ ์ฐธ๊ณ ํ์๋ฉด anchor bbox์ coordination ์ ๋ณด๋ฅผ ๋ฐํ์ผ๋ก ์ฌ๋ณํ์ ์์์ ์ผ๋ก ํ์ด๊ฐ๋ ๊ณผ์ ์ ์ด๋ ต์ง ์๊ฒ ์ดํดํ์ค ์ ์์ต๋๋ค. ์ต์ข
์ ์ผ๋ก object ์์ธก ๊ฒฐ๊ณผ๋ cls_pred๊ฐ ํน์ threshold ์ด์์ธ ๊ฐ๋ค์ ๋ํด์ Non-maximum suppresion(NMS)๋ฅผ ํต๊ณผ์ํจ ๊ฒฐ๊ณผ์
๋๋ค. cls_pred threshold, nms๊ฐ ๋ชจ๋ ๊ณ ๋ ค๋์๋ค๊ณ ๊ฐ์ ํ๊ณ ์์์ ์ป์ pos_delta_pred๋ฅผ test ๊ฒฐ๊ณผ๋ก ์ป์๋ค๊ณ ๊ฐ์ ํ๊ฒ ์ต๋๋ค. pos_bboxes_pred = delta2bbox(pos_bboxes, pos_delta_pred) ์๋ ๊ทธ๋ฆผ์์๋ positve predictions์ ๋ํด์ ์์ธกํ ๊ฐ๋ค์ index ์์๋๋ก ์๊ฐํํด๋ณด์์ต๋๋ค.\n# blue: gt, green: anchor, red: prediction draw_pos_assigned_bboxes(image_shape, anchor_base_size, gt_bboxes_list, pos_bboxes, pos_bboxes_pred) Conclusion ์ด๋ฒ ๊ธ์ ํตํด object detection์์ anchor์ ์ฌ์ฉ ๋ชฉ์ ๊ณผ ๊ตฌํ ๋ฐฉ๋ฒ์ ๋ํด์ ์ดํด๋ณด์์ต๋๋ค. ๋ค์ ๊ธ์์๋ ์ ๊น ์ธ๊ธํ ๋ฐ ์๋, anchor์ positive, negative label์ assignํ๊ณ ํ์ต์ ์ฌ์ฉํ sample์ ๋ฝ๋ ๊ณผ์ ์ ๋ํด ์ดํด๋ณด๊ฒ ์ต๋๋ค. Reference Faster R-CNN arXiv:1506.01497[cs.CV]\n [2] Translation-Invariant Anchors An important property of our approach is that it is translation invariant, both in terms of the anchors and the functions that compute proposals relative to the anchors. If one translates an object in an image, the proposal should translate and the same function should be able to predict the proposal in either location.\n [3] Multi-Scale Anchors as Regression References Our design of anchors presents a novel scheme for addressing multiple scales (and aspect ratios). The second way is to use sliding windows of multiple scales (and/or aspect ratios) on the feature maps.\n [5] For training RPNs, we assign a binary class label (of being an object or not) to each anchor. We assign a positive label to two kinds of anchors: (i) the anchor/anchors with the highest Intersection-overUnion (IoU) overlap with a ground-truth box, or (ii) an anchor that has an IoU overlap higher than $0.7$ with any ground-truth box. Note that a single ground-truth box may assign positive labels to multiple anchors. We assign a negative label to a non-positive anchor if its IoU ratio is lower than $0.3$ for all ground-truth boxes. Anchors that are neither positive nor negative do not contribute to the training objective.\n [6] For bounding box regression, we adopt the parameterizations of the 4 coordinates following: $$ t_x = (x - x_a) / w_a,\\ t_y = (y - y_a) / h_a, \\ t_w = \\log(w / w_a),\\ t_h = \\log(h / h_a), \\\\\nt_x^{\\ast} = (x^{\\ast} - x_a) / w_a,\\ t_y^{\\ast} = (y^{\\ast} - y_a) / h_a, \\ t_w^{\\ast} = \\log(w^{\\ast} / w_a),\\ t_h^{\\ast} = \\log(h^{\\ast} / h_a) $$\n [7] It is possible to optimize for the loss functions of all anchors, but this will bias towards negative samples as they are dominate. Instead, we randomly sample $256$ anchors in an image to compute the loss function of a mini-batch, where the sampled positive and negative anchors have a ratio of up to $1:1$.\nRetinaNet arXiv:1708.02002[cs.CV]\n [1] The design of our RetinaNet detector shares many similarities with previous dense detectors, in particular the concept of \u0026lsquo;anchors\u0026rsquo; introduced by RPN and use of features pyramids as in SSD and FPN.\n [4] We use translation-invariant anchor boxes similar to those in the RPN variant. The anchors have areas of $32^2$ to $512^2$ on pyramid levels $P_3$ to $P_7$, respectively. at each pyramid level we use anchors at three aspect ratios ${1:2, 1:1, 2:1}$. For denser scale coverage, at each level we add anchors of sizes ${2^0,2^{\\frac 1 3}, 2^{\\frac 2 3}}$ of the original set of 3 aspect ratio anchors. This improve AP in our setting. In total there are $A=9$ anchors per level and across levels they cover the scale range $32-813$ pixels with respect to the network\u0026rsquo;s input image. Each anchor is assigned a length $K$ one-hot vector of classification targets, where $K$ is the number of object classes, and a $4$-vector of box regression targets. We use the assignment rule from RPN but modified for multi-class detection and with adjusted thresholds. Specifically, anchors are assigned to ground-truth object boxes using an intersection-over-union(IoU) threshold of $0.5$; and to background if their IoU is in $[0, 0.4)$. As each anchor is assigned to at most one object box, we set the corresponding entry in its length $K$ label vector to $1$ and all other entries to $0$. If an anchor is unassigned, which may happen with overlap in $[0.4, 0.5)$, it is ignored during training. Box regression targets are computed as the offset between each anchor and its assigned object box, or omitted if there is no assignment.\n[8] The classification subnet predicts the probability of object presence at each spatial position for each of the $A$ anchors and $K$ object classes.\n[9] In parallel with the object classification subnet, we attach another small FCN to each pyramid level for the purpose of regressing the offset from each anchor box to a nearby ground-truth object, if one exists. For each of the $A$ anchors per spatial location, these $4$ outputs predict the relative offset between the anchor and the ground-truth box.\n","date":1560485700,"expirydate":-62135596800,"kind":"page","lang":"en","lastmod":1560485700,"objectID":"46b0c95da20c175a5768139e7ef4f474","permalink":"/post/2019-06-14-anchor-target/","publishdate":"2019-06-14T13:15:00+09:00","relpermalink":"/post/2019-06-14-anchor-target/","section":"post","summary":"Anchor algorithm in MMDetection","tags":[],"title":"[Tutorial] Anchor","type":"post"},{"authors":["young-kim","whi-kwon"],"categories":[],"content":" Introduction OpenCV์ Python์ผ๋ก Image processing์ ์์๋ด
์๋ค. ์ด ๊ธ์์๋ Image thresholding์ ๊ฐ๋จํ ์์๋ณด๊ณ , ์ด๋ป๊ฒ ์์ฉ๋๋์ง Blob labeling์์ ๋ฅผ ํตํด ํ์ธํ๊ฒ ์ต๋๋ค. Import Libraries import os import sys import math from platform import python_version import cv2 import matplotlib.pyplot as plt import matplotlib import numpy as np print(\u0026quot;Python version : \u0026quot;, python_version()) print(\u0026quot;OpenCV version : \u0026quot;, cv2.__version__) matplotlib.rcParams['figure.figsize'] = (4.0, 4.0) Python version : 3.6.7 OpenCV version : 3.4.5 Data load sample_image_path = '../image/' sample_image = 'lena_gray.jpg' img = cv2.imread(sample_image_path + sample_image, cv2.IMREAD_GRAYSCALE) coin_image = 'coins.jpg' mask = np.array([[0, 1, 0],[1, 1, 1], [0, 1, 0]], dtype=np.uint8) coin_img = cv2.imread(sample_image_path + coin_image, cv2.IMREAD_GRAYSCALE) ret, coin = cv2.threshold(coin_img, 240, 255, cv2.THRESH_BINARY_INV) coin = cv2.dilate(coin, mask, iterations=1) coin = cv2.erode(coin, mask, iterations=6) Data description ๋ณธ ์์ ์์ ์ฌ์ฉํ ๋ฐ์ดํฐ๋ ์๋์ ๊ฐ์ต๋๋ค. Lena : ์ง๋ ์์ ์์ ์ฌ์ฉํ Lena ์
๋๋ค. Coins : Blob labeling ์์ ์์ ์ฌ์ฉ๋ ์ด๋ฏธ์ง ์
๋๋ค. blob labeling์ด๋ผ๋ ์ฃผ์ ์ ๋ง๊ฒ ์ ์ฒ๋ฆฌ๊ฐ ๋ ์ด๋ฏธ์ง ์
๋๋ค. (blob labeling์์ ์์ธํ๊ฒ ์ค๋ช
ํฉ๋๋ค.) plt.subplot(1, 2, 1) plt.imshow(img, cmap='gray') plt.title('Lena') plt.subplot(1, 2, 2) plt.imshow(coin, cmap='gray') plt.title('Coins') plt.show() Binarization Binarization(์ด์งํ)์ด๋, grayscale์ ์ด๋ฏธ์ง๋ฅผ ๊ธฐ์ค์ ๋ฐ๋ผ 0 ๋๋ 1์ ๊ฐ๋ง์ ๊ฐ๋๋ก ๋ง๋๋ ์์
์
๋๋ค. ์ผ๋ฐ์ ์ผ๋ก ํน์ ํฝ์
๊ฐ์ ๊ธฐ์ค์ผ๋ก ๋ ์์ ๊ฐ์ 0์ผ๋ก, ๋ ํฐ ๊ฐ์ 1๋ก ๋ง๋ญ๋๋ค. ์ฌ์ฉ ๋ชฉ์ ์ ๋ฐ๋ผ ๊ฒฐ๊ณผ ๊ฐ์ ๋ฐ์ ์ํฌ ๋๋ ์๋๋ฐ, ์ถํ์ ์ฝ๋ ์์๋ก ์์๋ณด๊ฒ ์ต๋๋ค. ์ด์งํ ์์ฒด๋ ๋จ์ํ ์์
์ด๋, ์ถํ์ ๋ณด๋ค ๋ฐ์ ๋ ์๊ณ ๋ฆฌ์ฆ์ ๋ค๋ฃจ๊ธฐ ์ํ ๊ธฐ๋ณธ์ด ๋ฉ๋๋ค. def simple_img_binarization_npy(img, threshold): w, h = img.shape b_img = np.zeros([w, h]) b_img[img \u0026gt; threshold] = 1 return b_img plt.figure(figsize=(8, 8)) b_img1 = simple_img_binarization_npy(img, 200) b_img2 = simple_img_binarization_npy(img, 150) b_img3 = simple_img_binarization_npy(img, 100) plt.subplot(2, 2, 1) plt.imshow(img, cmap='gray') plt.title('Gray Lena') plt.subplot(2, 2, 2) plt.imshow(b_img1, cmap='gray') plt.title('Lena over 200') plt.subplot(2, 2, 3) plt.imshow(b_img2, cmap='gray') plt.title('Lena over 150') plt.subplot(2, 2, 4) plt.imshow(b_img3, cmap='gray') plt.title('Lena over 100') plt.suptitle('Lena with different threshold value (numpy)', size=15) plt.show() ์์์ numpy๋ฅผ ์ด์ฉํ๋ค๋ฉด, ์ด๋ฒ์ OpenCV ๋ด์ฅ ํจ์๋ฅผ ์ด์ฉํ์ฌ image threshold๋ฅผ ํด๋ณด๊ฒ ์ต๋๋ค. OpenCV ํจ์๋ฅผ ์ด์ฉํ๋ฉด numpy๋ก ์์ฑํ๋ ๊ฒ ๋ณด๋ค ํธ๋ฆฌํ๊ฒ ๋ค์ํ ๊ฒฐ๊ณผ๋ฌผ์ ๋ง๋ค์ด๋ผ ์ ์์ต๋๋ค. cv2.threshold() ํจ์์ ์ ๋ฌํ๋ ์ธ์๋ฅผ ํตํด threshold ์๊ณ ๋ฆฌ์ฆ์ ๋ค์ํ๊ฒ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค. ret, thresh1 = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY) ret, thresh2 = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY_INV) ret, thresh3 = cv2.threshold(img, 127, 255, cv2.THRESH_TRUNC) ret, thresh4 = cv2.threshold(img, 127, 255, cv2.THRESH_TOZERO) ret, thresh5 = cv2.threshold(img, 127, 255, cv2.THRESH_TOZERO_INV) plt.figure(figsize=(8, 12)) plt.subplot(3, 2, 1) plt.imshow(thresh1, cmap='gray') plt.title('threshold lena') plt.subplot(3, 2, 2) plt.imshow(thresh2, cmap='gray') plt.title('inversed threshold lena') plt.subplot(3, 2, 3) plt.imshow(thresh3, cmap='gray') plt.title('truncated threshold lena') plt.subplot(3, 2, 4) plt.imshow(thresh4, cmap='gray') plt.title('zero threshold lena') plt.subplot(3, 2, 5) plt.imshow(thresh5, cmap='gray') plt.title('inversed zero threshold lena') plt.suptitle('Lena with different threshold algorithm(OpenCV)', size=15) plt.show() Otsu\u0026nbsp;Algorithm Otsu algorithm(์ค์ธ ์๊ณ ๋ฆฌ์ฆ)์ ํน์ threshold๊ฐ์ ๊ธฐ์ค์ผ๋ก ์์์ ๋๋ก ๋๋ด์๋, ๋ ์์ญ์ ๋ช
์ ๋ถํฌ๋ฅผ ๊ฐ์ฅ ๊ท ์ผํ๊ฒ ํ ๋ ๊ฒฐ๊ณผ๊ฐ ๊ฐ์ฅ ์ข์ ๊ฒ์ด๋ค๋ ๊ฐ์ ํ์ ๋ง๋ค์ด์ง ์๊ณ ๋ฆฌ์ฆ์
๋๋ค. ์ฌ๊ธฐ์ ๊ท ์ผํจ ์ด๋, ๋ ์์ญ ๊ฐ๊ฐ์ ํฝ์
๊ฐ์ ๋ถ์ฐ์ ์๋ฏธํ๋ฉฐ, ๊ทธ ์ฐจ์ด๊ฐ ๊ฐ์ฅ ์ ๊ฒ ํ๋ threshold ๊ฐ์ด ์ค์ธ ์๊ณ ๋ฆฌ์ฆ์ด ์ฐพ๊ณ ์ ํ๋ ๊ฐ์
๋๋ค. ์์ ๊ธฐ์ ํ ๋ชฉ์ ์ ๋ฐ๋ผ, ์๊ณ ๋ฆฌ์ฆ์์๋ ํน์ Threshold $T$๋ฅผ ๊ธฐ์ค์ผ๋ก ์์์ ๋ถํ ํ์์ ๋, ์์ชฝ ์์์ ๋ถ์ฐ์ weighted sum์ด ๊ฐ์ฅ ์๊ฒ ํ๋ $T$๊ฐ์ ๋ฐ๋ณต์ ์ผ๋ก ๊ณ์ฐํด๊ฐ๋ฉฐ ์ฐพ์ต๋๋ค.\n weight๋ ๊ฐ ์์ญ์ ๋์ด๋ก ์ ํฉ๋๋ค. ์ด๋ค ์ฐ์ฐ์ ์ด๋ป๊ฒ ๋ฐ๋ณตํ๋์ง์ ๋ํ ๋ด์ฉ์ด ์๋ ์์์ ์์ธํ ๋์์์ต๋๋ค. $$ \\begin{align} \u0026amp; T = argmin_{t\\subseteq {1,\\cdots,L-1}} v_{within}(t) \\\\\n\u0026amp; v_{within}(t) = w_{0}(t)v_{0}(t) + w_{1}(t)v_{1}(t) \\\\\n\\\\\n\u0026amp; w_{0}(t) = \\Sigma_{i=0}^{t} \\hat h(i),\\hspace{2cm} \u0026amp;\u0026amp; w_{1}(t) = \\Sigma_{i=t+1}^{L-1} \\hat h(i)\\\\\n\u0026amp; \\mu_{0}(t)=\\frac{1}{w_{0}(t)}\\Sigma_{i=0}^{t}i\\hat h(i) \u0026amp;\u0026amp; \\mu_{1}(t)=\\frac{1}{w_{1}(t)}\\Sigma_{i=t+1}^{L-1}i\\hat h(i)\\\\\n\u0026amp; v_{0}(t) = \\frac{1}{w_{0}(t)}\\Sigma_{i=0}^{t}i\\hat h(i)(i-\\mu_{0}(t))^2 \u0026amp;\u0026amp; v_{1}(t) = \\frac{1}{w_{1}(t)}\\Sigma_{i=t+1}^{L-1}i\\hat h(i)(i-\\mu_{1}(t))^2\\\\\n\\end{align} $$ $w_{0}(t), w_{1}(t)$๋ threshold ๊ฐ์ผ๋ก ๊ฒฐ์ ๋ ํ์ ์์ญ๊ณผ ๋ฐฑ์ ์์ญ์ ํฌ๊ธฐ๋ฅผ ๊ฐ๊ฐ ๋ํ๋
๋๋ค.\n $v_{0}(t), v_{1}(t)$์ ๋ ์์ญ์ ๋ถ์ฐ์ ๋ปํฉ๋๋ค.\n ์ ์์์ ๊ทธ๋๋ก ์ ์ฉํ๋ฉด ์๊ฐ๋ณต์ก๋๊ฐ $\\Theta(L^{2})$์ด๋ฏ๋ก ์ค์ ๋ก ์ฌ์ฉํ๊ธฐ ๋งค์ฐ ์ด๋ ค์์ง๋๋ค.\n ๊ทธ๋ฌ๋, $\\mu$์ $v$๊ฐ ์์์ ๋ํด ํ๋ฒ๋ง ๊ณ์ฐํ๊ณ ๋๋ฉด ์์์ฒ๋ผ ์ทจ๊ธ๋๋ค๋ ์ฌ์ค์ ์ฐฉ์ํ์ฌ ๋ค์ ์๊ณ ๋ฆฌ์ฆ์ด ์์ฑ๋์์ต๋๋ค. $$ \\begin{align} \u0026amp;T = argmax_{t\\subseteq{0,1,\\cdots,L-1}}v_{between}(t)\\\\\n\u0026amp;v_{between}(t)=w_{0}(t)(1-w_{0}(t))(\\mu_{0}(t)-\\mu_{1}(t))^2\\\\\n\u0026amp;\\mu = \\Sigma_{i=0}^{L-1}i\\hat h(i)\\\\\n\\\\\n\u0026amp;\\text{์ด๊น๊ฐ}(t=0):w_{0}(0)=\\hat h(0),\\ \\mu_{0}(0)=0\\\\\n\u0026amp;\\text{์ํ์}(t\u0026gt;0):\\\\\n\u0026amp; \\hspace{1cm} w_{0}(t)=w_{0}(t-1)+\\hat h(t)\\\\\n\u0026amp; \\hspace{1cm} \\mu_{0}(t)=\\frac{w_{0}(t-1)\\mu_{0}(t-1)+t\\hat h(t)}{w_{0}(t)}\\\\\n\u0026amp; \\hspace{1cm} \\mu_{1}(t)=\\frac{\\mu-w_{0}(t)\\mu_{0}(t)}{1-w_{0}(t)}\\\\\n\\end{align} $$\n ์ ์ํ์์ $t$์ ๋ํ์ฌ ์ํํ์ฌ ๊ฐ์ฅ ํฐ$v_{between}$๋ฅผ ๊ฐ๋๋ก ํ๋ $t$๋ฅผ ์ต์ข
threshold $T$๋ก ์ฌ์ฉํฉ๋๋ค.\n ์ด์ ๊ฐ์ ์๊ณ ๋ฆฌ์ฆ์ด OpenCV์ thresholdํจ์์ ๊ตฌํ๋์ด์์ผ๋ฉฐ, cv2.THRESH_OTSU ํ๋ผ๋ฏธํฐ๋ฅผ ์๋ ์ฝ๋์ ๊ฐ์ด ์ฌ์ฉํ๋ฉด ์ ์ฉ์ด ๋ฉ๋๋ค.\n plt.figure(figsize=(8, 4)) ret, th = cv2.threshold(img, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU) plt.subplot(1, 2, 1) plt.imshow(img, cmap='gray') plt.title('Gray Lena') plt.subplot(1, 2, 2) plt.imshow(th, cmap='gray') plt.title('Otsu Lena') plt.suptitle('Lena with Otsu threshold value', size=15) plt.show() Blob\u0026nbsp;labeling Threshold๋ฅผ ํตํด ํ ์ ์๋ ์ผ์ ๊ทธ์ผ๋ง๋ก ๋ฌด๊ถ๋ฌด์งํ๋ฐ, ๊ทธ ์ค ํ๋๋ก ์ด๋ฏธ์ง ๋ถํ (image segmentation)์ ์์๋ก ๋ค ์ ์์ต๋๋ค.\n ๋ง์ผ threshold ๋ฑ์ ์๊ณ ๋ฆฌ์ฆ์ ์ด์ฉํ์ฌ ํน์ ๋ชฉ์ ์ ๋ฐ๋ผ ์์์ ๋ถํ ํ ์ ์๋ค๋ฉด(e.g. ์ฌ๋ ์ or ๋๋ก์ ์ฐจ์ ) 1๋ก ์ ํด์ง ํฝ์
๋ผ๋ฆฌ ํ๋์ object๋ผ๊ณ ์๊ฐํ ์ ์์๊ฒ์ด๊ณ , ์ฐ๋ฆฌ๋ ์ด object๋ฅผ ๋ฌถ์ด์ ์ฌ์ฉํ๊ณ ์ถ๊ฒ ๋ ๊ฒ์
๋๋ค. ์๋ก ๋ค๋ฅธ object์ธ์ง๋ฅผ ํ๋จํ๊ธฐ ์ํ์ฌ ํฝ์
์ ์ฐ๊ฒฐ์ฑ [2] ์ ๊ณ ๋ คํ ์๊ณ ๋ฆฌ์ฆ์ ์ํํ๊ณ ๊ฐ๊ธฐ ๋ค๋ฅธ label์ ํ ๋นํ๋๋ฐ, ์ด๋ฅผ Blob labeling์ด๋ผ ํฉ๋๋ค.\n Blob labeling์ ํ๋ฉด ๊ฐ๋ณ object์ ๋ํด ๊ฐ๊ฐ ์ ๊ทผํ์ฌ ์ฐ๋ฆฌ๊ฐ ํ๊ณ ์ถ์ ๋ค์ํ ์์์ฒ๋ฆฌ๋ฅผ ๊ฐ๋ณ์ ์ผ๋ก ์ ์ฉํ ์ ์๊ฒ ๋๋, ํ์ฉ๋๊ฐ ์์ฃผ ๋์ ๊ธฐ๋ฅ์
๋๋ค.\n ๋ณธ ์์ ์์๋ blob labeling์ ๋ํ ๊ฐ๋
์ ์ธ ์๊ฐ์ OpenCV์ ๊ตฌํ๋ ํจ์์ ๊ฐ๋จํ ์ฌ์ฉ๋ฒ์ ํ์ธํ๊ฒ ์ต๋๋ค. [3] ์ง๊ด์ ์ผ๋ก ์์ ํ์์ ๋๋ ์์น์ ํ๋์ blob์ ์๋ฏธํ๋ ํ๋์ ๋๊ทธ๋ผ๋ฏธ๋ฅผ ์์ฑํ๋ ๋ชจ์ต์
๋๋ค. ์๋ชป๋ ์์น์ ๊ทธ๋ ค์ง blob์ด ๋์ ๋๋๋ฐ์, ์ด์ ๊ฐ์ ๊ฒฐ๊ณผ๋ฅผ parameter๋ฅผ ํตํด handlingํ๋ ๋ด์ฉ์ ๋ํด์ ์ฐจํ ๋ค๊ฐ์ฌ ์ฃผ์ ์ธ Image Segmentation์์ ํ์ธํ๊ฒ ์ต๋๋ค. ret, coin_img = cv2.threshold(coin, 200, 255, cv2.THRESH_BINARY_INV) params = cv2.SimpleBlobDetector_Params() params.minThreshold = 10 params.maxThreshold = 255 params.filterByArea = False params.filterByCircularity = False params.filterByConvexity = False params.filterByInertia = False detector = cv2.SimpleBlobDetector_create(params) # Blob detector ์ ์ธ keypoints = detector.detect(coin_img) # Blob labeling ์ํ im_with_keypoints = \\ cv2.drawKeypoints(coin_img, keypoints, np.array([]), (0, 0, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) # ์๋ณธ ์ด๋ฏธ์ง์ ์ฐพ์ blob ๊ทธ๋ฆฌ๊ธฐ plt.figure(figsize=(15,15)) plt.imshow(im_with_keypoints) plt.title('Coin keypoint', size=15) plt.show() Conclusion Image thresholding์ ์ฌ์ฉ๋ฒ๊ณผ ๋ค์ํ ์์ฉ๋ฐฉ๋ฒ, threshold ๊ฐ์ ์ ํํด์ฃผ๋ Otsu ์๊ณ ๋ฆฌ์ฆ์ ์์๋ณด์์ต๋๋ค. ๋ง์ง๋ง์ ์์๋ณธ Blob labeling์ Image processing ๋ถ์ผ ์ ๋ฐ์ ๊ฑธ์ณ ์ฌ์ฉ๋๋ ๊ณณ์ด ์์ฃผ ๋ง์ผ๋ ์ถํ์ ๋ ๊น์ด ์์๋ณด๋ ์๊ฐ์ ๊ฐ๊ฒ ์ต๋๋ค. Reference [1] ์ค์ผ์, ์ปดํจํฐ ๋น์ , 2014, pp. 67-75 [2] \u0026lsquo;Pixel connectivity\u0026rsquo;, Wikipedia. 2019 [Online]. Available: https://en.wikipedia.org/wiki/Pixel_connectivity [3] Satya Mallick., \u0026lsquo;Blob Detection Using OpenCV ( Python, C++ )\u0026rsquo;, \u0026lsquo;Learn OpenCV. 2019 [Online]. Available: https://www.learnopencv.com/blob-detection-using-opencv-python-c/ ","date":1559876400,"expirydate":-62135596800,"kind":"page","lang":"en","lastmod":1559876400,"objectID":"085a588014c7b89adc4a8bdd5e611276","permalink":"/post/2019-06-07-image-thresholding/","publishdate":"2019-06-07T12:00:00+09:00","relpermalink":"/post/2019-06-07-image-thresholding/","section":"post","summary":"Image threshold using OpenCV","tags":[],"title":"[Tutorial] Image Thresholding","type":"post"},{"authors":["young-kim","whi-kwon"],"categories":[],"content":" Introduction OpenCV์ python์ผ๋ก Image processing์ ์์๋ด
์๋ค. ์ด ๊ธ์ ์ฒซ ๋ฒ์งธ posting์ผ๋ก, Image processing์์ Histogram์ด๋ ๋ฌด์์ธ์ง์ ๋ํ์ฌ ์์๋ณด๊ฒ ์ต๋๋ค. Import Libraries import os import sys import math from platform import python_version import cv2 import matplotlib import matplotlib.pyplot as plt import numpy as np print(\u0026quot;Python version : \u0026quot;, python_version()) print(\u0026quot;OpenCV version : \u0026quot;, cv2.__version__) matplotlib.rcParams['figure.figsize'] = (4.0, 4.0) Python version : 3.6.6 OpenCV version : 3.4.3 Data load sample_image_path = '../image/' sample_image = 'lena_gray.jpg' img = cv2.imread(sample_image_path + sample_image, cv2.IMREAD_GRAYSCALE) Data description ๋ณธ ์์ ์์ ์ฌ์ฉํ ๋ฐ์ดํฐ๋ ์๋์ ๊ฐ์ต๋๋ค. ๊ฑฐ์ ๋๋ถ๋ถ์ OpenCV ์์ ์์ ๋ณผ ์ ์๋ Lena ์
๋๋ค. ๋จ์ํ ํน์ง์ ๋ฐฐ๊ฒฝ๊ณผ ๋ณต์กํ ํน์ง์ ์ธ๋ฌผ์ด ํจ๊ป ์กด์ฌํ์ฌ ๋ค์ํ condition์ testํ๊ธฐ ์ข์ data๋ก ๋๋ฆฌ ์๋ ค์ ธ ์์ต๋๋ค. plt.imshow(img, cmap='gray') plt.title('Lena') plt.show() Histogram Histogram์ด๋, ์ด๋ฏธ์ง์์ ํน์ ํฝ์
๊ฐ์ ๋ฑ์ฅ ๋น๋๋ฅผ ์ ์ฒด ํฝ์
๊ฐฏ์ ๋๋น ๋น์จ๋ก ๋ํ๋ธ ๊ทธ๋ํ ์
๋๋ค. ์ด๋ฏธ์ง์ ์ ์ฒด์ ์ธ ๋ช
์ ๋ถํฌ๋ฅผ ํ ๋์ ํ์ธํ ์ ์์ต๋๋ค. ๋ ๊ฐ์ง ์์ ์ฝ๋๋ฅผ ํตํด Histogram์ ๋ํด ์์๋ณด๊ฒ ์ต๋๋ค. def plot_histogram_npy(img): w, h = img.shape w, h = int(w), int(h) hist_cnt = np.zeros(255) hist = np.zeros(255) for j in range(h): for i in range(w): hist_cnt[img[j, i]] += 1 hist = hist_cnt / (w * h) plt.plot(hist) plt.title('Histogram of Lena, numpy', size=15) plot_histogram_npy(img) OpenCV๋ฑ์ ์ด์ฉํ์ง ์๊ณ numpy๋ง์ ์ด์ฉํ์ฌ ๊ตฌํ Lena์ Histogram ์
๋๋ค. ์ด๋ฏธ์ง์์ ๊ฐ๋ณ ํฝ์
๊ฐ์ด ๋ช ๋ฒ์ฉ ๋ฑ์ฅํ๋์ง ํ์ธํ๊ณ ์ ์ฒด ํฝ์
์๋ก normalizeํ์ฌ Histogram์ ์ป๊ฒ ๋ฉ๋๋ค. def plot_histogram_cv(img): w, h = img.shape hist = cv2.calcHist([img], [0], None, [256], [0, 256]) hist_norm = hist / (w * h) # normalize plt.plot(hist_norm) plt.title('Histogram of Lena, OpenCV', size=15) plot_histogram_cv(img) OpenCV๋ฅผ ์ด์ฉํ๋ฉด ํจ์ ํธ์ถ์ ํตํด ๊ฐ๋จํ๊ฒ Histogram์ ๊ตฌํ ์ ์์ต๋๋ค. numpy๋ก ๊ตฌํ Histogram๊ณผ ๋น๊ตํด ๋ณด๋ฉด, ๋ ๊ฒฐ๊ณผ๋ฌผ์ด ์์ ํ ๋์ผํ ๊ฒ์ ์ ์ ์์ต๋๋ค. \u0026lsquo;cv2.calcHist()\u0026rsquo; ๋ฅผ ์ํํ๋ฉด ํฝ์
๊ฐ ๋ณ ๋ฑ์ฅ ํ์์ ๊ทธ๋ํ๋ฅผ ์ป๊ณ , ์ด๋ฅผ normalizeํ์ฌ ์ต์ข
์ ์ผ๋ก Histogram์ ์ป๊ฒ ๋ฉ๋๋ค. \u0026lsquo;cv2.calcHist()\u0026rsquo; ์ ์์ธํ ์ฌ์ฉ๋ฒ์ OpenCV ๊ณต์ tutorial page๋ฅผ ํตํด ํ์ธํ ์ ์์ต๋๋ค. [2] Histogram\u0026nbsp;Equalization Histogram Equalization(ํ์คํ ๊ทธ๋จ ํํํ)๋, pixel๊ฐ 0๋ถํฐ 255๊น์ง์ ๋์ ์น๊ฐ ์ง์ ํํ๊ฐ ๋๋๋ก ๋ง๋๋ ์ด๋ฏธ์ง ์ฒ๋ฆฌ ๊ธฐ๋ฒ ์
๋๋ค. ํ์คํ ๊ทธ๋จ ํํํ ๊ธฐ๋ฒ์ ์ด๋ฏธ์ง๊ฐ ์ ์ฒด์ ์ผ๋ก ๊ณจ๊ณ ๋ฃจ ์ด๋ก๊ฑฐ๋ ๊ณจ๊ณ ๋ฃจ ๋ฐ์์ ํน์ง์ ๋ถ๊ฐํ๊ธฐ ์ด๋ ค์ธ ๋ ์์ฃผ ์ฐ์
๋๋ค. ์ค๋ช
์ด ๋ํดํ๋ ์ฝ๋๋ฅผ ํตํด ์์ธํ ์์๋ณด๊ฒ ์ต๋๋ค. def show_stacked_histogram(img): stack_hist = np.zeros(255, dtype=np.float32) eq_hist = np.zeros(255, dtype=np.float32) w, h = img.shape hist = cv2.calcHist([img], [0], None, [256], [0, 256]) for i in range(255): stack_hist[i] = np.sum(hist[:i]) eq_hist[i] = round(stack_hist[i]) eq_hist /= (w * h) plt.plot(eq_hist) plt.title('Stacked Histogram', size=15) plt.show() show_stacked_histogram(img) 0๋ถํฐ 255๊น์ง์ Histogram์ ๋์ ์น ์
๋๋ค. ์ฝ๊ฒ ๋งํ๋ฉด Histogram์ ์ ๋ถํ ๊ฒ์ด๋ผ๊ณ ํ ์ ์์ต๋๋ค. e.g) eq_hist[150] = 0.675 \u0026rarr; ์ด๋ฏธ์ง ๋ด์์ 0๋ถํฐ 150๊น์ง์ pixel์ด ์ฐจ์งํ๋ ๋น์จ = 67.5% ๋น์ฐํ ํญ์ eq_hist[0] = 0์ด๋ฉฐ, eq_hist[255] = 1.0 ์
๋๋ค. ์ ์ฒด์ ์ผ๋ก ์ง์ ์ ๊ฐ๊น์ด ํํ์ง๋ง x์ขํ๊ธฐ์ค 0 ๊ทผ์ฒ์ 255 ๊ทผ์ฒ๋ ์ํ์ธ ๊ฒ์ ์ ์ ์์ต๋๋ค. ์ด ๋ง์ Lena image์์ pixel ๊ฐ ๊ธฐ์ค 0 ๊ทผ์ฒ์ 255 ๊ทผ์ฒ๊ฐ ์กด์ฌํ์ง ์๋๋ค๋ ๋ง ์
๋๋ค. ์ฆ, ๋ค์ ๋งํด ์ ์ฒด pixel ๊ฐ๋ค์ ๋ํ์ฌ ๋ถํฌ๊ฐ ๊ท ์ผํ์ง ์๋ค๋ ๋ง ์
๋๋ค. ํ์คํ ๊ทธ๋จ ํํํ๋ ์ด์ ๊ฐ์ด ๊ท ์ผํ์ง ์์ ํฝ์
๊ฐ์ ๋ถํฌ๋ฅผ ๊ณ ๋ฅด๊ฒ ๋ง๋๋ ์์
์
๋๋ค. \u0026mdash; ๊ทธ๋ผ ์ด์ ํ์คํ ๊ทธ๋จ ํํํ๋ฅผ ํด๋ณด๊ฒ ์ต๋๋ค. equ = cv2.equalizeHist(img) show_stacked_histogram(equ) OpenCV์ ๊ตฌํ๋์ด์๋ cv2.equalizeHist()ํจ์๋ฅผ ํตํด ํํํํ Lena์ Histogram์
๋๋ค. ์ด์ Histogram ๋์ ์น๊ฐ ์ง์ ํํ๋ผ๋ ๋ง์ด ํ์คํ๊ฒ ์ดํด ๋์ค ๊ฒ ๊ฐ์ต๋๋ค. \u0026mdash; ๋ง์ง๋ง์ผ๋ก ์ด๋ ๊ฒ ๋ณํ์ํจ ์ด๋ฏธ์ง๊ฐ ์๋ณธ ์ด๋ฏธ์ง์ ์ด๋ป๊ฒ ๋ค๋ฅธ์ง ํ์ธํด ๋ณด๊ฒ ์ต๋๋ค. plt.figure(figsize=(8,8)) plt.subplot(121) plt.imshow(img, cmap='gray') plt.title('Original Lena') plt.subplot(122) plt.imshow(equ, cmap='gray') plt.title('Equalized Lena') plt.show() ์ ์ฒด์ ์ธ ํค์ ๋ณํ๋ฅผ ํ์ธํ ์ ์๋๋ฐ, ๋ฐ์ ๋ถ๋ถ์ ๋ ๋ฐ์์ง๊ณ ์ด๋์ด ๋ถ๋ถ์ ๋ ์ด๋์์ง๋ ๋ชจ์ต์ ๋ณผ ์ ์์ต๋๋ค. ์ด๋ ์๋ณธ ์ด๋ฏธ์ง๊ฐ ์ค๊ฐ ์ ๋ ๋ฐ๊ธฐ์ ํฝ์
์ ๋ค์ ํฌํจํ๊ณ ์์๊ณ , ์๋์ ์ผ๋ก ์์ฃผ ์ด๋ก๊ฑฐ๋ ์์ฃผ ๋ฐ์ ๋ถ๋ถ์ ์ ์๊ธฐ ๋๋ฌธ์
๋๋ค. ํ์คํ ๊ทธ๋จ ํํํ๋ฅผ ํตํด ๋ชจ๋ ํฝ์
๊ฐ์ด ๋์ผํ ๋น์จ๋ก ๋ฑ์ฅํ๊ฒ๋ ์์ ํ์ฌ ์ด์ ๊ฐ์ ๋ณํ๊ฐ ์ผ์ด๋ฌ๋ค๊ณ ๋ณผ ์ ์์ต๋๋ค. ํ์คํ ๊ทธ๋จ ํํํ์ ๋ํ ์์ธํ ๋ด์ฉ์ ๋ง์ฐฌ๊ฐ์ง๋ก OpenCV ๊ณต์ tutorial page๋ฅผ ํตํด ํ์ธํ ์ ์์ต๋๋ค. [3] Conclusion ์ด๋ฏธ์ง ๋ถ์์ ๊ธฐ์ด์ธ ํ์คํ ๊ทธ๋จ์ ๋ํ์ฌ ์์๋ณด์์ต๋๋ค. ๋ํ ์ด๋ฏธ์ง ์ฒ๋ฆฌ ๊ธฐ๋ฒ์ค ํ๋์ธ ํ์คํ ๊ทธ๋จ ํํํ๋ฅผ ์์๋ณด์์ผ๋ฉฐ, ์ค์ง์ ์ผ๋ก ํ์คํ ๊ทธ๋จ์ ์ด๋ค ๋ณํ๋ฅผ ์ฃผ๋์ง ํ์ธํ ์ ์์์ต๋๋ค. Reference [1] ์ค์ผ์, ์ปดํจํฐ ๋น์ , 2014, pp. 58-63 [2] Alexander Mordvintsev \u0026amp; Abid K., \u0026lsquo;Histograms - 1 : Find, Plot, Analyze !!!\u0026lsquo;, OpenCV-python tutorials. 2013 [Online]. Available: https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_histograms/py_histogram_begins/py_histogram_begins.html#histogram-calculation-in-opencv [Accessed: 29- Mar- 2019] [3] Alexander Mordvintsev \u0026amp; Abid K., \u0026lsquo;Histograms - 2: Histogram Equalization\u0026rsquo;, OpenCV-python tutorials. 2013 [Online]. Available: https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_histograms/py_histogram_equalization/py_histogram_equalization.html#histogram-equalization [Accessed: 29- Mar- 2019] ","date":1559271600,"expirydate":-62135596800,"kind":"page","lang":"en","lastmod":1559271600,"objectID":"3a9e3a0c8005a7b8fbca52856eb129e2","permalink":"/post/2019-05-31-histogram/","publishdate":"2019-05-31T12:00:00+09:00","relpermalink":"/post/2019-05-31-histogram/","section":"post","summary":"Histogram using OpenCV","tags":[],"title":"[Tutorial] Histogram","type":"post"},{"authors":["hyungkyu-kim"],"categories":[],"content":" ์ด๋ฒ posting์์๋ competition์ ์ ์ฉํ์๋ reward shaping ๋ฐฉ๋ฒ๋ก ๊ณผ imitation learning ๋ฐฉ๋ฒ๋ก ์ ๊ธฐ๋ณธ์ผ๋ก reward, penalty๋ฅผ ๋ฐ๊ฟ๊ฐ๋ฉฐ ํ๋ ์ฌ๋ฌ ๊ฐ์ง ์คํ ๊ฒฐ๊ณผ์ ๊ดํด ์ด์ผ๊ธฐํด๋ณด๊ฒ ์ต๋๋ค.\n Reward shaping Google deep mind์์ 2015๋
๋ฐํํ Human-level control through deep reinforcement๋ฅผ ๋ณด๋ฉด ๋ค์ํ atari game environment์์ DQN์ ์ฑ๋ฅ์ ๋ณผ ์ ์์ต๋๋ค. montezuma\u0026rsquo;s revenge ๊ฐ์ ๊ฒฝ์ฐ ๊ฑฐ์ ๋ฐ๋ฅ์ ์๋ ด(randome play์ ๊ฐ์ ์์ค)ํ๋ ๊ฒฐ๊ณผ์น๋ฅผ ๋ณผ ์ ์๋๋ฐ์. ์ด ๊ฒ์์ stage๋ฅผ ํด๋ฆฌ์ดํ๊ธฐ ์ํด ์ฃผ์ธ๊ณต ์บ๋ฆญํฐ๊ฐ ๊ฑฐ์ณ์ผ ํ๋ ๋จ๊ณ๊ฐ ๋๋ฌด ๋ณต์กํ๊ณ ๋ง์ต๋๋ค. ์ด๊ฒ์ ๊ฐํํ์ต ๊ด์ ์์ ์ด์ผ๊ธฐํ๋ฉด reward๊ฐ ๋๋ฌด sparse ํ์ฌ ๊ฐํํ์ต agent๊ฐ ์ด๋ป๊ฒ ์ํฉ์ ํค์ณ๋๊ฐ ์ง์ ๋ํด ๊ฐํผ๋ฅผ ์ก์ง ๋ชปํ๋ค๊ณ ํ ์ ์์ต๋๋ค. Comparison of the DQN agent with the best reinforcement learning methods15 in the literature.\nfrom Human-level control through deep reinforcement , V Mnih et al. 2015 \n๊ทธ๋ ๋ค๋ฉด ์ด๋ป๊ฒ sparse ํ reward๋ฅผ dense ํ๊ฒ ๋ง๋ค ์ ์์๊น์? ํฌ๊ฒ 2๊ฐ์ง ํด๊ฒฐ์ฑ
์ด ์์ ์ ์์ต๋๋ค.\n manually design: ์์์
์ผ๋ก ์ง์ reward function์ ๋ง๋ฆ learn from demonstration: ์ ๋ฌธ๊ฐ์ demonstration trajectory๋ฅผ ๋ชจ๋ฐฉํ๊ฒ ํจ ์ด๋ฒ competition์์๋ ์์ ๋น์ทํ ๋ฌธ์ ๊ฐ ์์์ต๋๋ค. ๊ฐ time step ๋ณ๋ก ๋ฐ๋ผ๊ฐ์ผ ํ ์๋๋ ๋์ ์์์ง๋ง ๋๋จธ์ง ์ ๋ณด๋ ์ ํ ์๋ ์ํ์์ฃ . ํนํ ์์ธ๊ฐ์ ๊ฒฝ์ฐ๋ ์๋นํ ์ค์ํ๋ฐ, ํ์ฌ์ ์์ธ๊ฐ ๋ค์ ์์ธ์ ์ํฅ์ ๋ฏธ์น๊ธฐ ๋๋ฌธ์
๋๋ค. ์ด๋ฌํ ์ฐ์์ ์ธ ์์ธ์ ๋ชจ์์ผ๋ก ์ํ๋ ์๋๊ฐ ์ ๋๋ก ๋๋๋ ์ ๋๋๋๊ฐ ํ๊ฐ๋ฆ ๋๊ธฐ ๋๋ฌธ์, ์์ธ์ ๋ํ ์๋ฒ์ ๊ต์ฅํ ์ค์ํ ์์์์ต๋๋ค. ์ฐ์ manually design ํ ๋ฐฉ์์ผ๋ก ์ ๊ทผํ๊ธฐ ์์ํ์ต๋๋ค.\n์ฒ์์๋ ์์ฃผ ๊ฐ๋จํ reward์ penalty๋ถํฐ ์ถ๋ฐํ์์ต๋๋ค. NIPS2017 competition solution์ ๊ณต๊ฐ๋ ํ๊ธฐ๋ค์ ํ์ํ ๊ฒฐ๊ณผ ๊ฑฐ์ ๋ชจ๋ ์ฐธ๊ฐ์๊ฐ ์ ์ฉํ์๋ ๋ถ๋ถ์ด ์์์ต๋๋ค.\n ๊ณจ๋ฐ์ ์ ๋ฐฉ์ผ๋ก ๊ธฐ์ธ์ด ์ ธ์ผ ํ๋ค -\u0026gt; pelvis์ ๊ฐ๋ ๋จธ๋ฆฌ๋ ํญ์ ๊ณจ๋ฐ๋ณด๋ค ์์ ์์นํ์ฌ์ผ ํ๋ค -\u0026gt; head, pelvis์ ์์น ๋์ด์ง๋ฉด penalty ์ 3๊ฐ์ง๋ฅผ ๋ฃ๊ณ ์ํํ๋ฉฐ ๊ฒฐ๊ณผ๋ฅผ ์ง์ผ๋ดค๋๋ฐ, round 1 ๊ฐ์ ๊ฒฝ์ฐ ์๊ฐ๋ณด๋ค ๊ด์ฐฎ์ ๊ฒฐ๊ณผ๋ฌผ์ด ๋์์ต๋๋ค.\nImitation Learning Learn from demonstration์ Imitation Learning์ด๋ผ๊ณ ๋ ๋ถ๋ฆฝ๋๋ค. manually design ์ ๋ต์์ ๊ฝค ๊ด์ฐฎ์ ๊ฒฐ๊ณผ๋ฌผ์ ๋ด์์ง๋ง, ๋ ์ ๋ฐํ reward๋ฅผ ๋ง๋ค๊ธฐ ์ํด ์ผ๋ง ์ ๊ฐ Imitation Learning ๊ด๋ จ ๋ฆฌ์จ์น๋ฅผ ์์ํ์์ต๋๋ค. ๋ณธ๊ฒฉ์ ์ผ๋ก Imitation learning์ ์ ์ฉํ๊ธฐ ์์ํ์ ์๊ธฐ๋ competition์ด ์ด๋ ์ ๋ ์งํ๋ ํ์์ต๋๋ค. ์์ Opensim posting์์ ์ธ๊ธํ๋ ๊ฒ๊ณผ ๊ฐ์ด ์ฌ๋ฌ ๊ฐ์ง ์ํ์ฐฉ์ค๋ฅผ ๊ฒช์ผ๋ฉฐ ๋ฆฌ์จ์น๋ฅผ ์ํํ ํ์์ผ ์ด๋์ ๋ ๊ธฐ๋ณธ์ ์ธ Demonstration์ ๋ง๋ค ์ ์์๊ธฐ ๋๋ฌธ์ด์ฃ .\nDemonstration์ผ๋ก ์ธ kinematics ๋ฐ์ดํฐ์
์ด ์์ฑ๋์์ ์ด๊ธฐ์๋ ์ด๋ฒ competition์ ๊ธ๋ฐฉ ๋๋ผ ์ ์์ ๊ฒ๋ง ๊ฐ์ ์ฐฉ๊ฐ์ ๋น ์ ธ์์์ต๋๋ค. ์์ง opensim์ ๋ํด ์กฐ์ฌ๊ฐ ๊น์ด ์ด๋ฃจ์ด์ง๊ธฐ ์ ์ด์ด์, opensim tool๋ค์ ์ฌ์ฉํด์ ์ฃผ์ด์ง kinematics๋ก๋ถํฐ action์ ๋ง๋ค์ด ๋ผ ์ ์๋ค๊ณ ํ์
ํ๊ธฐ ๋๋ฌธ์ด์์ฃ . ๋ค์ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ด ๋ง์ด์ฃ . Typical workflow for generating a muscle-driven simulation. from Overview of the OpenSim Workflow action์ ๋ง๋ค์ด๋ด๋ ๊ฒ์ด ์ ์ค์ ํ๋๋ ํ๋ฉด, demonstration๊ณผ ๊ทธ์ ๋ฐ๋ฅธ action์ด ์๋ค๋ฉด Behavioral cloning ๋ฐฉ๋ฒ๋ก ์ ์ฌ์ฉํ ์ ์์๊ธฐ ๋๋ฌธ์
๋๋ค.\nBehavioral Cloning Brief description ์ฐ์ ๊ฐ๋จํ๊ฒ Behavioral cloning(BC) ๋ฐฉ๋ฒ๋ก ์ ๋ํด ์ดํด๋ด
์๋ค. ๊ธฐ๋ณธ ์ปจ์
์ ๋งค์ฐ ๊ฐ๋จํฉ๋๋ค. ๊ทธ ์ด๋ฆ๊ณผ ๊ฐ์ด agent๋ฅผ ์ฌ๋๊ณผ ๊ฐ์ experts์ ํ๋์ ์ ์ฌํ๊ฒ ๋ฐ๋ผ ํ๊ฒ ๋ง๋ค๊ฒ ๋ค๋ ๊ฒ์
๋๋ค. End to End Learning for Self-Driving Cars๋ฅผ ๋ณด๋ฉฐ ์์๋ด
์๋ค. ์ฐ์ training ๊ณผ์ ๋ถํฐ ์ดํด๋ณด๋ฉด ๋ค์ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ด ์ด๋ฃจ์ด์ง๊ฒ ๋ฉ๋๋ค.\n from CMU 10703 Deep Reinforcement Learning and Control - Imitation Learning 1 ๋ง์น Deep learning์์ CNN Classifier๋ฅผ ํ์ต์ํค๋ ๊ฒ๊ณผ ์ ์ฌํ๋ฐ์. Classifier ํ์ต์ ๋น๋์๋ฉด Input์ camera๋ฅผ ํตํด ๋ค์ด์ค๋ observation ๋ฐ์ดํฐ, Output์ steering command ๋ผ๊ณ ์๊ฐํ ์ ์์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ Label๋ก ์ ์๋ ์ฌ๋์ด ์
๋ ฅํ steering command์์ ์ฐจ์ด๋ฅผ loss๋ก back propagation์ ํตํด ํ์ต๋ฉ๋๋ค. ์ ๋ฆฌํ์๋ฉด ๋ค์๊ณผ ๊ฐ์ต๋๋ค.\n ์ฌ๋์ ์ด์ ๋ฐ์ดํฐ ์์ง Left, Center, Right camera๋ฅผ ํตํด observation ๋ฐ์ดํฐ๋ฅผ ์์ง steering wheel angle ๋
นํ๋ฅผ ํตํด action ๋ฐ์ดํฐ๋ฅผ ์์ง CNN ๋คํธ์ํฌ ํ์ต Data augmentation: Left camera์์ ์์ง๋ ๋ฐ์ดํฐ๋ action์ ์ฐ์ธก์ผ๋ก ๊ฐ๋ bias๋ฅผ ๋ํด์ค(๊ฐ์ด๋ฐ๋ก ๊ฐ๊ธฐ ์ํด) Right camera์์ ์์ง๋ ๋ฐ์ดํฐ๋ action์ ์ข์ธก์ผ๋ก ๊ฐ๋ bias๋ฅผ ๋ํด์ค(๊ฐ์ด๋ฐ๋ก ๊ฐ๊ธฐ ์ํด) ํ์ต(supervised learning) ํ์ต๋ agent๋ฅผ ์ด์ฉํ test๋ ๋งค์ฐ ๋จ์ํฉ๋๋ค. ๋ค๋ง ์ด ๋ฐฉ๋ฒ๋ก ์ ํ๊ณ์ ์ train ๋ฐ์ดํฐ์
์์ ๋ณผ ์ ์์๋ observation์ด test ์์ ์
๋ ฅ๋๊ฒ ๋๋ค๋ฉด, action์์ ๋ฏธ์ ์ ๋์์ด ๋ฐ์ํ๊ฒ ๋ฉ๋๋ค. deep-learning๊ณผ๋ ๋ฌ๋ฆฌ ์์๊ฐ๊ฐ ๋ณํ๋ ํ๊ฒฝ์์ ๋ฐ์ดํฐ๋ฅผ ์
๋ ฅ๋ฐ๊ธฐ ๋๋ฌธ์, ์ด๋ฐ ํ๋ฅ ์ ์๋นํ ๋์ ํธ์ ์ํ์ฃ . ์ ๋ฆฌํด์ ํํํ์๋ฉด expert์ trajectory ๋ฐ์ดํฐ์
$P_{\\text{data}}(o_t)$ ์ agent๊ฐ ํ์ฌ policy $\\pi_{\\theta}$๋ฅผ ํตํด ๊ฒฝํํ ์ ์๋ trajectory ๋ฐ์ดํฐ์
$P_{\\pi_{\\theta}}(o_t)$ ์ ๋ถํฌ๊ฐ ๋ค๋ฅด๊ธฐ ๋๋ฌธ์
๋๋ค. ์์ผ๋ก ํํํ๋ฉด ๋ค์๊ณผ ๊ฐ์ต๋๋ค.\n$$ P_{\\text{data}}(o_t) \\neq P_{\\pi_{\\theta}}(o_t) $$\n์ด๋ฐ ๋ฌธ์ ๋ค์ ํด๊ฒฐํ๊ธฐ ์ํด train ๋ฐ์ดํฐ์
์ augmentaionํ๊ธฐ ์ํ ์ฌ๋ฌ ๊ฐ์ง ๋ฐฉ๋ฒ๋ค์ด ์ฌ์ฉ๋ฉ๋๋ค. DAgger(Dataset Aggregation algorithm)๊ฐ ๋ํ์ ์ธ ๋ฐฉ๋ฒ๋ก ์ด์ฃ . The trained network is used to generate steering commands from a single front-facing center camera.\nfrom End to End Learning for Self-Driving Cars , Bojarski et al. 2016 \nOur works ์ด ๋ฐฉ๋ฒ๋ก ์ ์ ์ฉํ๋ ค๊ณ ๊ณ ๋ฏผํ๊ณ ์์ ๋๋ round 1์ ์งํ ์ค์ด์๊ธฐ ๋๋ฌธ์ ๊ธ๋ฐฉ ๋๋ผ ์ ์๋ค๋ ์์ผํ ์๊ฐ์ ๋ฐ์ฐจ๋ฅผ ๊ฐํ๋๋ฐ์. round 1 ๊ฐ์ ๊ฒฝ์ฐ๋ ์ฃผ๋ณ ์งํ์ง๋ฌผ์ด๋ ๊ธฐํ ๋ณํ ์์ด static ํ ํ๊ฒฝ์์ ๋ฑ์๋๋ก ๋ฐ์ด๊ฐ๊ธฐ๋ง ํ๋ฉด ๋๋ ๋ฌธ์ ์๊ธฐ ๋๋ฌธ์
๋๋ค. ์ ํด์ง action์ ์
๋ ฅํ๋ค๋ฉด ๋ณ๊ฒฝ ์์ด ํญ์ ์ ํด์ง observation state๊ฐ ๋์ค๊ฒ ๋๊ณ ์ด๋ฐ ๋ณํ ์๋ state๋ง ์
๋ ฅ๋๋ค๋ฉด Behavioral cloning์ผ๋ก ํ์ต๋ agent์๊ฒ๋ ์ต์ ์ ํ๊ฒฝ์ด๋ผ๋ ์๊ฐ์ด์์ต๋๋ค. round 2์ ๊ฒฝ์ฐ ์๋๊ฐ ๋ณํํ๋ค๋ ์ฌ์ค์ ์๊ณ ์์์ง๋ง, agent๋ฅผ ์ฐ์ ๊ธฐ๋ณธ์๋์ธ 1.25m/s๋ก ๊ธฐ๋ณธ์ ์ธ policy๋ฅผ ํ์ต์์ผ๋๊ณ , ๊ฐ๋ณํ๋ ์๋๋ ํ์ต๋ agent๋ฅผ ๊ฐ๊ณ ์ฌํธ๋ ์ด๋ํ๋ ๋ฐฉ์์ผ๋ก ์ ๊ทผํ๋ ค๊ณ ํ์ต๋๋ค.\n๊ทธ๋ฌ๋ ์ด๋ฐ ์ฃ๋ถ๋ฅธ ๊ธฐ์จ?์ ๊ทธ๋ฆฌ ์ค๋๊ฐ์ง ๋ชปํ์ต๋๋ค. ์์ posting์์ ๊ธฐ์ ํ๋ฏ์ด action์ ๋ง๋ค์ด๋ด๋ ๊ฒ์ด ์คํจํ๊ธฐ ๋๋ฌธ์
๋๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ action ์์ด observation state๋ง์ ์ด์ฉํ ๋ฐฉ๋ฒ๋ก ๋ค์ ํ์ํ๊ฒ ๋์์ต๋๋ค. ์ฌ๋ฌ ๋
ผ๋ฌธ๊ณผ ์ํฐํด๋ค์ ๋ฆฌ์จ์นํ๋ ์ค ์ ํฉํ ๋
ผ๋ฌธ์ ๋ฐ๊ฒฌํ๊ฒ ๋์๋๋ฐ ๊ทธ๊ฒ์ด Behavioral cloning from observation์
๋๋ค.\nBehavioral Cloning from Observation Brief description Behavioral Cloning from Observation(BCO)๋ model-based ๋ฐฉ๋ฒ๋ก ์
๋๋ค. Agent์ ํ์ต์๋ ๊ทธ๋๋ก BC๋ฅผ ์ฌ์ฉํ์ง๋ง, observation์ผ๋ก๋ถํฐ action์ ์์ธกํ๋ model์ด ์ถ๊ฐ๋ฉ๋๋ค. ์ด Neural network๋ก ๋ง๋ค์ด์ง model(Inverse Dynamics Model)์ ์ด์ฉ, ๋น์ด์๋ Demonstration์ action์ inference ํด์ BC์์ ์ฌ์ฉํ state, action์ ๋ง๋ค์ด๋ด๋ ๊ฒ์ด์ฃ .\n๋
ผ๋ฌธ์์ BCO(0)์ BCO(ฮฑ)์ ๋ฒ์ ์ ๋์๋๋ฐ, ์ฐจ์ด๋ environment์ interaction์ ์ผํ์ฑ์ผ๋ก ํ๋๋ ์ง์ํด์ ํ๋๋์ ์ฌ๋ถ์
๋๋ค. BCO(0)๋ model ํ์ต ์ agent์ ์ต์ด๋ก ์ค์ ๋ policy๋ฅผ ํตํด interaction(Pre-demonstration)์ ํ์ฌ ๋ง๋ค์ด๋ธ state transition ๋ฐ์ดํฐ์ action ๋ฐ์ดํฐ๋ง ์ด์ฉํฉ๋๋ค. BCO(ฮฑ)๋ agent์ update ๋ policy๋ฅผ ์ด์ฉํ์ฌ ์ถ๊ฐ์ ์ธ interaction(Post-demonstration)๋ฅผ ์ํํ๊ณ ์ด ๋ฐ์ดํฐ๋ค์ ์ด์ฉํฉ๋๋ค. ์ฌ๊ธฐ์๋ BCO(ฮฑ)๋ฅผ ์ฌ์ฉํ์์ต๋๋ค.\n Behavioral Cloning from Observation (BCO(ฮฑ)) framework. from Behavioral Cloning from Observation , Torabi et al. 2018 ์ ์ฒด ํ๋ก์ธ์ค๋ฅผ ๊ฐ๋จํ๊ฒ ์ดํด๋ณด๋ฉด ๋ค์๊ณผ ๊ฐ์ต๋๋ค.\n Initialize policy $\\pi_{\\phi}^{i=0}$ agent๋ ์ต์ด์ random policy๋ก ์์ ๋ค์ ๋ฐ๋ณต Run policy $\\pi_{\\phi}^i$: agent๋ ๊ฐ time step ๋ณ๋ก environment์ interaction ํ์ฌ samples($s_t^a, s_{t+1}^a$), action($a_t$) pair ์์ฑ Append to $\\mathcal{T}_{\\pi_{\\phi}}^a, \\mathcal{A}_{\\pi_{\\phi}}$: ์์ฑ๋ Samples๋ $\\mathcal{T}_{\\pi_{\\phi}}^a$ ์ action๋ค์ $\\mathcal{A}_{\\pi_{\\phi}}$์ ๋ฃ์ด์ค Update model $\\mathcal{M}_{\\theta}^i$: $\\mathcal{T}_{\\pi_{\\phi}}^a, \\mathcal{A}_{\\pi_{\\phi}}$๋ฅผ ์ฌ์ฉํ์ฌ model ์
๋ฐ์ดํธ Infer action: model์ด ์ฌ๋ฌ demonstration trajectory์ ๋ชจ์์ธ $D_{\\text{demo}}$ ์ฌ์ฉํ์ฌ action inference Update policy $\\pi_{\\phi}^i$: agent์ policy ์
๋ฐ์ดํธ. demonstration state๋ค๊ณผ inference ๋ action๋ค $\\mathcal{S}_{\\text{demo}}, \\tilde{\\mathcal{A}}_{\\text{demo}}$๋ฅผ ์ฌ์ฉํ์ฌ behavioral Cloning ์ํ\n ์กฐ๊ธ ๋ ์๋ฐํ ์ ์๋ฅผ ์ด์ผ๊ธฐํ์๋ฉด ๋ชจ๋ธ $\\mathcal{M}_{\\theta}$ ๋ฅผ ํ์ต์ํค๋ ๊ฒ์ observed transitions๋ฅผ ๊ฐ์ฅ ์ ๋ง๋ค์ด๋ผ ์ ์๋ $\\theta^*$๋ฅผ ์ฐพ๋ ๊ฒ์
๋๋ค. ์์์ผ๋ก ํํํ๋ฉด ๋ค์๊ณผ ๊ฐ์ต๋๋ค.\n$$ \\theta^* = {arg\\,max}_\\theta \\prod_{i=0}^{|\\mathcal{I}^{\\text{pre}}|}p_{\\theta}(a_i | s_i^a, s_{i+1}^a) $$\n์ด์ imitation policy $\\pi_{\\phi}$๋ฅผ ์ดํด๋ณด๋ฉด demonstration์ state๋ค๊ณผ model์ ํตํด inference๋ action์ pair {$s_i^a, \\tilde{a}_i$}๋ฅผ ๊ฐ์ฅ ์ ๋งค์นญ ์ํฌ ์ ์๋ $\\phi^*$๋ฅผ ์ฐพ์ต๋๋ค.\n$$ \\phi^* = {arg\\,max}_\\phi \\prod_{i=0}^{N}\\pi_{\\phi}(\\tilde{a}_i | s_i) $$\nOur works Behavioral cloning ๋ฐฉ๋ฒ๋ก ์ ํํ๋ ๋ ๋ค๋ฅธ ์ค์ํ ์ด์ ๋ ๊ฐํํ์ต ๋ถ์ฐ์ฒ๋ฆฌ๋ฅผ ์ํด ์ฌ์ฉํ๊ณ ์์๋ framework์ธ Ray์์ agent๊ฐ ๋ฏธ๋ฆฌ ๊ตฌํ๋ผ ์์๋ค๋ ์ ์
๋๋ค. ์๊ฐ์ ์ซ๊ธฐ๋ competition์์ ์ด๋ ๊ต์ฅํ ์ด์ ์ด์์ต๋๋ค. ๊ทธ๋ฌ๋ฏ๋ก ์๋ก์ด ํ์ต๋ฐฉ๋ฒ๋ก ์ ์ ์ ํ๋ ๊ณผ์ ์์ ํ์ต์ฑ๋ฅ๊ณผ ์ปจ์
๋ชป์ง์๊ฒ ๋น์ค์ ๋์๋ ๋ถ๋ถ์ด ์ด๋ป๊ฒ ํ๋ฉด ๊ธฐ์กด์ ์๋ ๋ชจ๋์ ์ด์ฉํ์ฌ ๊ตฌํ์๊ฐ์ ๋จ์ถํ ์ ์๋๋๋ ์ ์ด์์ต๋๋ค. BCO๋ ์ด์ ๋ฑ ์๋ง์ ๋ฐฉ๋ฒ๋ก ์ด์์ฃ . ray์์ ์ด๋ฏธ ๊ตฌํ๋์ด์๋ BC agent๋ฅผ ํ์ฉํด์ BCO agent๋ฅผ ๊ตฌํํ์์ต๋๋ค.1\n๊ทธ๋ฌ๋ ๊ฒฐ๊ณผ๋ ์๊ฐ๋ณด๋ค ์ข์ง ์์์ต๋๋ค. ๊ฒฐ๋ก ๋ถํฐ ์ด์ผ๊ธฐํ์๋ฉด behavioral cloning์ด ๊ฐ์ง ๊ทผ๋ณธ์ ์ธ ๋ฌธ์ ์ ์ด ํด๊ฒฐ๋์ง ์์์ต๋๋ค. BCO์์ ์ฌ์ฉํ๋ action์ inference ํด์ฃผ๋ model๋ ํ์ตํ์ง ๋ชปํ๋ observation ๋ฐ์ดํฐ๊ฐ ๋ค์ด์จ๋ค๋ฉด, ์ด์ํ action์ ๊ฒฐ๊ณผ๋ก ๋ง๋ ๋ค๋ ์ ์ด์์ต๋๋ค. ํ์ต์ด ๋์ง ์์ agent๊ฐ environment์์ ์ป์ด๋ผ ์ ์๋ ๋ฐ์ดํฐ๋ ๊ณ ์ ๋์ด์ง๋ ๋์๋ค๋ฟ์ด์๋๋ฐ, Demonstration์ ๋ณต์กํ ๋ฌ๋ฆฌ๊ธฐ ์ธ์ดํด์ ๋ํ action์ ๋น์ฐํ๋ ๋ง๋ค์ด ๋ผ ์ ์์์ต๋๋ค.\n๊ทธ๋์ ์ด๋ฌํ model์ ํ์ต์ํค๊ธฐ ์ํ ๋ฐ์ดํฐ ๋ถ์กฑํ์์ ๋ํ ํด๊ฒฐ์ฑ
์ผ๋ก, DAgger์ ๋น์ทํ๊ฒ train ๋ฐ์ดํฐ๋ฅผ augmentation ํ๋ ๋ฐฉ๋ฒ์ ์๊ฐํ๊ฒ ๋์์ต๋๋ค. ๊ธฐ์กด์ ์คํ์ ์ํด ์ฌ๋ฌ ๋ฐฉ๋ฒ๋ก ์ผ๋ก ํ์ต์ํค๊ณ ์์๋ ๋ค๋ฅธ agent๋ค์ ์ด์ฉํ์ฌ state transition ๋ฐ์ดํฐ์ action ๋ฐ์ดํฐ๋ฅผ ๋ง๋ค์ด ๋ด์์ต๋๋ค. BCO๋ฅผ ์ฌ์ฉํ์ฌ ํ์ตํ๊ธฐ ์ ์ ๋ฏธ๋ฆฌ ์์ฑํด๋์ ๋ฐ์ดํฐ์
์ผ๋ก model์ ํ์ต์ํจ ํ, ์ด pretrained model์ BCO agent ํ์ต์์ ์ด์ฉํ์์ต๋๋ค.\n๊ธฐ๋์๋ ๋ฌ๋ฆฌ ์ด ๊ฒฐ๊ณผ๋ ๋ฌธ์ ๊ฐ ๋ง์์ต๋๋ค. ๋ค๋ฅธ ๋ฐฉ์์ผ๋ก ํ์ต์ํจ agent์ ๋์๊ณผ demonstration ๋์์ด ๋งค์ฐ ๋ฌ๋๊ธฐ ๋๋ฌธ์ธ๋ฐ์. reward shaping์ ํตํด ๋์์ ๋ํ ์ต์ํ์ ๊ฐ์ด๋๋ง์ ์ค์ ํ์ต์ํจ agent๋ค์ ๋ฌ๋ฆฌ๋ ๋์์ด ๊ฐ๊ธฐ ์ ๋ฉ๋๋ก์์ต๋๋ค. ์ด agent๋ค์ ์์ธ๋ณด๋ค ๋ฌ์ฑํ๊ณ ์ ํ๋ ๋ชฉ์ ์ ์ข ๋ ๋ง๋ ํ์์ผ๋ก ํ์ต๋๊ธฐ ๋๋ฌธ์, ์ฌ๋์ด ๋ดค์ ๋ ๊ดด์ํด ๋ณด์ผ ์ ์์ง๋ง, reward ์์ผ๋ก ๋ดค์ ๋๋ ๋์ ์ ์๋ฅผ ์ป์ต๋๋ค. ๊ทธ๋์ ์ด ๋์๋ค์ demonstration์ ๋ฌ๋ฆฌ๊ธฐ ๋์์ฒ๋ผ ์ผ๋ฐ์ ์ธ ๋ฐ์ดํฐ๊ฐ ๊ฑฐ์ ์์์ต๋๋ค. ์๋ ๊ทธ๋ฆผ์ ๋ด
์๋ค.\n Round 1 Demonstration Round 1 ARS result ๋ ๊ทธ๋ฆผ ๋ชจ๋ round 1 ์ฉ ๋ฐ์ดํฐ๋ค์
๋๋ค. ์ข์ธก์ demonstration ๋ฐ์ดํฐ, ์ฐ์ธก์ Augmented Random Search(ARS)๋ก ํ์ต์ํจ agent์ ๊ฒฐ๊ณผ์
๋๋ค. ๊ทธ๋ฆผ์ ๋ณด๋ฉด ์ ์ ์์ง๋ง, ๋ ๋์์ด ๋งค์ฐ ๋ค๋ฆ
๋๋ค. ์ ์๋ ์์ธ์์ ๋ฌ๋ฆฌ๊ธฐ๊น์ง์ ์ถ๋ฐ ๋์์ ํนํ ์ฐจ์ด๊ฐ ์ฌํด์ ๋ฌธ์ ๊ฐ ๋ง์์ต๋๋ค. model์ด ํ์๋ก ํ๋ ์ฐธ๊ณ ํ ๋งํ transition ๋ฐ์ดํฐ๊ฐ ๋งค์ฐ ์ ์๊ธฐ ๋๋ฌธ์, ์ ๋๋ก ๋ action์ ๋ง๋ค์ด๋ด์ง ๋ชปํ๊ณ ๊ฒฐ๊ณผ์ ์ผ๋ก ์ด ์ ๋ต ๋ํ ์คํจ๋ก ๋ง๋ฌด๋ฆฌ๋์์ต๋๋ค.\nBC ๊ณ์ด ๊ฐ์ ๊ฒฝ์ฐ ๋์์ ์ํ์ค๋ฅผ ์๋ ค์ค์ ์์ฐ์ค๋ฝ๊ฒ ๋ชฉ์ ์ ๋ฌ์ฑํ๊ฒ ๋ฉ๋๋ค. ์ฐ๋ฆฌ๊ฐ goal์ด๋ ํด์ผ ํ task๋ฅผ ๋ช
ํํ๊ฒ ์ง์ ํด์ฃผ์ง ์์ฃ . agent์๊ฒ ๊ฐ time step ๋ณ๋ก ๋ฐ๋ผ ํด์ผ ํ ๋์๋ค๋ง์ ํํธ๋ก ์ ๊ณตํฉ๋๋ค. ๊ทธ๋ ๋ค ๋ณด๋ time step ๋ณ๋ก ์ง์ ๋ ๋์์ ์ํ์ค๊ฐ ํ๋ฒ ๊นจ์ง๊ฒ ๋๊ณ ์ด๋ฐ ๋ถ๋ถ์ด ์์ด๊ฒ ๋๋ฉด ๊ฒฐ๊ณผ์ ์ผ๋ก ๋ฌ์ฑํด์ผ ํ ๋ชฉ์ ์์ ํฌ๊ฒ ๋ฒ์ด๋๊ฒ ๋ฉ๋๋ค. from CMU 10703 Deep Reinforcement Learning and Control - Imitation Learning 1 \n๊ทธ๋ฌ๋ฏ๋ก ์์ธ๋ฅผ ์ฐธ๊ณ ๋ ํ๋ ๋ฌ์ฑํด์ผ ํ ๋ชฉ์ ์ ๊ณ์ํด์ ์ผ๋์ ๋๊ณ ์ํํ๋, ๋์๊ฐ ์ฐธ๊ณ ํด์ผ ํ ์์ธ์ ์ํํด์ผ ํ ๋ชฉ์ ์ ๋น์จ์ ์กฐ์ ํด๊ฐ๋ฉฐ ์คํํด๋ณผ ์ ์๋ ์๋ก์ด ๋ฐฉ๋ฒ๋ก ์ด ํ์ํ๋ค๋ ์๊ฐ์ ํ์์ต๋๋ค. ๋๋ค์ ๋ง์ ํ์ ๊ณผ์ ์ ๊ฑฐ์ณ DeepMimic์ด๋ผ๋ ๋ฐฉ๋ฒ๋ก ์ ์ฌ์ฉํ๊ฒ ๋์์ต๋๋ค.\nDeepMimic Brief description DeepMimic์ Task ๋ชฉ์ ๊ณผ reference์ motion์ ๋ชจ์ฌํ๋ ๊ฒ์ ๋์์ ๊ณ ๋ คํ๋ ๋ฐฉ๋ฒ๋ก ์
๋๋ค. ์ด ๋ฐฉ๋ฒ๋ก ์ ์ฃผ์ ์์ด๋์ด๋ ํฌ๊ฒ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. - Reward - Imitation, Task - Reference State Initialization (RSI) - Early termination (ET) - Multi-Clip Reward\nReward - Imitation, Task DeepMimic ์์ด๋์ด ์ค ๊ฐ์ฅ ํต์ฌ์ ์ธ ๋ถ๋ถ์ผ๋ก ๋ณผ ์ ์์ต๋๋ค. reward๋ฅผ ํฌ๊ฒ 2 ๋ถ๋ถ์ ํฉ์ฐ์ผ๋ก ๊ณ์ฐํฉ๋๋ค. ์ผ๋ง๋ reference motion์ ์ imitationํ๋๊ฐ์ agent๊ฐ ์ํํ๋ ค๋ task๋ฅผ ์ผ๋ง๋ ๋ฌ์ฑํ๋๊ฐ์
๋๋ค. ์ฐ์ ์์์ ๋ด
์๋ค. ํน์ time step(t)์ reward์ธ $r_t$๋ ๋ค์๊ณผ ๊ฐ์ด ๊ณ์ฐ๋ฉ๋๋ค.\n$$ r_t = w^Ir_t^I + w^Gr_t^G $$\n $r_t^I$: imitation reward $r_t^G$: task reward $w^I$: imitation weights $w^G$: task weights ์ฌ๊ธฐ์ imitation reward๋ ๋ค์ ์์๊ณผ ๊ฐ์ด ์ธ๋ถ๋ฉ๋๋ค. ์ ์ฒด์ ์ธ ์์์ ๋จผ์ ๋ณด๊ณ , ๊ฐ ๋ด์ฉ์ ๋ํด ์ด์ผ๊ธฐํด ๋ณด๊ฒ ์ต๋๋ค.\n$$ r_t^I = w^pr_t^p + w^vr_t^v + w^er_t^e + w^cr_t^c \\ w^p = 0.65, w^v = 0.1, w^e = 0.15, w^c = 0.1 $$\n $r_t^p$: joint orientations reward $r_t^v$: velocity reward $r_t^e$: end-effector reward $r_t^c$: center-of-mass reward ์ด์ ๊ฐ reward๋ค์ ์กฐ๊ธ ๋ ์์ธํ ๋ด
์๋ค. ๋จผ์ $ r_t^p $๋ ์ joint orientations์ ์ ์ฌ ์ ๋์ ๋ฐ๋ผ reward๋ฅผ ์ฃผ๊ฒ ๋ฉ๋๋ค. ์ ์ฒด imitation reward์์๋ 0.65๋ก ๊ฐ์ค์น๊ฐ ๊ฐ์ฅ ํฐ๋ฐ์. ๊ทธ๋งํผ ์ค์ํ position ๊ด๋ จ factor๋ผ๊ณ ๋ณผ ์ ์๊ฒ ์ต๋๋ค. opensim์์ ๋ด์๋๊ฒ์ฒ๋ผ, character์ joint์ angle๋ค์ด pose๋ฅผ ๊ฒฐ์ ํ๊ธฐ ๋๋ฌธ์
๋๋ค. ์ด๊ฒ์ด kinematics ๋ฐ์ดํฐ๋ก ํํ๋ผ ์๊ณ ์. ๊ฐ joint๋ค์ least squares error์ ๊ฐ์ค์น ํฉ์ผ๋ก ๊ณ์ฐ๋ฉ๋๋ค. ์์์ ๋ณด๋ฉด ๋ค์๊ณผ ๊ฐ์ต๋๋ค.2\n$$ r_t^p = exp[-2(\\sum_j|\\hat{q}_t^j - q_t^j|^2)] $$\n $\\hat{q}_t^j$: time step t์ผ๋, reference์ j๋ฒ์งธ joint์ orientations $q_t^j$: time step t์ผ๋, agent์ j๋ฒ์งธ joint์ orientations ๋ ๋ฒ์งธ๋ก velocity reward๋ ๋ค์๊ณผ ๊ฐ์ด ๊ณ์ฐํฉ๋๋ค.\n$$ r_t^v = exp[-0.1(\\sum_j|\\hat{\\dot{q}}_t^j - \\dot{q}_t^j|^2)] $$\n $\\hat{\\dot{q}}_t^j$: time step t์ผ๋, reference์ j๋ฒ์งธ joint์ ๊ฐ์๋ $\\dot{q}_t^j$: time step t์ผ๋, agent์ j๋ฒ์งธ joint์ ๊ฐ์๋ ์ธ ๋ฒ์งธ๋ end-effector reward์
๋๋ค. character์ ์๊ณผ ๋ฐ๊ฐ์ ๋ง๋จ๋ถ(end-effector)์ ์์น๊ฐ reference์ ์ ์ฌํ ์ ๋๋ฅผ ๊ณ์ฐํฉ๋๋ค.\n$$ r_t^e = exp[-40(\\sum_e|\\hat{p}_t^e - p_t^e|^2)] $$\n $\\hat{p}_t^e$: time step t์ผ๋, reference์ e๋ฒ์งธ end-effector์ ์์น $p_t^e$: time step t์ผ๋, agent์ e๋ฒ์งธ end-effector์ ์์น ๋ง์ง๋ง์ผ๋ก center-of-mass reward์
๋๋ค. character์ ์ง๋์ค์ฌ(center-of-mass)์ ์์น๊ฐ reference์์ ์ฐจ์ด ์ ๋์ ๋ฐ๋ผ์ reward๊ฐ ๋ฌ๋ผ์ง๋๋ค.\n$$ r_t^c = exp[-10(\\sum_e|\\hat{p}_t^c - p_t^c|^2)] $$\n $\\hat{p}_t^c$: time step t์ผ๋, reference์ center-of-mass ์ ์์น $p_t^c$: time step t์ผ๋, agent์ center-of-mass ์ ์์น task reward๋ agent๊ฐ ๋ฌ์ฑํ๊ณ ์ ํ๋ ๋ชฉํ๋ง๋ค ๋ฌ๋ผ์ง๋๋ฐ ๊ธฐ๋ณธ์ ์ผ๋ก ์์์ ํํ๋ imitation reward์ ๋น์ทํ๊ฒ exp[sum(least square error)] ํํ์
๋๋ค.\n์๋ฏธ๋ค์ ์ฐ์ ์ดํด๋ณด์๋๋ฐ, reward ์์์ ํํ๋ฅผ ์กฐ๊ธ ๋ ์์ธํ ๋ถ์ํด ๋ณด๊ฒ ์ต๋๋ค. ์์์ ๊ฐ์ฅ ์์ชฝ์ reference์ ์ฐจ์ด๋ฅผ ๊ณ์ฐํ๋ error sum ๋ถ๋ถ์ ๋ด
์๋ค.\n$$ r_t^p = exp[\\underbrace{-2(\\sum_j|\\hat{q}_t^j - qt^j|^2)}{\\text{error sum}}] $$\n์ผ๋จ $-x^2$์ ๊ทธ๋ํ๋ ๋ค์๊ณผ ๊ฐ์ ํํ์
๋๋ค. \n์ฌ๊ธฐ์ x๋ฅผ reference์ agent์ ํน์ factor์ ์ฐจ์ด๋ผ๊ณ ๋ณด๋ฉด, ์ฐจ์ด๊ฐ ์ปค์ง๋ฉด ์ปค์ง์๋ก ๊ฒฐ๊ด๊ฐ์ด - ๋ฐฉํฅ์ผ๋ก ์ปค์ง๊ณ , ์์์ง๋ฉด ์์์ง์๋ก 0์ ๊ฐ๊น์์ง๋๋ค. ๋ํ, factor์ ์ฐจ์ด๊ฐ ์์์ง๋ฉด ๊ฒฐ๊ณผ๋ก ๋์ค๊ฒ ๋๋ ๊ฒฐ๊ด๊ฐ์ ์ฐจ์ด๊ฐ ์์ต๋๋ค. ๊ทธ๋ํ๋ฅผ ๋ณด๋ฉด ์ง๊ด์ ์ผ๋ก ์ ์ ์์ง๋ง, ๊ฒฐ๊ด๊ฐ์ด 0์ ๊ฐ๊น์์ง์๋ก ๊ทธ๋ํ๊ฐ ๋ญ๋ํด์ง๋๋ค. factor ๊ฐ์ ์ฐจ์ด๊ฐ ํฌ๋ฉด ํด์๋ก ๋ ๊ฐํ ํ๋ํฐ๋ฅผ ์ค๋ค๊ณ ๋ณผ ์ ์์ต๋๋ค.\n์ด์ ๋ฐ๊นฅ์ชฝ ๋ถ๋ถ์ ๋ด
์๋ค.\n$$ r_t^p = exp[\\text{error sum}] $$\nexponential์ ๊ทธ๋ํ๋ ๋ค์๊ณผ ๊ฐ์ ํํ์
๋๋ค. \n์ฌ๊ธฐ์ y์ถ์ reward, x์ถ์ ์์์ ์ค๋ช
ํ error sum์ ๊ฒฐ๊ด๊ฐ์
๋๋ค. error sum ๊ฒฐ๊ด๊ฐ์ ๋ฌด์กฐ๊ฑด 0๋ณด๋ค ์์ ๊ฐ์ ๊ฐ๊ธฐ ๋๋ฌธ์ reward๋ 0~1 ์ฌ์ด์ ๊ฐ์ ๊ฐ๊ฒ ๋ฉ๋๋ค. reward์ max ๊ฐ์ด 1๋ก ์ค์ ๋๋ ์
์ด์ฃ . ๋ํ, error sum ๊ฒฐ๊ด๊ฐ(reference์์ ์ฐจ์ด)์ด ์ปค์ง๋ฉด ์ปค์ง์๋ก x๊ฐ์ exp๊ทธ๋ํ์ ๋ง์ด๋์ค ๋ฐฉํฅ์ผ๋ก ์ฐํ๊ฒ ๋๋ฏ๋ก, ๊ฒฐ๊ณผ๋ก ๋์ค๋ reward ๊ฐ์ 0์ ํ์์ด ๊ฐ๊น์์ง๊ฒ ๋ฉ๋๋ค. ์ด ์ฐจ์ด ๊ฐ์ด -3 ์ ๋๊ฐ ๋์ด๊ฐ๊ฒ ๋๋ฉด ์ป๊ฒ ๋๋ reward๋ 0.05 ์ดํ๋ก ๋งค์ฐ ๋ฎ์์ง๊ฒ ๋ฉ๋๋ค. ์ฌ๊ธฐ์ ์ ์ ์๋ ์ค์ํ ์ฌ์ค์ error sum์ ๊ฒฐ๊ด๊ฐ์ด ์ด๋ ๋ฒ์๋ด์ ๋ค์ด์ค๋ ๊ฒ์ ์ ๋ฒํ reward๋ก ์ธ์ ํ ๊ฒ์ด๋๋ฅผ error sum ์์ ์์ ๋ถ์ ๊ณ์๋ฅผ ํตํด์ ์กฐ์ ํ๋ค๋ ๊ฒ์
๋๋ค. ์ฆ, reference์์ ์ฐจ์ด์ ํ์ฉ์น๋ฅผ ์กฐ์ ํ๋ค๋ ๋ง์
๋๋ค. factor๋ค์ ๋ค์ํ ๋ฌผ๋ฆฌ๋์ ๋ค๋ฃน๋๋ค. ์ด๋ค ๊ฒ์ angle์ด ๋ ์๋ ์๊ณ , position ๊ฐ๋ค์ด ๋ ์๋ ์์ต๋๋ค. ์ด๋ฐ ๊ฐ๋ค์ด ํํ๋๋ ๊ณ ์ ํ ํ์์ ๋ฐ๋ผ ๋ถํฌ๋ ๋ฒ์๊ฐ ๋ฌ๋ผ์ง ์ ์์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ agent๋ฅผ ํ์ต์ํค๋ ๊ฐ๋ฐ์๋ค์ ํ์์ ๋ฐ๋ผ ์ ํจํ ๋ฒ์๋ฅผ ์กฐ์ ํ๊ณ ์ถ์ ์ ์์ต๋๋ค. ์ด๋ฐ ๋ถ๋ถ๋ค์ -2, -0.1, -40, -10๊ณผ ๊ฐ์ ๊ณ์๋ค์ ํตํด ํต์ ํฉ๋๋ค. \nReference State Initialization (RSI) ์ผ๋ฐ์ ์ธ ๊ฐํํ์ต์์๋ ๊ฐ episode ์์ ์์ initial state๊ฐ ๊ณ ์ ๋์ด ์์ต๋๋ค. ๊ฒ์์ ์์ํ ๋ ์์ ํฌ์ธํธ์ ์บ๋ฆญํฐ๊ฐ ํญ์ ๋๊ฐ์ ๊ณณ์ ์์นํ๋ ๊ฒ์ฒ๋ผ์. ๋ณต์กํ ๋์์ ๋ฐฐ์ฐ๊ธฐ์๋ ์ด๋ฐ ์ ๋ต์ด ์ ํจํ์ง ์์ ์ ์์ต๋๋ค. ์๋ํ๋ฉด, agent์ policy๋ ํญ์ ์ด๊ธฐ์ reference์ motion๋ถํฐ ์ฐจ๋ก๋๋ก ํ์ต์ด ๋๋๋ฐ, ์ด๊ธฐ ๋์์ ํ์คํ๊ฒ ๋ง์คํฐํ๊ธฐ ์ ๊น์ง๋ ํ์ ๋์์ ํ์ตํ๊ธฐ ์ด๋ ต์ต๋๋ค. ๋ํ, ๊ฐํํ์ต์ ์ด์ ์ ๊ฒฝํํ trajectory์์ ๋์ reward๋ฅผ ํ ๋ฒ์ด๋ผ๋ ์ป์ด์ผ๋ง ์ ๋๋ก ๋ ํ์ต์ด ๊ฐ๋ฅํ๋ฐ, backflip๊ฐ์ด ๋ณต์กํ๊ณ ์ด๋ ค์ด ๋์์ random exploration์ ํตํด ์ฑ๊ณต์ ์ธ ๊ฒฐ๊ณผ๋ฅผ ์ป๊ธฐ๊ฐ ๋งค์ฐ ์ด๋ ต์ต๋๋ค. from Towards a Virtual Stuntman \n๊ทธ๋ฌ๋ฏ๋ก RSI์์๋ ์ด initial state๋ฅผ ๋ณ๊ฒฝํฉ๋๋ค. reference motion์ state ์ค ํ ํฌ์ธํธ์์ ๋ฌด์์๋ก ์์ํฉ๋๋ค. backflip์ผ๋ก ์๋ฅผ ๋ค์๋ฉด ์ด๋ค ๋๋ ๋
์์ ์์ํ ์๋ ์์ง๋ง, ์ด๋ค ๋๋ ๊ณต์ค์์ ๋ชธ์ด ๋์๊ฐ๋ ์ค์ด ๋ ์๋ ์๊ฒ ์ง์. from Towards a Virtual Stuntman \nEarly termination (ET) agent๊ฐ ํน์ ์ํฉ์ ๋ผ์ด์(stuck) ๋๋ ํ์ต์ ์งํํ ์ ์๋ ์ํ์ผ ๋, ํ์ต์ ์ผ์ฐ ์ข
๋ฃ์ํต๋๋ค. ๋ฌ๋ฆฌ๊ธฐ๋ฅผ ๋ฐฐ์ฐ๋ ํ๊ฒฝ์ธ๋ฐ ๋์ด์ก๋ค๋๊ฐ ํ๋ ์ํฉ๊ฐ์ด์. ์ด๋ฒ competition์์ ๊ณจ๋ฐ์ ์์น๊ฐ ํน์ ๋์ด ์ดํ๋ก ๋จ์ด์ง๋ฉด ET๋ฅผ ์ํ์ํค๋ ์ฝ๋๊ฐ ๊ธฐ๋ณธ์ ์ผ๋ก ๋ค์ด๊ฐ ์์ต๋๋ค.\n Comparison of policies trained without RSI or ET. RSI and ET can be crucial for learning more dynamics motions. Left: RSI+ET. Middle: No RSI. Right: No ET.\nfrom Towards a Virtual Stuntman Multi-Clip Reward ์ฌ๋ฌ reference motion์ ํ์ฉํ์ฌ agent๋ฅผ ํ์ต์ํต๋๋ค. ๋งค time step ๋ณ๋ก ์ฌ๋ฌ reference ์ค ์ ํฉํ ๊ฒ์ ๊ณจ๋ผ๋ด๋ manually crafted kinematic planner์ ๊ฐ์ ๋ฐฉ์๋ณด๋ค ๊ฐ๋จํ๋ฉด์ ์ข์ ์ฑ๋ฅ์ ๋ณด์๋ค๊ณ ํฉ๋๋ค. ์์์ ๋ณด๋ฉด ๋ช
ํํ๋ฐ, ํด๋น time step์์ ๊ฐ์ฅ reward๊ฐ ๋์(max) reference์ reward๋ฅผ ์ฌ์ฉํฉ๋๋ค.\n$$ r_t^I = \\max_{j=1, \u0026hellip; ,k}r_t^j $$\n $r_t^j$: j๋ฒ์งธ motion clip์ imitation reward Our works DeepMimic์ ์ ์ฉํ๊ธฐ ์ํด opensim-rl์ reward function์ ์๋ก ์ ์ํ์์ต๋๋ค. DeepMimic์์ ์ฌ์ฉํ์๋ ๋ชจ๋ ์ฃผ์ ์์ด๋์ด๋ฅผ ์ ์ฉํ๋ ค๊ณ ํ์์ง๋ง, RSI ๊ฐ์ ๊ฒฝ์ฐ๋ ์๋ฎฌ๋ ์ด์
ํ๊ฒฝ ์์ฒด๋ฅผ ๋ฏ์ด๊ณ ์ณ์ผ ํ๋ ๋ฒ๊ฑฐ๋ก์์ด ์์๊ณ , opensim ์๋ฎฌ๋ ์ดํฐ๋ฅผ ๊ทธ ์ ๋๋ก ๊น๊ฒ ์ฐ๊ตฌํ ์๊ฐ์ด ์์๊ธฐ ๋๋ฌธ์ Reward, ET, Multi-Clip Reward ์ ๋๋ง ์ ์ฉํ ์ ์์์ต๋๋ค. ์ด ์์
์ ์ํํ๋ฉฐ ๊ณ ๋ฏผํ๋ ํฌ์ธํธ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.\n demonstration ๋ฐ์ดํฐ์ ์ ๋ขฐ์ฑ ๋ฌธ์ reference์ ์ด๋ค factor๋ค์ ์์น๋ฅผ ๋น๊ตํ ๊ฒ์ธ๊ฐ? reward๋ค์ ๊ฐ๊ฐ์ weight๋ ์ด๋ค ์์ผ๋ก ์ค์ ํ ๊ฒ์ธ๊ฐ? penalty ์ค์ ์ฌ๋ถ task reward๋ ์ด๋ป๊ฒ ์ค์ ํ ๊ฒ์ธ๊ฐ? ์ฐ์ demonstration์ ์ ๋ขฐ์ฑ ๋ฌธ์ ๋ถํฐ ์ด์ผ๊ธฐํด ๋ณด๊ฒ ์ต๋๋ค. ๊ธฐ๋ฐ์ด ๋์๋ kinematics๊ฐ์ ๊ฒฝ์ฐ ์คํ๋ฐ์ดํฐ๋ฅผ ๊ธฐ๋ณธ์ผ๋ก ์์
์ด ๋์์ง๋ง, ์์์
์ผ๋ก ๋ฐ์ดํฐ ์์ ์ ํตํด ๋ง๋ค์ด๋๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ด ์ค์ ์๋ฎฌ๋ ์ด์
ํ๊ฒฝ์์ ๋์ํ ์ง ๋ฏธ์ง์์์ต๋๋ค. \n๋ฌผ๋ก ์์ ํ kinematics๊ฐ ๋์ํ๋ ๊ฒ์ opensim gui tool์์ ํ์ธํ์์ง๋ง, ์ด๊ฒ์ ๊ทผ์ก์ action์ ํตํ ๋์์ด ์๋ ๋จ์ํ pose๋ค์ ์ฐ์์ธ ๊ป๋ฐ๊ธฐ๋ง ๋์์ํจ ๊ฒ์ด๊ธฐ ๋๋ฌธ์
๋๋ค. ์์ BCO์์๋ action ๋ฐ์ดํฐ๋ฅผ ๋ง๋ค ๋ ์ด๋ฏธ ์๋ฎฌ๋ ์ด์
์ ์ด์ฉํ๊ธฐ ๋๋ฌธ์ ๊ทธ๋ฆฌ ํฐ ๋ฌธ์ ๋ก ์๊ฐํ์ง ์์์ต๋๋ค. ๊ทธ๋ฌ๋ ์ฌ๊ธฐ์๋ ์ค๋ก์ง kinematics์ ์ฐจ์ด๋ง์ ๊ฐ์ง๊ณ ํ์ต์ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ ๋ฌธ์ ๊ฐ ๋ ์ ์์์ต๋๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ demonstration์ validation ํ๊ธฐ ์ํด ์ฌ๋ฌ๋ชจ๋ก ์ฐ๊ตฌ๋ฅผ ํ์์ง๋ง, ๋พฐ์กฑํ ์๋ฅผ ์ฐพ์ ์๊ฐ ์์์ต๋๋ค. ๊ฒฐ๊ตญ, imitation reward์ task reward์ weight๋ฅผ ๋ฐ๊ฟ๊ฐ๋ฉฐ ์คํ์ ์ผ๋ก ์ฑ๊ณต์ ์ธ ์์น๋ฅผ ์ฐพ์๋ด๊ธฐ๋ก ํ์์ต๋๋ค. ์ฐ์ ๋ง๋ค์ด์ ธ ์๋ demonstration์ ๋ํด ์ ๋ขฐ์ฑ์ด ๋จ์ด์ก์ผ๋ฏ๋ก task reward weight๋ฅผ ์กฐ๊ธ ๋ ํฌ๊ฒ ์ก๋ ์ชฝ์ผ๋ก ์คํ์ ์์ํ์์ต๋๋ค.\n๊ทธ๋ฆฌ๊ณ imitation reward๋ฅผ ์ค์ ํ๊ธฐ ์ํด ์ด๋ค factor๋ค์ ๋น๊ตํ ๊ฒ์ธ์ง๋ฅผ ์์๋ด์ผ ํ์ต๋๋ค. ์ฐ์ ํ์ฌ reference๋ก ์ฌ์ฉํ demonstration์ ๋ฐ์ดํฐ ์ค ์ฌ์ฉ ๊ฐ๋ฅํ ํ๋๋ค์ ํ์
์ด ์ค์ํ๋๋ฐ์. ์ด๊ฒ์ kinematics์ ์ ํจ์ฑ๊ณผ๋ ๋ณ๊ฐ์ ๋ฌธ์ ์์ต๋๋ค. ์ด์ posting์์ ์ธ๊ธํ๋ฏ kinematics ๋ฐ์ดํฐ๋ฅผ ํตํด demonstration์ state๋ค์ ๋ง๋ค์ด์ฃผ๋ opensim tool์ ์ด์ฉํ script์ ๊ฒฐ๊ณผ๊ฐ ์ผ๋ง๋ ์ ํจํ ๋ฐ์ดํฐ์ธ์ง ์ ์ ์์๊ธฐ ๋๋ฌธ์
๋๋ค. ์ด ํ๋ก๊ทธ๋จ์ ์ญํ ์ ์กฐ๊ธ ๋ ์์ธํ ์ค๋ช
ํ๋ฉด, kinematics ๋ฐ์ดํฐ์ ์๋ ๊ฐ time step ๋ณ position, joint angle ๊ฐ๋ค์ ๋ฐํ์ผ๋ก velocity, acceleration ๊ฐ์ ๊ฐ๋ค์ ๊ณ์ฐํด์ state๋ค์ ์ถ๊ฐํฉ๋๋ค. ๊ทธ๋์ ์๋ก ์ถ๊ฐ๋ ๋ฐ์ดํฐ๋ค์ ์ ํจ์ฑ์ ๊ฒ์ฆํ๊ณ ์, ๋ค์ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ ๊ณผ์ ์ ์ฌ์ฉํ์์ต๋๋ค. \nobservation์ ๋ฐ์ดํฐ์๋ ๋ชจ๋ position, velocity, acceleration ๊ฐ๋ค์ด ํฌํจ๋์ด ์์ต๋๋ค. ์ฌ๊ธฐ์ ์ป์ ๋ฐ์ดํฐ๋ฅผ ์ ๋ต์ผ๋ก ํ์ ๋, script๋ฅผ ํตํด ์๋ก ๋ง๋ค์ด๋ธ ๋ฐ์ดํฐ์ ์ผ๋ง๋ ์ ์ฌํ์ง๋ฅผ ๊ฒ์ฌํ์์ต๋๋ค. ๊ทธ ๊ฒฐ๊ณผ acceleration์ ์ ์ธํ ๊ฐ๋ค์ 80% ์ด์์ ์ ์ฌ๋๋ฅผ ๋ณด์๊ณ , ์ด ์ ๋๋ฉด ๊ฐ์ค์น๋ฅผ ํตํด ๊ฒฝ์ค์ ์กฐ์ ํด๊ฐ๋ฉฐ reference๋ก ์ด์ฉํ ๋งํ ๊ฐ์ด๋ผ๊ณ ํ๋จํ์ต๋๋ค. ๊ทธ๋ ๊ฒ ํด์ ์ต์ข
์ ์ผ๋ก reference๋ก ์ฌ์ฉํ๊ธฐ๋ก ํ factor๋ค์ joint angle(pose), joint velocities, center-of-mass์ด 3๊ฐ์ง์
๋๋ค.\nreward์ weight ๋ฐ penalty๋ฅผ ๊ฒฐ์ ํ๋ ์ผ์ ๊ต์ฅํ ์๊ฐ์ด ๋ง์ด ์์๋๋ ์ผ์ด์์ต๋๋ค. ๋์ด ์ธ์ ์ผ์ง ๋ชจ๋ฅผ hyper parameter tuning ์์
์ด์๋๋ฐ์. imitation reward์ task reward์ ๋น์จ๋ถํฐ, imitation factor๋ค์ ๊ณ์๋ค, penalty ์ฌ์ฉ ์ฌ๋ถ ๋ฐ ์ค์ ๊น์ง. ์์ ํ๊ณ ์คํํด์ผ ํ ๊ฒ๋ค์ด ์์ฒญ๋๊ฒ ๋ง์์ต๋๋ค. ๋ํ, ์คํ์ ์งํํ๋ฉฐ ์๋ก์ด ํ๋ผ๋ฏธํฐ๋ค์ ์ถ๊ฐํด์ผ๋ง ํ๋๋ฐ, kinematics ๋ฐ์ดํฐ์ ๋ถํ์ค์ฑ ๋๋ฌธ์ธ ๋ฏ rotation ๊ฐ๊ณผ position ๊ฐ๋ค์ ๋จ์ ๋น๊ต๋ง์ผ๋ก๋ ์ ๋๋ก ๋ ํ์ต์ด ์ด๋ฃจ์ด์ง์ง ์์์ต๋๋ค. ํด๊ฒฐ์ฑ
์ ์ฐพ๋ ์ค opensim IK tool์์ ๊ณ์ฐํ๋ ๊ฒ์ ์ฐธ๊ณ ํ์ฌ, joint๋ค์ weight๋ฅผ ๊ฐ๊ฐ ๋ฐ๋ก ๋ถ์ฌํ์ฌ ์ค์ํ ๋ถ๋ถ์ ์ค๋ฅ์ ๋ฏผ๊ฐํ๊ฒ ๋ฐ์ํ๋๋ก ํ๋ ํ์ต์ด ์ด๋ฃจ์ด์ก์ต๋๋ค. ๊ทธ๋์ ์ต์ข
์ ์ผ๋ก ์๋ ์์ ์ ๊ฐ์ด parameter configuration์ ๋ง๋ค๊ณ hyper parameter tuning์ ์งํํ์์ต๋๋ค.\n************************************ reward configuration step limit: 150 task reward: True reward proportion: - task: 3 - imi: 7 imitation reward weight: - rot weight: -4 - vel weight: -0.1 - center pos weight: -10 - task weight: -2.5 joint weight: - pelvis_tilt : 15 - pelvis_list : 5 - pelvis_rotation : 1 - hip_flexion_r : 3 - hip_adduction_r : 3 - knee_angle_r : 0.5 - hip_flexion_l : 3 - hip_adduction_l : 3 - knee_angle_l : 0.5 - ankle_angle_l : 2 demo files: - /home/medipixel/demos/GIL02_free2_181019.xlsx - /home/medipixel/demos/GIL02_free2_181026_3.xlsx - /home/medipixel/demos/GIL02_free2_181026_2.xlsx ************************************ ํ์ต ์์ ์๋ฎฌ๋ ์ด์
์ ์ฒ์๋ถํฐ ๋๊น์ง ๋๋ ค์ ๊ฒฐ๊ณผ๋ฅผ ํ์ธํ์ง ์๊ณ time step์ 150~200 step ์ ๋์์ ๋๊ณ ์ถ์ด๋ฅผ ์ง์ผ๋ณด์๋๋ฐ์. ํ๋์ ์ํ ์๊ฐ์ ์๋ผ๊ธฐ ์ํด์์๊ธฐ๋ ํ์ง๋ง ์ถ๋ฐ ์์ธ๊ฐ ์ ์ผ ์ค์ํ๋ค๊ณ ํ๋จํ๊ธฐ ๋๋ฌธ์
๋๋ค. ์ฐ์ ์ด ๊ณผ์ ์ด ๊ฐ์์ ์์ํ๋ ๋ถ๋ถ์ด์๊ธฐ ๋๋ฌธ์ ๋น ๋ฅด๊ฒ ๋ชฉํ ์๋์ ์ง์
ํ๊ธฐ ์ํด ๊ฐ์ฅ ์ค์ํ ๋ถ๋ถ์ด์๊ณ , gait cycle์ ์์ ์ ์ผ๋ก ์ง์
ํ๊ธฐ๋ง ํ๋ค๋ฉด ๊ฐ์ ์์ง์์ด ๋ฐ๋ณต๋๊ธฐ ๋๋ฌธ์ ํฐ ์ด๋ ค์ ์์ด ํ์ต์ด ๊ฐ๋ฅํ๋ค๊ณ ์๊ฐํ๊ธฐ ๋๋ฌธ์
๋๋ค. ์ฌ๋ฌ ์คํ์ ํ๋ฉฐ ๋ค์๊ณผ ๊ฐ์ ๊ฒฐ๊ณผ๋ค์ ์ป์ ์ ์์์ต๋๋ค.\n ๋ง์ง๋ง์ผ๋ก ๋ฌธ์ ์ task reward ๋ถ๋ถ์
๋๋ค. task reward ๊ฐ์ ๊ฒฝ์ฐ๋ deepmimic์์ ์ฌ์ฉํ๋ exp[error sum]ํํ๋ฅผ ์ฌ์ฉํ์๋๋ฐ, ์ถ๋ฐ ๋์์ ํ์ต์ํฌ ๋๊น์ง๋ ๋ฌธ์ ์์ด ๋์ํ๋ ๊ฒ์ฒ๋ผ ๋ณด์์ต๋๋ค. ๊ทธ๋ฌ๋ ์ ์ถ 3์ผ ์ ๊ฑฐ์ ๋ชจ๋ parameter๋ฅผ ํ์ ํ๊ณ ๋ณธ๊ฒฉ์ ์ผ๋ก ์ต์ข
ํธ๋ ์ด๋์ ์ํค๋ ค๊ณ ํ ๋ ์ ์ ์ด task reward๋ก๋ ์ ์ง์ด ์ ๋๋ค๋ ๊ฒ์ด ๋ฐํ์ก์ต๋๋ค.\n๋ฌผ๋ก ๋ค๋ฅธ ์ ๋ต์ผ๋ก ARS agent๋ฅผ ํธ๋ ์ด๋ ์ค์ด์ด์ ์ต์
์ ์ํฉ์๋ ์ ์ถ์ ํ ์ ์์์ง๋ง, ์ฌ๋ฌ ์คํ์ ํตํด ์ถ๋ฐ์์ธ๋ฅผ ๋ค์ก์๋์ agent๋ฅผ ํฌ๊ธฐํ๊ธฐ ๋๋ฌด ์๊น์ ์ต๋๋ค. ์๊ฐ์ ๋งค์ฐ ์ด๋ฐํ์ง๋ง, round 1 agent๋ ๋์์ ๊ทธ๋๋ง ์ํ๋ ๊ฒ์ ์ฐฉ์, ์ด์ฌ์ผ๋ก ๋์๊ฐ์ round 1์ ์ค์ ๋ถํฐ ์ดํด๋ณด๊ธฐ๋ก ํ์์ต๋๋ค.\nConclusion round 2๋ฅผ ์งํํ๋ฉฐ task reward ๋ถ๋ถ์ deepmimic์ฒ๋ผ exp ํํ๋ก ๋ฐ๊พผ ๊ฒฐ์ ์ ์ธ ์ด์ ๊ฐ ์์๋๋ฐ, task reward๋ฅผ ๊ธฐ๋ณธ reward ํํ๋ก ์ค์ ํด๋์ผ๋ฉด ์ ์งํ์ง ์๊ณ ๊ทธ ์๋ฆฌ์ ๊ฐ๋งํ ์ ์๊ธฐ ๋๋ฌธ์ด์์ต๋๋ค. ๊ทธ๋ฌ๋ round 1 ๊ฐ์ ๊ฒฝ์ฐ๋ task reward๋ฅผ ๋ณํํ์ง ์๊ณ ๊ธฐ๋ณธํ์ผ๋ก ์ฐ๋๋ผ๋ ์๋ฌด ๋ฌธ์ ์์ด ํ์ต์ด ์๋์์ฃ . ์ฌ์ง์ด imitation learning์ ์ฐ์ง ์๋๋ผ๋์. ๊ทธ๋ฐ ์ด์ ์์ round 1์ reward๋ฅผ ์ดํด๋ณด๋ฉฐ ์ฐจ์ด์ ์ ํ์
ํ๋ ค ํ์ต๋๋ค. ์ด๋ฐ์ ๋ฐ ๊ฒํ ๋ฅผ ํ๋ ์ค ์ค์ํ ์ ์ ๋ฐ๊ฒฌํ์ต๋๋ค. ์ค๋ช
์ ์์ round 1๊ณผ round 2์ ๋น๊ต๋ฅผ ๋จผ์ ํด๋ณด๊ฒ ์ต๋๋ค. ์ฐ์ round 1 reward์ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.\nreward = 9.0 - (state_desc[\u0026quot;body_vel\u0026quot;][\u0026quot;pelvis\u0026quot;][0] - 3.0)**2 ์ด๋ฅผ ๊ทธ๋ํ๋ก ๊ทธ๋ ค๋ณด๋ฉด ๋ค์๊ณผ ๊ฐ์ต๋๋ค. x์ถ์ ์๋ y์ถ์ reward์
๋๋ค. ๊ทธ๋ฆฌ๊ณ round 2์ ๊ธฐ๋ณธ reward ์ฝ๋๋ฅผ ๋ณด๋ฉด ๋ค์๊ณผ ๊ฐ์ต๋๋ค.3\n# target_vel = 1.25 penalty += (state_desc[\u0026quot;body_vel\u0026quot;][\u0026quot;pelvis\u0026quot;][0] - state_desc[\u0026quot;target_vel\u0026quot;][0])**2[0])**2 reward = 10.0 reward - penalty ๊ทธ๋ํ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. \n์ด ๋์ ์ฐจ์ด์ ์ ๊ทธ๋ํ๋ฅผ ๋ณด๋ฉด ๋ช
ํํด์ง๋๋ฐ, round 1์ด ์ ์ง์ ์ฑ๊ณตํ๋ ์ด์ ๋ ์๋๊ฐ 0์ผ ๋ reward๋ฅผ ์ป์ง ๋ชปํ๊ธฐ ๋๋ฌธ์
๋๋ค. ๊ทธ์ ๋ฐํด round 2๋ ๋น์ฐํ๋ ์ ์งํ์ง ์์์ต๋๋ค. ์ ์์ผ๋ฉด(์๋๊ฐ 0์ผ ๋) ์์ ํ๊ฒ 8 ์ด์์ reward ์ทจ๋์ด ๊ฐ๋ฅํ๊ธฐ ๋๋ฌธ์
๋๋ค. ์ ์งํ๋ ๊ฒ์ ๊ต์ฅํ risk๋ฅผ ์ง์ด์ง๋ ์ผ์
๋๋ค. ํ์ฌ ์์ธ๋ฅผ ๋ง์ณ๊ฐ๋ฉฐ ๋ถ์์ ํ ์์ธ์ ์ง์
ํ๋ ๊ฒ์ด๊ธฐ ๋๋ฌธ์ด์ฃ . ๋น๊ต์ ์์ฝ๊ฒ ์ป์ ์ ์๋ reward๋ฅผ ํฌ๊ธฐํ๋ ๊ฒ ์
๋๋ค. ๊ทธ๋์ ์๋์ ์ผ๋ก ์ฌ์ด reward์ overfitting ๋๋ ๊ฒ์ด์์ต๋๋ค. ์์ฃผ ์ฌ๋ฏธ์๊ฒ๋ ์ฝ์ญ๋น ๋ฅธ ์ฌ๋์ฒ๋ผ ๊ผผ์๋ถํฐ ๋ฐฐ์ด ๊ฒ์ด์ฃ .\n์ฌ๊ธฐ์ ๊ฐ์ ๊ฐ๋ฅํ ๋ถ๋ถ์ ๋ฐ๊ฒฌํ์ต๋๋ค. round 2์ ๋ฆฌ์๋๋ฅผ round 1์ฒ๋ผ ์๋๊ฐ 0์ผ ๋ ๋ฆฌ์๋ ์ทจ๋์ ๋ชปํ๋๋ก ๋ฐ๊พธ๋ ๊ฒ์
๋๋ค. ๊ทธ๋ฆฌ๊ณ ๋ ๋์๊ฐ ์คํ๋ ค ๊ฐ๋งํ ์ ์์ผ๋ฉด penalty๋ฅผ ์ฃผ๋ ๋ฐฉ๋ฒ์ ์ ์ฉํ์ต๋๋ค. ์๋๊ฐ 0์ผ ๋ ์ฝ๊ฐ์ ๋ฒ์ ์ ๋ฐ๋๋ก ํ์ต๋๋ค. ๋ฒ์ ์ด ๋๋ฌด ์ธ๋ฉด agent๊ฐ ์ฃผ๋
?๋ค์ด์ ์คํ๋ ค ์๋ฌด ํ๋๋ ์ทจํ์ง ๋ชปํ์ต๋๋ค. ์ด๋ ๊ฒ task reward๋ฅผ ๊ฐํธํ๋ ๋๋์ด ์ ์ง์ ์์ํ์ต๋๋ค. ๊ทธ๋ฌ๋ ๊ฐ์ฅ ์ค์ํ ์์์ธ ์๊ฐ๋ถ์กฑ์ผ๋ก ํ์ต์ ์๋ฃํ ์ ์์์ต๋๋คโฆ. ๋ง์ง๋ง ํ์ต ๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. \n๊ฒฐ๊ตญ, ์ต์ข
๊ฒฐ๊ณผ๋ฌผ์ imitation learning์ด ์๋ ARS์์ ํ์ตํ์๋ agent๊ฐ ๋์์ต๋๋ค.\n์ด๋ฒ competition์ imitation learning์ ์ฌ์ฉํ์ฌ ํ์ต์ํจ ๊ฒฐ๊ณผ๋ฌผ ์ ์ถ์ ์คํจํ์ง๋ง ์ ์ผ๋ จ์ ๊ณผ์ ์ ์งํํ๋ฉฐ ์ป์๋ ๊ฒฝํ๊ณผ ์ง์์ ์์ผ๋ก ๊ฐ๋ฐ์ ์์ด ํผ์ ์ด์ด ๋ ๋งํ ๊ฒ๋ค์ด์์ต๋๋ค. ๋ง์ง๋ง์ผ๋ก ์ฌ๊ธฐ์ ์ ์ ์์๋ ๊ฐ์ฅ ์ค์ํ ์ ์ agent๊ฐ ํ๊ณ ์ฌ๋ผ๊ฐ ์ ์๋ reward function์ ๋ง๋ค์ด์ค์ผ ํ๋ค๋ ์ ์
๋๋ค. ์ ๋นํ ์ฑ์ฐ๊ณผ ์ ๋นํ ๋น๊ทผ์ด ํ์ํฉ๋๋ค. reward๋ฅผ ํตํด ๋์ ์๋๋ฅผ agent์ ์ฌ์ ์ ์์ด์ผ ํฉ๋๋ค. ๋ํ์ง๋ ๋ํ์ง๋ ์๊ฒ ๋ง์ด์ฃ .\nReferences Bojarski, M., Del Testa, D., Dworakowski, D., Firner, B., Flepp, B., Goyal, P., \u0026hellip; \u0026amp; Zhang, X. (2016). End to end learning for self-driving cars. arXiv preprint arXiv:1604.07316. Ross, S., Gordon, G., \u0026amp; Bagnell, D. (2011, June). A reduction of imitation learning and structured prediction to no-regret online learning. In Proceedings of the fourteenth international conference on artificial intelligence and statistics (pp. 627-635). Torabi, F., Warnell, G., \u0026amp; Stone, P. (2018). Behavioral Cloning from Observation. arXiv preprint arXiv:1805.01954. Peng, X. B., Abbeel, P., Levine, S., \u0026amp; van de Panne, M. (2018). DeepMimic: Example-Guided Deep Reinforcement Learning of Physics-Based Character Skills. arXiv preprint arXiv:1804.02717. Liu, M. Q., Anderson, F. C., Schwartz, M. H., \u0026amp; Delp, S. L. (2008). Muscle contributions to support and progression over a range of walking speeds. Journal of biomechanics, 41(15), 3243-3252. Mnih, V., Kavukcuoglu, K., Silver, D., Rusu, A. A., Veness, J., Bellemare, M. G., \u0026hellip; \u0026amp; Petersen, S. (2015). Human-level control through deep reinforcement learning. Nature, 518(7540), 529. Xue Bin (Jason) Peng. (2018). Towards a Virtual Stuntman. Available at: https://bair.berkeley.edu/blog/2018/04/10/virtual-stuntman [Accessed 13 Dec. 2018]. UC Berkeley. (2018). Deep Reinforcement Learning. Available at: http://rail.eecs.berkeley.edu/deeprlcourse/ [Accessed 11 Dec. 2018]. Carnegie mellon university. (2018). Imitation Learning. Available at: http://www.andrew.cmu.edu/course/10-703/slides/Lecture_Imitation_supervised-Nov-5-2018.pdf [Accessed 12 Dec. 2018]. ๊ตฌํ ๋ด์ฉ์ ๋ํ ์ค๋ช
์ ๋ค์ posting์์ ๋ค๋ฃฐ ์์ ์
๋๋ค. ^ ๋
ผ๋ฌธ์์๋ ์ด ์์์ - ๊ธฐํธ๊ฐ ์๋ $\\ominus$ ๊ฐ ์ฌ์ฉ๋ฉ๋๋ค. ์ด์ ๋ ๋
ผ๋ฌธ์์ ์ฌ์ฉ๋ ๋ฐ์ดํฐ๊ฐ joint orientation์ quaternion๋ก ํํํ๊ธฐ ๋๋ฌธ์ธ๋ฐ, quaternion difference๋ฅผ ๊ตฌํ๋ ๊ฒ์ $\\ominus$๋ผ๊ณ ํ ๊ฒ์
๋๋ค. ์ฌ๊ธฐ์๋Towards a Virtual Stuntman์ ์ธ๊ธํ ๊ฒ์ฒ๋ผ ์ผ๋ฐ - ๋ฅผ ์ฌ์ฉํ์์ต๋๋ค. ^ ์ฌ์ค round2 reward์๋ z์ถ penalty๊ฐ ๋ ์์ต๋๋ค. ๋ค๋ง ์ฌ๊ธฐ์๋ ๊ฐ์ฅ ํฐ ์ ์ ์ฐจ์ด๊ฐ ๋ฐ์ํ๋ ๋ถ๋ถ์ด x์ถ penalty์ด๊ธฐ ๋๋ฌธ์ ๊ฐ์ํ๋ฅผ ์ํด ์๋ตํ์ต๋๋ค. ^ ","date":1545139337,"expirydate":-62135596800,"kind":"page","lang":"en","lastmod":1545139337,"objectID":"560003bdab8e68a5b8d3bbb0e877ff10","permalink":"/post/2018-12-18-nips2018-imitation_learning/","publishdate":"2018-12-18T22:22:17+09:00","relpermalink":"/post/2018-12-18-nips2018-imitation_learning/","section":"post","summary":"Imitation Learning for AI for Prosthetics Challenge","tags":[],"title":"[Competition] AI for Prosthetics Challenge - Imitation Learning","type":"post"},{"authors":["hyungkyu-kim"],"categories":[],"content":" ์ด๋ฒ ํํธ์์๋ Opensim ํ๊ฒฝ๊ณผ Task ์ ๋ํด ์ค๋ช
ํ๋๋ก ํ๊ฒ ์ต๋๋ค. (competition์ด ์ข
๋ฃ๋ ํ ์๋ก์ด webinar ๊ฐ ๋์์ต๋๋ค. ์์ธํ ์ค๋ช
๋์ด ์์ผ๋ ์ฐธ๊ณ ๋ฐ๋๋๋ค.)\n I. Opensim ๊ฐํ ํ์ต์์ ํ๊ฒฝ(environment)์ด๋ ๋งค์ฐ ์ค์ํ ์์์
๋๋ค. ๊ฐํํ์ต Agent๊ฐ interaction์ ํตํด ์ฃผ์ด์ง task๋ฅผ ์ํํ๋ ๊ณต๊ฐ์ด ๋ฐ๋ก ์ด๊ณณ์ด๊ธฐ ๋๋ฌธ์ ๋น์ฐํ ๋ง์ด๊ฒ ์ฃ . ์ด๋ค ๋ฐฉ์์ผ๋ก ์ ๊ทผํ๋ ํ๊ฒฝ์ ๋ํ ๊น์ ์ดํด๊ฐ ์ ํ๋์ด์ผ๋ง ์ข์ ์๋ฃจ์
์ด ๋์ฌ ์ ์๋คํด๋ ๊ณผ์ธ์ด ์๋๋๋ค. ๋๋ฌธ์ ์ ํฌ ํ์ ์ด๋ฒ ์ปดํํฐ์
์ ์งํํ๋ฉด์ opensim์ด๋ผ๋ ํ๊ฒฝ์ ์ฌ๋ ์๊ฒ ์ดํดํ๊ธฐ ์ํด ๋ง์ ๋
ธ๋ ฅ์ ๊ธฐ์ธ์์ต๋๋ค.\nOpensim์ ์ ๊ฒฝ๊ทผ ๊ณจ๊ฒฉ ๋ชจ๋ธ(neuromusculoskeletal model)์ ์์ง์์ ์๋ฎฌ๋ ์ด์
ํ๊ธฐ์ํ ์ํํธ์จ์ด์
๋๋ค. ์คํ๋ฐ์ดํฐ๋ฅผ ๋ถ์ํ๊ณ ์์ง์์ ์๋ฎฌ๋ ์ด์
ํ์ฌ ํด๋ถํ, ์๋ฆฌํ, ์ด๋์ญํ ๋ฑ์ ์ ๊ทผ์ ๊ฐ๋ฅํ๊ฒ ํฉ๋๋ค. ๊ต์ฅํ ๋ค์ํ ๋ถ์ผ์์ ์ฐ์ผ ์ ์๋๋ฐ, ์ด๋ ์ํ์ค๋ฅผ ๋ถ์ํด์ ๊ฐ์ ํ๋ค๋ ๊ฐ, Modeling Evaluation and Control Optimization of Exosuit with OpenSim ์ ๊ฐ์ด ์์กฑ์ด๋ ๊ธฐํ ๋ณด์กฐ๊ธฐ๊ธฐ ์ฐฉ์ฉ ์ ์์ง์ ์์ธก ๋ฑ๋ฑ์ ์ฐ์
๋๋ค. ์์คํ
์ ๋ชจ๋ ๋ถ๋ถ์ ์ ๋ถ ์ธ๊ธํ๊ธฐ์๋ ๋๋ฌด๋ ๋ฐฉ๋ํ๋ฏ๋ก ์ฌ๊ธฐ์๋ ๊ฐ๊ด์ ์ธ ๋ถ๋ถ๊ณผ opensim-rl์ ๊ด๋ จ๋ ๋ถ๋ถ ์์ฃผ๋ก ๊ธฐ์ ํ๋๋ก ํ๊ฒ ์ต๋๋ค.\nWorkflow ์ฐ์ opensim์ ์ด์ฉํ ๊ธฐ๋ณธ์ ์ธ ๋ถ์ ์ํ์ค๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.\n Elements of a typical musculoskeletal simulation in OpenSim. from OpenSim: Simulating musculoskeletal dynamics and neuromuscular control to study human and animal movement ๋ฐฉ๋ํ ์์คํ
๋ต๊ฒ ์์ฒด์ญํ์ ์์ง์์ ๋ํ ๋ค์ํ ๋ถ์์ด ๊ฐ๋ฅํ๋ฐ์. ์ด๋ค ๋ฐฉํฅ์ผ๋ก ๋ฌธ์ ๋ฅผ ๋ณด๋๊ฐ์ ๋ฐ๋ผ ํฌ๊ฒ 2๊ฐ์ง๋ก ๋๋ ์ ์์ต๋๋ค.\n Inverse problem Forward problem 1. Inverse problem ์ผ๋ฐ์ ์ผ๋ก opensim์ ์ฐ๋ ๋ง์ ์์ฒด ์ญํ ๋ถ์ผ์ ์ฐ๊ตฌ์๋ค์ด ์ฐ๋ ๋ฐฉ์์
๋๋ค. ์คํ๋ฐ์ดํฐ๋ฅผ ํตํด ์์ง์์ ๊ด๋ จ๋ ์ฌ๋ฌ ๊ฐ์ง ๋ถ์์ ํ๊ธฐ ์ํด ์ฌ์ฉ๋์ฃ . ์์ ์ํ์ค ๊ทธ๋ฆผ์์ ๋ณด๋ฉด Movement -\u0026gt; Neural command ๋ฐฉํฅ์ผ๋ก ์งํ๋๋ ํ๋ก์ธ์ค๋ผ๊ณ ๋ณผ ์ ์์ต๋๋ค. ๋ง์ปค๋ฅผ ๋ถ์ฐฉํด์ ์คํ์ผ๋ก๋ถํฐ ํน์ ๋ชจ์
์ ๊ดํ ๋ฐ์ดํฐ๋ฅผ ์ป์ด๋ด๊ณ , ์ด๋ฅผ ํตํด ์์ง์์ ์ญํ ๋ชจ๋ธ์ ๋ง๋ค์ด ๊ทผ์ก์ ํ์ฑํ ์ ๋์ ๊ทผ์ก์ ํ์ฑํ ์ํค๋ ๋ฐ ํ์ํ ์ ๊ฒฝ์ ํฅ๋ถ ์ ๋๋ฅผ ๊ณ์ฐํฉ๋๋ค. ๋ค์๊ณผ ๊ฐ์ ๋ฌธ์ ๋ค์ ๋ต์ ์ป์ด๋ด๋ ๊ณผ์ ์ ํตํด motion์ ๊ด๋ จ๋ ์ฌ๋ฌ ๊ฐ์ง ์์น๋ฅผ ์ป์ ์ ์์ต๋๋ค.\n Inverse problem. from Tutorial 3 - Scaling, Inverse Kinematics, and Inverse Dynamics Inverse kinematic ํด๋น motion์ ๋ง๋ค์ด๋ด๋ ๊ฐ joint์ angle ๊ฐ๋ค์ ๊ตฌํฉ๋๋ค. pose์ ๊ด๊ณ๋ ๋ด์ฉ์ด๋ฏ๋ก, ์ง๋์ด๋ ๊ด์ฑ ๊ฐ์ ๊ฐ๋ค์ ํ์ ์์ต๋๋ค.\nCF) Forward kinematics VS Inverse kinematics\n Forward kinematics๋ ์ฃผ์ด์ง joint position(angles)๋ค๋ก๋ถํฐ ๋ง๋จ์ฅ์น(end effector)์ ์์น๋ฅผ ๊ตฌํฉ๋๋ค. Forward kinematics. from Inverse Kinematics Inverse kinematics๋ ์ฃผ์ด์ง ๋ง๋จ์ฅ์น(end effector)์ ์์น๋ก๋ถํฐ joint position(angles)๋ค์ ๊ตฌํฉ๋๋ค. Inverse Kinematics. from Inverse Kinematics Inverse dynamics ํด๋น motion์ ์ ๋ฐํ๋ force์ moment๊ฐ๋ค์ ๊ตฌํฉ๋๋ค. ์ฌ๊ธฐ์ ์ป์ด๋ธ force๋ค์ ์ฌ์ฉํด์ ์ด๋ค ๊ทผ์ก๋ค์ด ์ผ๋ง๋งํผ์ ํ์ ๋ฐ๋์ง ์์๋
๋๋ค. ์ด๋ฅผ ๊ณ์ฐํ๊ธฐ ์ํด ์ง๋๊ณผ ๊ด์ฑ ๊ฐ์ ๊ฐ๋ค์ด ํ์ํฉ๋๋ค.\n๊ธฐ๋ณธ์ ์ผ๋ก ๋ดํด๊ณผ ์ค์ผ๋ฌ์ ์์์ด ์ฌ์ฉ๋ฉ๋๋ค.\n Newton (linear): F = m.a (Force = mass x linear acceleration) Euler (angular): M = I.ฮฑ (Moment = mass moment of inertia x angular acceleration) ๊ทธ๋ฆฌ๊ณ ๋ค์ ๊ฐ์ ๋ค์ด ์ ์ฉ๋ฉ๋๋ค.\n Joint๋ ๋ฌด๋ง์ฐฐ ํ ์กฐ์ธํธ(frictionless pin joint) ์ง๋ ์ค์ฌ์ ์ง์ค์ง๋์ด ์๋ค๊ณ ๊ฐ์ ๋ ๊ฐ ๊ฐ์ฒด๋ค์ ์กฐํฉ ์ฃผ๋๊ทผ๊ณผ ๊ธธํญ๊ทผ( agonist and antagonist)์ ๊ณต๋(๋์)์์ถ์ ์์ ๊ณต๊ธฐ ์ ํญ์ ์ต์ ์์ ํ ์ ๋ฐํ ์ธ์ฒด ๋์ ์ฐ๊ตฌ๊น์ง๋ ๋ถ๊ฐ๋ฅํ์ง๋ง, ์๋นํ ์ ์๋ฏธํ ๊ฒฐ๊ณผ๋ฅผ ์ป์ ์ ์์ต๋๋ค.\n2. Forward problem ์ด๋ฒ competition์์ ์ฐ์ด๋ opensim-rl์์ ์ฌ์ฉ๋๋ ๋ฐฉ์์
๋๋ค. Neural command -\u0026gt; Movement ๋ฐฉํฅ์ผ๋ก ์งํ๋ฉ๋๋ค. ์ผ๋ฐ์ ์ธ ์ธ๊ฐ, ๋๋ฌผ์ ์์ง์์ ๋ ์ฌ๋ฆฌ๋ฉด ๋ฉ๋๋ค. neural command์ excitation ์ ๋์ ๋ฐ๋ผ ๊ทผ์ก์ ์์ถ/์ด์์ ๊ธธ์ด์ ์๋๊ฐ ๊ฒฐ์ ๋๊ณ ๊ทธ์ ๋ฐ๋ฅธ motion์ด ๋ง๋ค์ด์ง๋๋ค.\nArchitecture Opensim์ ์ ์ฒด ๊ตฌ์กฐ๋ ๋ค์ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ต๋๋ค. ํ๋ถ ๋จ์ simtk API ๋ฅผ ์ด์ฉํ์ฌ ์ด๋ฃจ์ด์ ธ ์๋๋ฐ ์ค์ ์๋ฎฌ๋ ์ด์
๊ด๋ จ ๊ณ์ฐ์ ๋๋ถ๋ถ ์ฌ๊ธฐ์ ์ด๋ฃจ์ด์ง๋๋ค. OpenSim\u0026rsquo;s Architecture. from OpenSim\u0026rsquo;s Architecture and API \nExacutables Opensim API๋ฅผ ์ด์ฉํ ์ฌ๋ฌ ๊ฐ์ง ์์ฉ ์์คํ
๋ค์
๋๋ค. opensim gui app๋ถํฐ ์ด๋ฒ competition์์ ์ฌ์ฉ๋๋ opensim-rl ๊น์ง ๋ชจ๋ ์ด ๋ถ๋ถ์ ์ํฉ๋๋ค.\n๋๋ต ๋ค์๊ณผ ๊ฐ์ ์ธํฐํ์ด์ค๋ฅผ ํตํด opensim์ ์ฌ์ฉ ๊ฐ๋ฅํฉ๋๋ค.\n GUI command line XML Python scripting MATLAB scripting C++ Opensim API ์๋ฎฌ๋ ์ด์
์ํ์ ์ํ ๋ชจ๋ธ์ ๊ตฌ์กฐ๋ฅผ ์ ์ํฉ๋๋ค. ๊ทผ๊ณจ๊ฒฉ ๊ด๋ จ ,์ ๊ฒฝ ๊ด๋ จ ๋ฑ์ ์ค์ ๊ด๋ จ ๋ชจ๋๋ค์ ๊ฐ๊ณ ์์ต๋๋ค. SimTK๋ฅผ ์ด์ฉํ์ฌ ์๋ฎฌ๋ ์ด์
์ ์ํํฉ๋๋ค.\n Model: ๊ทผ๊ณจ๊ฒฉ ๋ชจ๋ธ class. xml ํ์ผ์ ํตํด ์ค์ ์ ์ฝ์ด์ฌ ์ ์์ต๋๋ค. ModelComponents ๋ค์ ํฌํจํฉ๋๋ค. OpenSim Model Class Structure. from OpenSim\u0026rsquo;s Architecture and API \n ModelComponent: ๊ทผ๊ณจ๊ฒฉ ๋ชจ๋ธ์ ํน์ ๋ถ๋ถ์ ๋ํ๋ด๋ class. simtk์ multibodySystem์์ ์ฌ์ฉ๋์ด ๊ณ์ฐ๋ฉ๋๋ค. OpenSim ModelComponent. from OpenSim\u0026rsquo;s Architecture and API \n Manager: ์ ์ฒด ์๋ฎฌ๋ ์ด์
๋์์ ๊ด๋ฆฌํ๋ class. SimTK::Integrator ์ SimTK::TimeStepper๋ฅผ ์ด์ฉํ์ฌ ์๋ฎฌ๋ ์ด์
์ ์ํํฉ๋๋ค.\n Analysis: ๋ถ์ ๊ด๋ จ plug-in class. ์๋ฎฌ๋ ์ด์
๊ณผ ๊ด๋ จ๋ ์ฌ๋ฌ ๊ฐ์ง ๋ถ์๋ ์์น๋ค์ ๊ธฐ๋กํ ๋ ์ฌ์ฉํฉ๋๋ค.\n SimTK ์๋ฎฌ๋ ์ด์
๋์์ ์ํ ์ฐ์ฐ ์์ง์
๋๋ค. SimTK::Integrator ์ SimTK::TimeStepper์ด time step ๋ณ๋ก ์๋ฎฌ๋ ์ด์
์ ๋ณํ๋ฅผ ๊ณ์ฐํฉ๋๋ค. ๋ด๋ถ์ ์ผ๋ก ๋ดค์ ๋ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ด subsystem ๋ค๋ก ๊ตฌ์ฑ๋์ด ์์ต๋๋ค. Systems are composed of Subsystems. from Simbody User\u0026rsquo;s Guide \u0026ndash; start here ์ด subsystem๋ค์ด ์๋ฎฌ๋ ์ด์
์ ํ์ฌ time step์ state๋ค์ ์ด์ฉํ์ฌ ๋ค์ state๋ค์ ๋ง๋ค์ด๋
๋๋ค. state๋ค์ stage๋ฅผ ๊ฐ๊ณ ์์ผ๋ฉฐ ์์ฐจ์ ์ผ๋ก ๊ณ์ฐ๋์ด ์ ์ฅ๋ฉ๋๋ค. ์ด์ stage์ ๊ฒฐ๊ณผ๋ ๋ค์ stage์ ๊ณ์ฐ์์ ์ฌ์ฉ๋์ด ์ง๋๋ค. ์ ์ฒด ๊ตฌ์กฐ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. The organization of a computation into ordered stages. from Simbody User\u0026rsquo;s Guide \u0026ndash; start here state์์ ์ฌ์ฉ๋๋ ์ฃผ์ ๋ณ์๋ค์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.\n t: time q: generalized coordinates u: generalized speeds z: auxiliary variables Structure ์ ์ด์ ์์์ ์ธ๊ธํ๋ ๋ชจ๋ ๋ชจ๋๋ค๊ณผ ์์คํ
๋ค์ด ํฉ์ณ์ง ์ ์ฒด ๊ตฌ์กฐ๋ฅผ ๋ด
์๋ค. opensim์์ visualization๋๋ model๋ถํฐ ํ๋ถ์ simtk๊น์ง ๋ค์ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ ์ฐ๊ฒฐ ๊ตฌ์กฐ๋ก ๋์ด ์์ต๋๋ค. The OpenSim modeling layer. from OpenSim\u0026rsquo;s Architecture and API \nTools Opensim์ ํ์ํ ์์น๋ค์ ๊ตฌํ ์ ์๋๋ก ๋ฏธ๋ฆฌ ๊ตฌํ๋ application์ธ computational tool๋ค์ ์ ๊ณตํด์ค๋๋ค. Opensim GUI app์์ ์ฌ์ฉํ ์ ์๊ณ , script ๋ฐฉ์์ผ๋ก matlab์ด๋ python์์๋ ์ง์ ํจ์๋ฅผ ํธ์ถํ์ฌ ์ฌ์ฉ ๊ฐ๋ฅํฉ๋๋ค.\ntool์ ๊ธฐ๋ณธ์ ์ผ๋ก ํ์ํ ์ค์ ํ์ผ, ๋ฐ์ดํฐ ํ์ผ๋ค์ loadํด์ ์ฌ์ฉํ๋๋ฐ์. RRA tool์ ์์ ๋ฅผ ๋ณด๋ฉด ๋ค์๊ณผ ๊ฐ์ต๋๋ค. Inputs and Outputs for performing residual reduction. from Getting Started with RRA ์ข์ธก์ subject01_walk1_ik.mot, subject01_walk1_grf.xml, subject01_simbody.osim ์ด ์ธํ๋๋ ๋ฐ์ดํฐ์ ๋ชจ๋ธ๋ค์ด๊ณ , ์๋จ์ gait2354_RRA_Actuators.xml, gait2354_RRA_Tasks.xml์ด ๊ด๋ จ ์ค์ ๋ค ์
๋๋ค. ์ค์ ํ์ผ์ ํ๋ฒ์ ํฉ์ณ์ subject01_Setup_RRA.xml๋ก ์
๋ ฅํ ์ ์์ต๋๋ค. ์ฐ์ธก์ ํ์ผ๋ค์ ๊ฒฐ๊ณผ๋ฌผ๋ก ๋์ค๊ฒ๋๋ ์์ํ๋ค์
๋๋ค.\nGUI app์์์ ์ฌ์ฉ๋ฒ์OpenSim: Complete Run-through youtube๋ฅผ ์ฐธ๊ณ ํ์๊ธฐ ๋ฐ๋๋๋ค.\n๋ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํํ๋ก ์ ๊ณต๋ tool๋ค์ ์ฝ๋์์์ ์ฌ์ฉํ๋ ์์ ๋ medipixel git ์ ์ฐธ๊ณ ํ์๊ธฐ ๋ฐ๋๋๋ค.\nScale ์คํ ๋ฐ์ดํฐ๋ ๋ณดํต ๋ชจ์
์บก์ณ๋ฅผ ํตํด ์ป๊ฒ ๋ฉ๋๋ค. ์ ์ฒด ์ฌ๋ฌ ๋ถ์์ ๋ง์ปค๋ฅผ ๋ฌ๊ณ ์ธก์ ๋๋ ๊ฐ๊ฐ์(x, y, z)์ขํ๋ฅผ ๊ธฐ๋กํ๋๋ฐ์, ์ฌ๊ธฐ์ ํ๋ํ๊ฒ ๋๋ ์ขํฏ๊ฐ๋ค์ ๋ง์ปค๋ฅผ ๋ฌ๊ณ ์๋ ์ฌ๋์ ์ ์ฒด๋น์จ์ ๋ฐ๋ผ ์กฐ๊ธ์ฉ ๋ฌ๋ผ์ง๋๋ค. ๋ฐ๋ผ์ ์ ํํ ์๋ฎฌ๋ ์ด์
์ ์ํด์๋ ์ค์ ์ธก์ ํ ์ฌ๋์ ์ ์ฒด ๋น์จ๊ณผ ์๋ฎฌ๋ ์ด์
์ ์ฌ์ฉ๋ ๋ชจ๋ธ์ ๋น์จ์ ๋ง์ถฐ์ฃผ๋ ์์
์ด ํ์ํ๋ฐ, ์ด ๋จ๊ณ์์ ์ฌ์ฉ๋๋ tool์ด Scale tool์
๋๋ค. Experimental and Virtual Markers. from How Scaling Works ๊ทธ๋ฆผ๊ณผ ๊ฐ์ด ๋ง์ปค ์ธก์ ๋น์จ e1, e2 ์ ๋ชจ๋ธ์ m1, m2์ ๊ฐ์ด ๊ฐ๊ธฐ ๋์๋๋ ์ ๋ค ๊ฐ์ ๊ฑฐ๋ฆฌ๋ฅผ ๋ง์ถฐ์ค๋๋ค.\nInverse Kinematics IK(Inverse Kinematics) tool์ ๊ฐ ์คํ ๋ฐ์ดํฐ๋ก๋ถํฐ opensim model์ ํฌ์ฆ๋ฅผ ๋ง๋ค๊ธฐ ์ํด ์ฌ์ฉ๋ฉ๋๋ค. ๊ฐ time step ๋ณ๋ก ์ธก์ ๋ marker์ ์ขํฏ๊ฐ๊ณผ ๊ฐ์ฅ ์ผ์นํ๋ ํฌ์ฆ๋ก ๋ชจ๋ธ์ ์์น์ํค๋ ์ผ๋ฐํ๋ ์ขํ(generalized coordinate)๊ฐ๋ค์ ๊ณ์ฐํฉ๋๋ค. ์ผ์นํ๋ ํฌ์ฆ๋ ๋ชจ๋ธ์ ๋ง์ปค์ ์คํ๋ฐ์ดํฐ ๋ง์ปค์ ๊ฑฐ๋ฆฌ์ธ marker error๋ฅผ ์ต์ํํ๋ ๋ฐฉํฅ์ผ๋ก ๊ณ์ฐํ๋๋ฐ์. marker์ ์ค์๋์ ๋ฐ๋ผ์ ๊ฐ์ค์น๋ฅผ ๋ถ์ฌํฉ๋๋ค. ๊ทธ๋์ ๊ฐ marker๋ค์ weighted least square๊ฐ์ ํฉํ์ฌ ์ด๊ฒ์ min ๊ฐ์ด ๋๋ ํฌ์ฆ๋ฅผ ์ฐพ์๋
๋๋ค. ์์์ผ๋ก ํํํ๋ฉด ๋ค์๊ณผ ๊ฐ์ต๋๋ค.\n$$ min_q \\left[ \\sum_{i\\in{markers}}w_i |x_i^{exp} - x_i(q)|^2 \\right] $$\nResidual Reduction Algorithm ์คํ ๋ฐ์ดํฐ๋ noise๋ฅผ ํฌํจํฉ๋๋ค. noise ์๊ธฐ๋ ์ด์ ๋ ์ฌ๋ฌ ๊ฐ์ง๊ฐ ์์ผ๋ ๊ฐ์ฅ ์ค์ํ ์์ธ์ ํฌ๊ฒ 3๊ฐ์ง๊ฐ ์์ต๋๋ค.\n ํ์ด ์๋ค ์ธก์ ์์ noise ์ธก์ ์์น ๋ง์ปค ์๋ฌ ์ด๋ฌํ ์์ธ๋ค์์ํด inverse dynamics๋ฅผ ์ํํ ๋ residual force๋ผ๋ ์ถ๊ฐ์ ์ธ ํ์ด ๋ฐ์ํ๊ฒ ๋ฉ๋๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ์ ์ฒด inverse dynamics๋ฅผ ํตํด ๊ตฌํ์ฌ์ง force์์ residual force๋ฅผ ๊ทผ์ (์ต์ํํ์ฌ)ํ๊ฒ ์ฐ์ถ ํด์ ๋นผ์ค์ผ ์ ํํ force๋ฅผ ์ป์ด ๋ผ ์ ์์ต๋๋ค. ์๋์๊ณผ ๊ฐ์ด ๋ํ๋ด๊ฒ ๋ฉ๋๋ค.\n$$ F + F_{\\text{residual}} = ma $$\nRRA tool์ ์ด๋ฐ ๊ธฐ๋ฅ์ ์ํํฉ๋๋ค.\nStatic Optimization Inverse dynamics๋ฅผ dicrete time๋ณ๋ก ํ์ด๋
๋๋ค. ์ฌ๊ธฐ์ ์์๋ธ force์ moments๋ฅผ ์ฌ์ฉํ์ฌ, ๊ทผ์ก์ ํ์ฑํ ์ ๋๋ฅผ ๊ณ์ฐํฉ๋๋ค. ์ฌ๊ธฐ์ ํ์ฑํ ์ ๋๋ฅผ ๊ณ์ฐํ ๋ ๊ทผ๋ ฅ์ด ๊ฐ์ง๊ณ ์๋ ํ๊ณ๋ฅผ ๋์ด๊ฐ์ง ์๋๋ก ์ ํํฉ๋๋ค. ์์์ ๋ณด๋ฉด ๋ค์๊ณผ ๊ฐ์ต๋๋ค.\n$$ \\sum_{m=1}^n(a_mF_m^0)r_{(m,j)} = \\tau_j $$\n $a_m$: ๊ทผ์ก์ activation level $F_m^0$: ์ต๋ ์์ถ ํ $r_{(m,j)}$: moment arm ์ด๋ฅผ force-length-velocity ์์ฑ์ ์ถ๊ฐํ์ฌ ๋ฐ๊พธ๋ฉด ๋ค์๊ณผ ๊ฐ์ต๋๋ค.\n$$ \\sum_{m=1}^n[a_mf(F_m^0,l_m,v_m)]r_{(m,j)} = \\tau_j $$\n $f(F_m^0,l_m,v_m)$: force-length-velocity์ด์ฉํ ํ ๊ด๋ จ ํจ์ $l_m$: ๊ทผ์ก์ ๊ธธ์ด $v_m$: ์์ถ ์๋ Computed Muscle Control ์๋์ ๊ฐ์ด Static Optimization๊ณผ Forward dynamics๋ฅผ ๋ฒ๊ฐ์ ์ํํ๋ฉฐ, ํด๋น kinematics๋ฅผ ๋ง๋ค์ด๋ผ ์ ์๋ ๊ทผ์ก์ activation level์ ๊ณ์ฐํฉ๋๋ค. Schematic of the Computed Muscle Control Algorithm Applied to Gait. from How CMC Works \nForward dynamics Forward problem์ ์ํํฉ๋๋ค. ์ผ๋ฐ์ ์ผ๋ก ์ ํต์ ์ธ opensim ์คํ๋ฐ์ดํฐ์๋ ์ ๊ฒฝ์ excitation์ ํฌํจ๋์ด ์์ง ์์ต๋๋ค. ๋ฐ๋ผ์ ์๋์ ๊ฐ์ tool๋ค์ ์ฐจ๋ก๋๋ก ์ด์ฉํ์ฌ ์ป์ด๋ธ excitation(control) ๊ฐ์ ์ฌ์ฉํฉ๋๋ค. - Scale - Inverse Kinematics - Residual Reduction Algorithm - Computed Muscle Control Typical workflow for generating a muscle-driven simulation. from Overview of the OpenSim Workflow \n II. Opensim-rl Opensim-rl์ ์๋ ๊ทธ๋ฆผ์์ main()๊ณผ ๊ฐ์ด opensim ๋ชจ๋ธ๊ณผ manager๋ฅผ ์ด์ฉํ์ฌ ์๋ฎฌ๋ ์ด์
์ ์ํํ๋ ํ๋ก๊ทธ๋จ์
๋๋ค. from OpenSim\u0026rsquo;s Architecture and API \nswig๋ฅผ ์ฌ์ฉํ์ฌ python scripting ๋ฐฉ์์ผ๋ก ๊ตฌํ๋์ด ์์ต๋๋ค. ์์ ์ค๋ช
์์ forward problem ๊ณผ ๊ฐ์ ๋ฐฉํฅ์ผ๋ก ์งํ๋ฉ๋๋ค. agent๋ neural command(action)์ ์ด์ฉํ์ฌ model์ ์ปจํธ๋กค ํฉ๋๋ค.\n III. Walking/Running gait ์ด๋ฒ competition์์ ์ฃผ์ด์ง Task๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.\n Round1: 3์ด๊ฐ 3m/s์ ๋ง์ถฐ ๋ฐ๊ธฐ Round2: 10์ด๊ฐ 1.25m/s์ ๋ง์ถฐ ๊ฑท๊ธฐ 1 ์ ํฌ ํ์ ์ด Task ํด๊ฒฐ์ ์ํด ํ๊ฒฝํ์
๋ชป์ง์๊ฒ \u0026ldquo;Walking/Running gait\u0026rdquo; ๋ฌธ์ ์ ๊ดํ ํ๊ตฌ์๋ ๋ง์ ์๊ฐ์ ํฌ์ํ์์ต๋๋ค.\n๊ฐํํ์ต์์ Task๊ฐ ํ์
์ด ์๋์๋ค๋ฉด reward ์ค์ ๋ ์ํ ์ ์์ต๋๋ค. Task๋ฅผ ์ ํ์
ํ๋ค๋ฉด agent ํ์ต ์ ๊ทธ ๋ชฉ์ ์ ๋ฐ๋ผ ์ด๋ค ๋ถ๋ถ์ reward๋ก ์ค์ ํ์ฌ ๋ ๊ฒฉ๋ คํ ์ง ์๋๋ฉด penalty๋ก ์ค์ ํ์ฌ ์ต์ ํ ์ง ๋ช
ํํด์ง๊ธฐ ๋๋ฌธ์, ์ํํ ํ์ต์ด ๊ฐ๋ฅํด์ง๋๋ค. ๋ํ, ๋ค์ part์์ ์ธ๊ธํ imitation learning๊ณผ ๊ฐ์ ๋ฐฉ๋ฒ๋ก ์ ์ฌ์ฉํ ๋์๋ Task์ ๋ํ ๋ช
ํํ ์ดํด๊ฐ ์์ด์ผ๋ง ๊ฐ์ด๋๋ก ์ฌ์ฉํ demonstration์ด ์๋์๋์ง ์๋์๋์ง์ ๋ํด ์ ์ ์์ต๋๋ค. ์ด์ ์ ์ ์๋ ค์ฃผ๋ ค๋ฉด ์ด์ ์ ๋ํด ์ ์์์ผ ํ๊ณ , ๋ฌ๋ฆฌ๊ธฐ๋ฅผ ์ ์๋ ค์ฃผ๋ ค๋ฉด ๋ฌ๋ฆฌ๊ธฐ๋ฅผ ์ ์์์ผ ํฉ๋๋ค. Task์ ๋ํ ์ดํด๋๊ฐ ๋์ผ๋ฉด ๋์์๋ก ์ข์ agent๋ฅผ ๋ง๋ค ์ ์๋ ํ๋ฅ ์ด ์ฌ๋ผ๊ฐ๋๋ค. ๊ทธ๋ฐ ์๋ฏธ์์ ๊ฑท๊ธฐ์ ๋ฌ๋ฆฌ๊ธฐ ๋ฉ์ปค๋์ฆ์ ๋ํ ์ดํด๋ ๋งค์ฐ ์ค์ํ ๋ถ๋ถ์ด์์ต๋๋ค.\nExperimental Data ๋ง์นจ nips2018์์๋ ์๋
๊ณผ๋ ๋ค๋ฅด๊ฒ experimental data๋ฅผ ์ฌ์ฉํ ์ ์๋ค๋ ์ ์ฝ์ฌํญ์ด ์ฌ๋ผ์ก์ต๋๋ค. ์ฐ์ simtk ์ปค๋ฎค๋ํฐ๋ฅผ ๊ฒ์ํ๋ฉด์ ์ฌ๋ฌ ๊ณต๊ฐ๋ฐ์ดํฐ ์
๊ณผ ๊ธฐ์กด ์ฐ๊ตฌ๋ค์ ์กฐ์ฌํ์๋๋ฐ์, ๊ฐ์ฅ ์ค์ ์ ์ผ๋ก ํ์ธํ ์ฌํญ์ gait cycle ์ค kinematic์ ๋ณํ๋ค, ์ฆ joint๋ค์ ์์ง์์ด ์ด๋ค ํจํด์ ๊ฐ๋๊ฐ์์ต๋๋ค. ๋คํํ ์ด๊ฒ์ ๋ํด์๋ ์ฌ๋ฌ ๊ฐ์ง ๊ทธ๋ํ์ ๋ฐ์ดํฐ์ ํํ๋ก ๋ง์ ๋ถ์์ด ์งํ๋์ด ์์์ต๋๋ค. ๊ทธ ์ค Multiple Speed Walking Simulations๋ผ๋ ์ฐ๊ตฌ์์ round 2์์ ์ฌ์ฉํ ๋งํ ๋ฐ์ดํฐ์
์ ๋ฐ๊ฒฌํ ์ ์์์ต๋๋ค. walkning speed๊ฐ ์ ํํ๊ฒ 1.25m/s๋ ์๋์์ง๋ง subject 2, 3์ free speed์ ๊ฒฝ์ฐ์๋ ๊ทธ์ ๋น์ทํ ์๋(1.21, 1.29)๋ก ์ฌ์ฉํ ๋งํ ์์น์์ต๋๋ค. round1์ opensim-rl page์ ์์๋ก ์ ๊ณต๋ Muscle contributions to mass center accelerations over a range of running speeds ์ฐ๊ตฌ์์ ์ ๊ณต๋ ๋ฐ์ดํฐ์
์ด ์ ํํ๊ฒ 3m/s๋ก ๋ฌ๋ฆฌ๋ ๋ฐ์ดํฐ์๊ธฐ ๋๋ฌธ์ ๋น๊ต์ ์ฝ๊ฒ ๊ฒฐ๋ก ์ ๋ด๋ฆด ์ ์์์ต๋๋ค.\n์์ ๋ฐ์ดํฐ์
์ opensim์์ ๋์์ํค๋ฉด ๋ค์๊ณผ ๊ฐ์ ๋ชจ์ต์
๋๋ค. ๋จผ์ round1 ์ฉ ๋ฐ์ดํฐ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. ๊ทธ ๋ค์์ round 2์ฉ ๋ฐ์ดํฐ ์
๋๋ค. \nProper data-type โป ์๋ ๋์ค๋ Imitation learning ๊ด๋ จ ์์ธํ ๋ด์ฉ ์ค๋ช
์ Imitation learning posting์์ ๋ค๋ฃฐ ์์ ์
๋๋ค.\n๊ทธ๋ฌ๊ณ ๋์ ํ๋ ๊ณ ๋ฏผ์ ์ด ๋ฐ์ดํฐ๋ค์ ์ด๋ป๊ฒ ํ๋ฉด imitation learning์์ ์ฌ์ฉํ ๋งํ demonstrationํํ๋ก ๋ฐ๊ฟ ์ ์๋๊ฐ์์ต๋๋ค. ์ต์ด์ ์๋๋ ์์ ํ Behavioral cloning์ ์๊ฐ ํ์๊ธฐ ๋๋ฌธ์, action์ ๊ด๋ จ๋ ๋ฐ์ดํฐ๋ ๋ง๋ค์ด๋ด๊ธฐ ์ํด ๋
ธ๋ ฅํ์์ต๋๋ค. ์ opensim tool์์ ์ค๋ช
ํ์์ง๋ง, ๊ธฐ์กด opensim์ ์ด์ฉํ ์ฐ๊ตฌ์๋ค์ด forward problem์ ํด๊ฒฐํ๋ ๋ฐฉ์์ฒ๋ผ Data -\u0026gt; CMC tool ๊ณผ์ ์ ๊ฑฐ์ณ Neural command ์ฆ action์ ๋ง๋ค์ด๋ด๋ ค๊ณ ํ์ง์. ๋ค๋ง ์ด ์๋๋ ๋ช ๊ฐ์ง ์ ์ฝ์ฌํญ ๋๋ฌธ์ ๋๊ด์ ๋ด์ฐฉํ์๋๋ฐ\n ๊ธฐ์กด์ ์ฐ๊ตฌ๋ ๋ฐ์ดํฐ๋ค์ ๊ฐ๊ธฐ ๋ค๋ฅธ opensim model๋ค์ ์ฌ์ฉํ๋ค ์ฌ์ฉ๋ model์ ๋ฐ๋ผ ๊ด์ ์ ์์ ๋(DoF: Degree of Freedom)๊ฐ ๋ค๋ฅด๋ค ์ฌ์ฉ๋ model์ ๋ฐ๋ผ ๊ทผ์ก์ ๊ฐ์๊ฐ ๋ค๋ฅด๋ค CMC tool์ ์ฌ์ฉํ ๋ ๋ณดํต external forces, reserve actuators๋ฅผ ๋ฑ๋กํ์ฌ ์ฌ์ฉํ๋๋ฐ, opensim-rlํ๊ฒฝ์์๋ ์ฌ์ฉ ๋ถ๊ฐ๋ฅ์ด๋ค ๊ฒฐ๊ตญ, ์ด๋ฐ ๋ฌธ์ ์ ๋ค ๋๋ฌธ์, Behavioral cloning์ผ๋ก ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ค๋ ์ ๊ทผ์ ํ๊ธฐ๋์์ต๋๋ค.\n๊ทธ๋์ action์ ๋ํ data ์์ด ๊ด์ฐฐ๋๋ ๋ชจ์ต(kinematics)์ data๋ง ์ด์ฉํ์ฌ ํ์ตํ ์ ์๋ ๋ฐฉ๋ฒ๋ก 2์ ์ฐพ์๋ด์๊ณ , ์คํ๋ฐ์ดํฐ๋ฅผ ์ ํฉํ demonstration์ผ๋ก ๊ฐ๊ณตํ๊ธฐ ์ํด ๊ณ ๋ฏผํ์์ต๋๋ค.\nMaking Demonstration ์คํ๋ฐ์ดํฐ๋ ๊ธฐ๋ณธ์ ์ผ๋ก ๋ค์๊ณผ ๊ฐ์ ์ ์ฝ๋ค์ด ์์์ต๋๋ค.\n Round1์ 3์ด๊ฐ ๋์, Round2๋ 10์ด๊ฐ ๋์ํด์ผ ํจ์ ๋นํด demo ์๊ฐ์ด ๋๋ฌด ์งง๋ค(1์ด ์ดํ) ์ ์๋ฆฌ ํน์ ์งง์ ๊ฑฐ๋ฆฌ๋ง ์ด๋ํ๋ค ์คํํ
๋์์ด ์๋ค ์ ์ ์ฝ์ kinematics ๋ฐ์ดํฐ๋ฅผ ์์ ํ์ฌ ํด๊ฒฐํ์์ต๋๋ค. ์คํ๋ฐ์ดํฐ์ ์๋ gait cycle(๊ฑท๋ ๋์)์ ๋ฐ๋ณต์ ์ผ๋ก ์ด์ด๋ถ์ด๊ณ , ์ค๊ฐ์ ์ด์ํ ๋ถ๋ถ์ ๋ฐ์ดํฐ๋ฅผ ์๋ก ๋ง๋ค์ด ๋ฃ์์ต๋๋ค.\n๊ทธ๋ ๊ฒ ๋ง๋ค์ด์ง round 1์ Demo๋ ๋ค์๊ณผ ๊ฐ์์ต๋๋ค. round 2์ Demo๋ ๋ค์๊ณผ ๊ฐ์ด ๋ง๋ค์ด์ก์ต๋๋ค. \n๋ํ, ํด๊ฒฐํด์ผ ํ๋ ๋ถ๋ถ์ ์ฌ๊ธฐ์ ๋ง๋ค์ด์ง kinematic ๋ฐ์ดํฐ์ ํํ์ opensim-rl์์ ๊ด์ธก๋๋ observation state์ ํํ๊ฐ ๋ค๋ฅด๋ค๋ ์ ์ด์์ต๋๋ค.\n์ด๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด opesim python script๋ฅผ ์ด์ฉํ์ฌ ๊ฐ๋จํ transfer ํ๋ก๊ทธ๋จ์ ๋ง๋ค์์ต๋๋ค. ํด๋น ์ฝ๋๋ medipixel git์์ ํ์ธ ๊ฐ๋ฅํฉ๋๋ค. ๋ณํ๊ณผ์ ์ ๊ฐ๋จํ๊ฒ ์ค๋ช
ํ๋ฉด\n motion ๋ฐ์ดํฐ๋ฅผ ์ฝ์ด์จ๋ค 0.01 ์ด๋ง๋ค ์๋ ๊ณผ์ ์ ๋ฐ๋ณต motion ๋ฐ์ดํฐ์ time step ๋ณ๋ก ์ ์ฅ๋ ๋ฐ์ดํฐ๋ฅผ ํตํด ์๋ฎฌ๋ ์ด์
์ ๊ตฌ๋์ํจ๋ค model์ ์ ๋ณด(observation)๋ฅผ ์ฝ์ด์์ list์ ์ ์ฅํ๋ค list์ ์ ์ฅ๋ ์ ๋ณด์ shape์ ๋ณํํ๋ค ์์ ๊ฐ์ ๊ณผ์ ์ ๊ฑฐ์ณ ์๋ก์ด demonstration์ผ๋ก ์ฌ์ฉ ๊ฐ๋ฅํ ํํ๋ก ๋ณํ์ํต๋๋ค.\n References Seth, A., Hicks, J. L., Uchida, T. K., Habib, A., Dembia, C. L., Dunne, J. J., \u0026hellip; \u0026amp; Hamner, S. R. (2018). OpenSim: Simulating musculoskeletal dynamics and neuromuscular control to study human and animal movement. PLoS computational biology, 14(7), e1006223. Delp, S. L., Anderson, F. C., Arnold, A. S., Loan, P., Habib, A., John, C. T., \u0026hellip; \u0026amp; Thelen, D. G. (2007). OpenSim: open-source software to create and analyze dynamic simulations of movement. IEEE transactions on biomedical engineering, 54(11), 1940-1950. Liu, M. Q., Anderson, F. C., Schwartz, M. H., \u0026amp; Delp, S. L. (2008). Muscle contributions to support and progression over a range of walking speeds. Journal of biomechanics, 41(15), 3243-3252. University of Michigan. (2018). Inverse Kinematics. Available at: http://web.eecs.umich.edu/~ocj/courses/autorob/autorob_10_ik_closedform.pdf [Accessed 01 Dec. 2018]. Chris Kirtley. (unknown). Inverse Dynamics. Available at: http://www.clinicalgaitanalysis.com/teach-in/inverse-dynamics.html. [Accessed 01 Dec. 2018]. Michael Sherman. (2011). Simbody documentations. Available at: https://simtk.org/docman/?group_id=47. [Accessed 01 Dec. 2018]. NCSRR. (2018). Opensim documentations. Available at: https://simtk-confluence.stanford.edu/display/OpenSim/Documentation. [Accessed 07 Dec. 2018]. overfit ๊ฒ์ฌ๋ฅผ ์ํด ๋ง์ถฐ์ผ ํ ์๋๋ ๊ฐ๋ณ์ ์ด๊ธฐ๋ ํ๋ ๊ธฐ๋ณธ์ ์ผ๋ก 1.25m/s์
๋๋ค. ^ Behavioral cloning from observation, DeepMimic ^ ","date":1544361737,"expirydate":-62135596800,"kind":"page","lang":"en","lastmod":1544361737,"objectID":"17196bfbd7ebac42cfbbb6df808c0679","permalink":"/post/2018-12-09-nips2018-opensim/","publishdate":"2018-12-09T22:22:17+09:00","relpermalink":"/post/2018-12-09-nips2018-opensim/","section":"post","summary":"Opensim in AI for Prosthetics Challenge","tags":[],"title":"[Competition] AI for Prosthetics Challenge - Opensim","type":"post"},{"authors":["hyungkyu-kim"],"categories":[],"content":" ์ ํฌ Medipixel์ ์ด๋ฒ NIPS 2018 - AI for Prosthetics Challenge์ ์ฐธ์ฌํ์ฌ 401ํ ์ค 17์๋ผ๋ ์ฑ์ ์ผ๋ก ๋ง๊ฐํ๊ฒ ๋์์ต๋๋ค. competitoin์ ์งํํ๋ฉฐ ์ํ์ฐฉ์ค ๋์ ๋ง์ ๊ฒ๋ค์ ๋ฐฐ์ธ ์ ์์๋๋ฐ์. ๊ทธ๊ฐ ์ฌ๋ฌ ๊ฐ์ง ๋ฆฌ์จ์น์ ์๋๋ฅผ ํ๋ฉฐ ์ป์๋ ์ง์๊ณผ ๊ฒฝํ๋ค์ ๋ณธ post๋ฅผ ๊ธฐ์ ์ผ๋ก ๋ช ํ์ ๊ฑธ์ณ ์ ๋ฆฌํ๊ณ ์ ํฉ๋๋ค. ์ด๋ฒ Post์์๋ ์ฐ์ ๋ณธ๊ฒฉ์ ์ธ ๋ด์ฉ ํ๊ตฌ์ ์์ ์ด ๋ํ๋ ์ด๋ค ๋ํ์๋์ง, ์ด๋ค ๋ฐฉ์์ผ๋ก ์ ๊ทผ์ ํ์๋์ง์ ๋ํด ๊ฐ๋จํ๊ฒ ์ ๋ฆฌํ๊ฒ ์ต๋๋ค.\n AI for Prosthetics Challenge AI for Prosthetics Challenge๋ NeurIPS 2018 Competition Track์ ์ํ ๊ณต์ competition์
๋๋ค. Opensim ์๋ฎฌ๋ ์ดํฐ ํ๊ฒฝ์์ ์งํ๋์๋๋ฐ์, ์ค๋ฅธ์ชฝ ๋ค๋ฆฌ์ ์์กฑ์ ์ฐฉ์ฉํ ์ฌ๋(๊ทธ๋์ ์ด competition์ ์ด๋ฆ์ด Prosthetics์
๋๋ค.)์ ๊ทผ๊ณจ๊ฒฉ ๋ชจ๋ธ์ ๊ฐํํ์ต agent๋ฅผ ํตํด ์ ์ดํ์ฌ ์ฃผ์ด์ง ์๋์ ์ผ์นํ๊ฒ ์ ์ง์ํค๋ ๊ฒ์ด ์ด๋ฒ competition์ ์ฃผ์ ์์ต๋๋ค.\nWorks ์ฐ์ ์์ํ ํ๊ฒฝ์ ๋ถ์ํด์ผ ํ์ต๋๋ค. Opensim ์๋ฎฌ๋ ์ดํฐ ๋ฐ ์ฃผ์ด์ง ๊ฑท๊ธฐ/๋ฌ๋ฆฌ๊ธฐ ์ํ์ค ๋ชจ๋ ์ ํฌ ํ์ด ์๋ ํ๊ณ ์๋ ์
๋ฌด์๋ ์ด๋ ์ ๋ ๊ฑฐ๋ฆฌ๊ฐ ์๋ ์ผ์ด์๊ธฐ ๋๋ฌธ์, ํ๊ฒฝ๊ณผ task์ ๋ํ ๋ถ์์ ๋ง์ ์๊ฐ์ ๋ค์์ต๋๋ค.\n๊ทธ๋ฆฌ๊ณ ์ผ๋ฐ์ ์ธ 3d ๋ชจ๋ธ์ ์ด์ฉํ ๊ฐํํ์ต ํ๊ฒฝ์ฒ๋ผ ์ ์ง, ํ์ง, ํ์ ๋ฑ์ ๋์์ ์ง์ ์ฃผ๋ ๊ฒ์ด ์๋, ๊ฐ ๊ทผ์ฌ์ 1๊ฐ 1๊ฐ๋ฅผ ๋ชจ๋ ๋ฐ๋ก ์ ์ดํด์ผ ํ๊ธฐ ๋๋ฌธ์, ์๋นํ ๋ณต์กํ ํ๊ฒฝ์ด์์ต๋๋ค. ๋ํ, ๊ด์ธกํ ์ ์๋ ๊ฐ๋ค๋ ์๋ฐฑ ๊ฐ ์ด์์ผ๋ก ๋ง์ฐฌ๊ฐ์ง๋ก ๋ณต์กํ์ต๋๋ค. ๊ทธ๋์ ๋น์ฐํ๋ ๋ก์ปฌ๋จธ์ ๋ง์ผ๋ก์ ํ์ต์ ์๊ฐ์ด ๋๋ฌด ์ค๋ ๊ฑธ๋ ธ๊ณ , ํ์ฐ์ ์ผ๋ก ๋ถ์ฐ์ฒ๋ฆฌ๋ฅผ ์ด์ฉํ ๊ฐํํ์ต ๋ฐฉ๋ฒ๋ก ์ ์ฌ์ฉํ ์๋ฐ์ ์์์ต๋๋ค. ๋ํ, ํ์ต์๋๋ฅผ ๋์ด๊ธฐ ์ํด reward shaping, imitation learning ๋ฑ์ ๋ฐฉ๋ฒ์ ์ฌ์ฉํ๊ฒ ๋์์ต๋๋ค.\n๊ฐํํ์ต ๋ฐฉ๋ฒ๋ก ์ competition ๊ธฐ๊ฐ ๋ด๋ด ๊ณ์ํด์ ํ์๊ณผ ๋ณด์์ ๊ฑฐ๋ญํ์์ต๋๋ค. ๋น์ทํ ํ๊ฒฝ์์ ์น๋ฌ์ง NIPS2017 competition solution์ ์ฐธ๊ณ ํ์ฌ ๋ฆฌ์จ์น๋ฅผ ์์ํ์๋๋ฐ, ์ด๋ฒ ํ๊ฒฝ์์ ์ ์ฉ๋์ง ์๋ ๋ถ๋ถ๋ ๋ง์๊ณ , ์๊ฐ์ง๋ ๋ชปํ ๋๊ด์ด ๋ฐ์ํ์ฌ์ ์ฌ๋ฌ ๊ฐ์ง ๊ฐ์ ๋์ ์์ ํํ ์ ์์์ต๋๋ค.\nContents ๋ค์ ๋ด์ฉ์ผ๋ก Posting์ ์งํํ ์์ ์
๋๋ค.\n Opensim Imitation learning Distributed reinforcement learning Agent ","date":1544275337,"expirydate":-62135596800,"kind":"page","lang":"en","lastmod":1544275337,"objectID":"c4b6d3c2a4e95e831295051fbc05cd82","permalink":"/post/2018-12-08-nips2018-intro/","publishdate":"2018-12-08T22:22:17+09:00","relpermalink":"/post/2018-12-08-nips2018-intro/","section":"post","summary":"Introduction to AI for Prosthetics Challenge","tags":[],"title":"[Competition] AI for Prosthetics Challenge - Intro","type":"post"}]