신경망은 컨텐츠 자동생성의 꿈을 꾸는가 딥러닝을 이용한 SRPG 맵 평가 사례 연구 넥슨 신규개발본부 Blast팀 김환희
PCG
• 절차(알고리즘)으로 컨텐츠를 만드는 방법
http://www.gamasutra.com/blogs/AAdonaac/20150903/252889/Procedural_Dungeon_Generation_Algorithm.php
PCG
• 손으로 하나하나 튜닝하는 것에 대비됨
http://boingboing.net/2015/06/16/super-mario-maker-design.htmlhttp://www.howtogeek.com/94977/infinite-mario-is-an-endless-super-mario-3-game-in-your-browser/
http://www.gamasutra.com/blogs/TanyaShort/20140204/209176/Level_Design_in_Procedural_Generation.php
던전
http://florentdeville.com/student-projects/procedural-generation-of-cities/
도시
https://ggtriple.wordpress.com/2014/10/05/top-5-best-orcs-in-middle-earth-shadow-of-mordor/
몬스터
컨텐츠의 의도치 않은 오류
http://pgr21.com/pb/pb.php?id=humor&no=126193http://cdn.tutsplus.com/gamedev/uploads/2014/01/caveat-overlap.gif
컨텐츠의 평가
https://www.reddit.com/r/proceduralgeneration/comments/2q3m5e/procedural_building_generator/
평가 기준 필요, 자동화
신경망
• 전통적인 문제 해결법으로 풀 수 없는 문제들을 풀거나, 성능을 개선하기 위해 사용됨
• 최근 급격한 발전으로 다양한 분야에서 엄청난 성능을 보임 (ex. 알파고)
http://www.33rdsquare.com/2013/06/stanford-researchers-and-google-create.html
https://www.dramafever.com/news/googles-alphago-to-challenge-korean-baduk-champion-lee-sedol-in-the-game-of-go/
AlphaGo
http://www.inferse.com/14173/facebook-reportedly-working-advance-face-recognition-system-deepface/
DeepFace
http://spectrum.ieee.org/computing/embedded-systems/bringing-big-neural-networks-to-selfdriving-cars-smartphones-and-drones
자동 주행 차량
https://i.kinja-img.com/gawker-media/image/upload/dcqehohll3cy5ytjkdvq.jpghttp://www.extremetech.com/computing/174275-google-has-built-a-neural-network-to-identify-100-million-house-numbers-for-streetview
그 밖에도 수많은 실생활 예들
신경망의 구조
• 뉴런 (Neuron)• 신경망의 기본 단위
• 생물체의 신경 세포인 뉴런을 모사
http://www.slideshare.net/jbhuang/lecture-29-convolutional-neural-networks-computer-vision-spring2015
신경망의 구조
• 층 = 레이어 (Layer)• 뉴런을 여러 개 모아놓은 것
• 입력/출력 구조• 입력층과 출력층에 뉴런을 배치
• 입력층에서 받아온 정보를 가공해서 출력층에 전달, 출력
• 원하는 값이 나오도록 신경망을 학습시킴
신경망의 구조
• 입력층과 출력층으로 구성한 AND 게이트
• A = 1, B = 1일 때만 1 x 0.5 + 1 x 0.5 = 1 > 0.5 로 1을 출력
A B
x0.5 x0.5
> 0.5 ? 1 : 0
신경망의 역사
• 1980~ : 다층 신경망으로 XOR 문제 해결, 더 복잡한 문제들에 도전
• ~2006 : 은닉층의 개수를 계속 늘렸지만 학습이 잘 되지 않았음
40
8
□ + 5
입력층
출력층
은닉층□ / 3
□ - 7
http://blog.kodewerx.org/2015/09/its-lovely-day-for-postmortem.html
http://www.techrepublic.com/article/google-deepmind-ai-tries-it-hand-at-creating-hearthstone-magic-the-gathering-cards/
하스스톤 카드 제작
딥네트워크
• Deep = 은닉층을 2개 이상 이용 or 총 레이어 개수 5개 이상
• 많은 수의 Hidden Layer 학습 가능
• Feature Learning
http://www.rsipvision.com/exploring-deep-learning/
https://dnnip.wordpress.com/2013/09/04/convolution-neural-network-for-speech-recognition/
ImageNet 분류를 위한 Deep Convolutional Neural Network
딥네트워크
Feature
• 낮/밤 구별하기
https://www.hackerrank.com/challenges/digital-camera-day-or-night
Feature Extraction
• 전통적 기법
• Corner, Blob, Edge, Line 등
미리 정의된 특징을 추출
http://kr.mathworks.com/products/computer-vision/features.html
http://www.slideshare.net/zukun/eccv2010-feature-learning-for-image-classification-part-0
Feature Extraction전통적 알고리즘
Feature Extraction
전통적 알고리즘의 문제점
1. 전문적 지식 필요
2. 수행에 시간이 오래 걸림
3. 다른 도메인에 일반화하기 힘듦
http://www.slideshare.net/zukun/eccv2010-feature-learning-for-image-classification-part-0
Feature Extraction
http://www.rsipvision.com/wp-content/uploads/2015/04/Slide6.png
• Modern Approach (딥러닝)
• 특징을 찾아낼 수 있도록 학습시킴
Feature Extraction
http://www.rsipvision.com/wp-content/uploads/2015/04/Slide6.png
딥러닝 = 범용적인 문제 해결법
• 어떤 도메인이건 딥 네트워크에 Input을 넣으면 feature learning 후
유의미한 Output이 나옴
딥네트워크Input Output
Feature Extraction
http://www.rsipvision.com/wp-content/uploads/2015/04/Slide6.png
딥러닝 = 범용적인 문제 해결법
• 어떤 도메인이건 딥 네트워크에 Input을 넣으면 feature learning 후
유의미한 Output이 나옴
딥네트워크Input Output
딥네트워크SRPG맵 승률
SRPG
• 전략적인 면이 강조된 (턴제) RPG
• 영걸전, 디스가이아, 창세기전 등
• 맵 형태가 전략성의 핵심
http://www.urbandictionary.com/define.php?term=SRPG
SRPG 맵 평가 - 전통적 알고리즘
• 움직일 수 있는 타일 판단 : DFS
• 병목(choke point) 판단
• 막다른 길(dead end) 판단
• 저격 위치(sniper location) 판단
SRPG 맵 평가
• 전통적 알고리즘으로 하기 힘든 것승률 예측, 유닛 퍼포먼스 – K/D 예측 등
• 보통 수백~수천 번의 시뮬레이션을 돌려서 평균값을 내서 계산
• 시뮬레이션 없이도 평가가 가능할까?
문제 공간
• 20 x 20 타일 맵 (2D)
• 지형은 Grass, Cliff, Water 의 3종
• 유닛은 타워, 보병, 궁병, 기병의 4종
• 1 : 1 PvP• 상대편 타워의 HP를 먼저 0으로 만들면 승리
• 반대의 경우 패배
• 승패 없이 30턴이 지나면 무승부
지형
Grass (+Rock) Cliff Water
이동 가능 이동 불가 이동 불가
- 큰 덩어리 얇게 퍼질 수도 있음
Image Resource from : http://opengameart.org/content/2d-lost-garden-zelda-style-tiles-resized-to-32x32-with-additionshttp://opengameart.org/content/2d-lost-garden-tileset-transition-to-jetrels-wood-tileset
유닛 제원 (Specifications)
보병 궁병 기병 타워
공격력 1 공격력 2 공격력 1 -
이동력 4 이동력 4 이동력 6 -
HP 6 HP 3 HP 4 HP 10
Image Resource from : http://units.wesnoth.org/1.10/mainline/en_US/mainline.htmlhttp://forums.rpgmakerweb.com/index.php?/topic/49063-sythian-bards-world-map-tiles/
유닛 제원 (Specifications)
보병 궁병 기병 타워
-
-
Icon Resource from : http://yanfly.moe/2015/10/23/freebies-mv-ready-ace-icons/
유닛 제원 (Specifications)
보병 궁병 기병 타워
-
-
Icon Resource from : http://yanfly.moe/2015/10/23/freebies-mv-ready-ace-icons/
병종 구성
• Blue : 보병 2, 궁병 2, 기병 1 (화력)
• Red : 보병 2, 궁병 1, 기병 2 (기동성)
• Blue 에 유리한 지형 /
Red 에 유리한 지형 찾기 위해 서로 다름
맵 생성 절차 (Procedures)
1. Poisson Disc Sampling 으로 노드 추출
2. Minimal Spanning Tree 으로 노드 간 간선 추출• 노드의 간선이 하나면 터미널 노드로 지정
3. 지형 배치• 터미널 노드에 장애물(Cliff, Water) 생성
• 가까운 장애물은 Cellular Automata 로 서로 합침
4. 다시 Poisson Disc Sampling 으로 메인 경로 추출
5. 메인 노드 정하고 유닛 배치
http://devmag.org.za/2009/05/03/poisson-disk-sampling/
Poisson Disc Sampling
시뮬레이션
85% 95.6% 71.3% 39.6%
78.6% 80.3% 10.6% 20%
300 Games / 1 Map
1,500,000 Games / 1 Day
Blue 팀의 승률을 계산 (0~100%)
신경망 구축 도구
• 언어 : Python 2.7• 라이브러리 : nolearn ← lasagne ← theano
• IDE : Anaconda2, jupyter Notebook
Tutorial - http://nbviewer.jupyter.org/github/dnouri/nolearn/blob/master/docs/notebooks/CNN_tutorial.ipynb
신경망 구성
• 5 x 20 x 20 Input Layer
• 32 x 18 x 18 Convolutional 2D Layer 1
• 32 x 9 x 9 Max Pooling Layer 1
• 64 x 8 x 8 Convolutional 2D Layer 2
• 64 x 4 x 4 Max Pooling Layer 2
• 256 Dense Layer 1
• 256 Drop Out Layer 1
• 256 Dense Layer 2
• 256 Drop Out Layer 2
• 1 Output Layer
Reference - http://danielnouri.org/notes/2014/12/17/using-convolutional-neural-nets-to-detect-facial-keypoints-tutorial/http://blog.christianperone.com/2015/08/convolutional-neural-networks-and-feature-extraction-with-python/
Image
Conv/Pool
Conv/Pool
Dense
Drop out
Dense
Drop out
Regression
신경망 구성
• Learning parameters = 338,177
Input5x20x20
Conv32x18x18
Pool 32x9x9
Conv 64x8x8
Pool64x4x4
Dense256, 256
Drop out256, 256
Output1
지형 보병 궁병
기병 타워
Input Layer지형과 유닛을 각각의 채널로 분리 (5 channels)
Reference - http://cs231n.stanford.edu/reports/ConvChess.pdf
Input Layer
• 지형 Input Data (0~15번 Map)
• Grass = 0.0 (Black)
Cliff = 1.0 (White)
Water = 0.8
• Cliff 와 Water 는 이동을 막는다는 유사성이 있어서
채널을 분리할 때보다 합칠 때 결과값이 좋았음
Input Layer
• 궁병 Input Data (0~15번 Map)
• Blue team = +1.0 (White)
Red team = -1.0 (Black)
Empty = 0.0
Convolutional 2D Layer
• 32 x 18 x 18 Convolutional 2D Layer 1
• 64 x 8 x 8 Convolutional 2D Layer 2
• 포토샵 등에 있는 이미지 필터
• 경계선 검출 등에 쓰임
http://www.cas.miamioh.edu/~meicenrd/anatomy/ch14_independentinvestigation/imagej/ij-docs/ij-docs/docs/menus/process.html
Convolutional 2D Layer
http://ufldl.stanford.edu/tutorial/supervised/FeatureExtractionUsingConvolution/
• Convolution 연산의 예
1 0 1
0 1 0
1 0 1
필터
Convolutional 2D Layer
• Conv1 : 20 x 20 → 18 x 18 (with 3x3 window)
• Conv2 : 9 x 9 → 8 x 8 (with 2x2 window)
Input Conv1
Convolutional 2D Layer
• Conv1 : 20 x 20 → 18 x 18 (with 3x3 window)
• Conv2 : 9 x 9 → 8 x 8 (with 2x2 window)
Input Conv1
Convolutional 2D Layer
• Conv1 : 20 x 20 → 18 x 18 (with 3x3 window)
• Conv2 : 9 x 9 → 8 x 8 (with 2x2 window)
Input Conv1
Convolutional 2D Layer
http://ufldl.stanford.edu/tutorial/supervised/FeatureExtractionUsingConvolution/
• 여기서는 랜덤하게 생성한 필터를 사용하고,
각 필터와 이미지가 얼마나 유사한지 확인하는 용도
Max Pooling Layer
• 32 x 18 x 18 Convolutional 2D Layer 1
• 32 x 9 x 9 Max Pooling Layer 1
• 64 x 8 x 8 Convolutional 2D Layer 2
• 64 x 4 x 4 Max Pooling Layer 2
• Subsampling 기법
• 인접한 셀은 비슷한 정보를 갖기 때문에 압축으로
효율을 높임
http://ufldl.stanford.edu/tutorial/supervised/Pooling/
Max Pooling Layer
• Pool1 : 18 x 18 → 9 x 9 (with 2x2 window)
• Pool2 : 8 x 8 → 4 x 4 (with 2x2 window)
Conv1 Pool1
Max Pooling Layer
• Pool1 : 18 x 18 → 9 x 9 (with 2x2 window)
• Pool2 : 8 x 8 → 4 x 4 (with 2x2 window)
Conv1 Pool1
Drop Out Layer
• 256 Dense Layer 1
• 256 Drop Out Layer 1
• 256 Dense Layer 2
• 256 Drop Out Layer 2
• Overfitting 을 방지하는 역할
• 일정 확률로 학습을 건너뜀
Drop Out Layer
• 256 Dense Layer 1
• 256 Drop Out Layer 1
• 256 Dense Layer 2
• 256 Drop Out Layer 2
• Overfitting 을 방지하는 역할
• 일정 확률로 학습을 건너뜀
https://www.cs.toronto.edu/~hinton/absps/JMLRdropout.pdf
결과
• N= 115,812; epoch = 200• MSE 0.0191173
• R2 0.75934472914
• Explained variance score 0.761066198349
test
predict