반응형

Hyperparameters in Deep RL with Optuna


Hyperparameters in Deep RL with Optuna

[1편 문제: Hyper-parameters]

[2편 해결: Bayesian Search]

[3편: Hyper-parameter Search with Optuna]

총 3편으로 나눠서 Deep Reinforcement Learning에서의 Hyperparameter 의 중요성과

다양한 Hyperparameter를 선택하는 Search 방법을 소개하고

Optuna 사용 방법을 익혀보겠습니다.


[1] 개요: Hyper-parameters in Deep RL

  • Build a perfect agent to solve the Cart Pole environment using Deep Q
  • set of hyperparameters used
  • to become a real PRO in Reinforcement Learning
  • need to learn how to tune hyperparameters
  • with using the right tools
  • Optuna : open-source library for hyperparameters search in the Python ecosystem

[2] 문제: Hyper-parameters

Machine Learning models

1. parameters

  • numbers found AFTER training your model

2. hyperparameters

  • numbers need to set BEFORE training the model
  • exists all around ML

ex. learning rate in supervised machine learning problems

  • too low number stuck in local minima
  • too large number oscillate too much and never converge to the optimal parameters
  • Deep RL is even more challenging.

  • Deep RL problem
    • have more hyperparameters than supervised ML models
    • hyperparameters in Deep RL have a huge impact on the final training outcome

How can we find the good hyperparameters?

  • to find good hyperparameters we follow trial-and-error approach
  1. choose a set of hyperparameters
  2. train the agent
  3. evaluate the agent
  4. if we are happy with the result, we are done.
    Otherwise, we choose a new set of hp and repeat the whole process.

find good hyperparameters we follow trial-and-error approach


[3] Grid Search

  • trying all possible combinations and select the one that works best.
  • method called grid search
  • works well for many supervised ML problems
grid search

[4] Grid Search Problem

  • Deep RL problems
    • many more hyperparameters (e.g 10-20)
    • each can take many possible values
    • it creates massive grid in which to search the best combinatio
      • number of combinations grows exponentially
        • ex. 10개 hyperparameter, 1~10까지 가능하다면? grid size = 10,000,000,000
        • 한 번의 training loop이 10분이 걸린다고 해도? 10분 X 10,000,000,000 = 190,258년
        • 현실적으로 불가능!
        • 100,000개의 병렬 프로세스로 돌린다고 해도 2년..
    • 따라서 Grid search는 Deep RL 문제 풀이에는 매우 비효율적인 방법

[5] Random Search

  • instead of checking each of the 𝑁 possible hyperparameter combinations
  • randomly try a subset of them with size 𝑇
    • 𝑇 is much smaller than 𝑁
  • also train and evaluate the agent 𝑇 times

 

  • with this 𝑇 trials
    • we select the combination of hyperparameters that worked best
  • more efficient way to search and works better than Grid Search
    • speed and quality of the solution
    • but it is just spinning a roulette to decide hyperparameter
    • something more smart way needed.
반응형
반응형

동일경로

import하고자 하는 모듈이 작업하는 공간과 동일한 폴더에 있는 경우

현재 경로를 의미하는 . 을 사용하여 import

from . import want_to_import

하위경로

import 하고자 하는 모듈 혹은 파일이 작업 중인 파일 공간과 같은 위치에 있는 폴더 안에 있을 경우

from [하위폴더]를 지정하여 import

from [하위폴더] import want_to_impot

상위경로

import하고자 하는 모듈 혹은 파일이 저장된 폴더가 

작업 중인 파일의 상위 폴더에 위치해 있을 때

import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
from [상위폴더에_존재하는_폴더] import want_to_import
# 상위 폴더에 모듈이 존재할 경우 from . import want_to_import

위의 코드에서 

(os.path.dirname(os.path.abspath

는 한 단계 상위를 의미함

두 단계 상위 폴더라면 아래와 같이 두 번 작성 해주어야 한다

(os.path.dirname(os.path.abspath(os.path.dirname(os.path.abspath

절대경로

절대경로를 이용해 import하려면 아래와 같이 sys.path.append를 이용한다

import sys
sys.path.append([파일이_저장된_구체적_경로])

from . import want_to_import

예제

optuna 이용시 상위경로의 src폴더 의 config.py 파일 접근하여 OPTUNA_DB import 사용

반응형
반응형

가상환경 만들기

conda create -n {envname}

-n 옵션은 가상환경의 이름 설정 

 

다음의 명령어로 지금 실행하고자 하는 conda가 어느 경로에 있는 conda인지 확인

which conda

 

가상환경 목록 확인하기

만들어진 가상환경을 확인

기본 환경인 경우 (base)로 표시 됨

conda env list

현재 활성화된 가상환경에 대한 더 자세한 정보를 알아보고자 하면 다음의 명령어 입력

conda info

가상환경 들어가기 activate

conda activate {envname}
source activate {envname}

들어간 가상 환경의 설치된 패키지 list 확인은 다음의 명령어들 이용

conda list
pip list

가상환경 나오기 deactivate

source deactivate

필요없는 가상환경 삭제하기

conda env remove -n {envname}

-all 옵션을 주면 가상환경 아래 깔린 모든 라이브러리 삭제 가능 {envname} 뒤에 붙이기

가상환경 복제하여 이름 변경하기

conda create -n {새로운 envname} --clone {기존 envname}

가상환경 패키지 목록 관리하기

가상환경에 설치된 패키지는 목록을 저장해두었다가 다시 설치 가능

pip freeze로 패키지 목록과 버전 정보 txt파일에 저장

pip freeze > requirements.txt

pip install 에서 -r 혹은 --requirement 옵션을 활용하여 txt파일 내용대로 패키지를 설치합니다.

pip install -r requirements.txt

 

Conda 환경 복사하기

1. Requirements.txt 생성

conda env export > conda_requirements.yaml

2. Requirements.txt와 동일한 환경 설치

conda env create -f conda_requirements.yaml

 

파이썬 버전 변경하기

사용 가능한 python 리스트 확인

conda search python

입력하는 버전으로 파이썬 버전 변경 

conda install python=x.x.x
 
 
반응형

'스스로 학습 > terminal' 카테고리의 다른 글

conda install pytest, stable-baselines3  (0) 2024.04.29
#include <unistd.h> 로 read() 읽고, write() 쓰기  (0) 2022.01.02
vim 명령어 모음  (0) 2022.01.02
반응형

파이썬 다른 버전으로 preference에서 변경하고 

pyqt5 install 하니 성공!

qimage2ndarray도 install 해야함

반응형

'강의 > 멀티미디어처리' 카테고리의 다른 글

3주차 - 멀티미디어처리기술 실습  (0) 2022.03.18

+ Recent posts