[Deep learning] Gradient Descent Optimizer

이미지
https://icim.nims.re.kr/post/easyMath/70 알기 쉬운 산업수학 알기 쉬운 산업수학 Gradient Descent Optimizer 2017년 12월 13일(수) | 김민중 URL  (1) 주어진 목적함수  f f 의 최솟값(minimum)을 찾아가는 알고리즘으로 다음과 같은 방식으로 최솟값을 찾아간다. 초기값  x 0 x 0 을 임의로 설정, 적당한 Learning rate  α α  설정 n ≥ 0 n ≥ 0 인 정수에 대해서  x n + 1 x n + 1 은 다음과 같이 정의한다. x n + 1 : = x n − α ⋅ ∇ f ( x n ) x n + 1 := x n − α ⋅ ∇ f ( x n ) 주의사항 함수 f f 의 모양이 convex가 아닌 경우 global minimum이 아닌 local minimum으로  x n x n 이 수렴할 가능성이 있다. Learning rate  α α  값이 큰 경우 최솟값으로  x n x n 이 수렴하는 것이 아니라 발산할 수 있다. Learning rate  α α  값이 작은 경우 수렴하는 속도가 지나치게 느릴 수 있다. 방정식  2 ⋅ x = 10 2 ⋅ x = 10  의 근을 Gradient Descent를 이용해서 찾아보자. 목적함수  f ( x ) : = ( 10 − 2 x ) 2 f ( x ) := ( 10 − 2 x ) 2 으로 설정하겠다( f f 의 최솟값인 0이 되게 하는  x x 값이 우리가 원하는 방정식의 근이다). 초기값  x 0 = 0 x 0 = 0 , Learning rate  α = 0.05 α = 0.05 으로 설정 f ′ ( x ) = 4 ( 2 x − 10 ) f ′ ( x ) = 4 ( 2 x − 10 )...

Install opencv with GPU option and python

The rest of this blog post will assume that you have already installed CUDA Toolkit and cuDNN.


1. Install OpenCV prerequisites


Keep up  to date packages
$ sudo apt-get update
$ sudo apt-get upgrade

Install the required developer tools and packages
$ sudo apt-get install build-essential cmake pkg-config

Install the image packages. Theses packages allow you to load various image file format such as JPEG, PNG, TIFF, etc
$ sudo apt-get install libjpeg8-dev libtiff5-dev libjasper-dev libpng12-dev

Install GTK development library to build Graphical User Interfaces and OpenCV's highgui which allow you to view images on your screen.
$ sudo apt-get install libgtk2.0-dev

Install the necessary video I/O packages to load video files using OpenCV
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev

Install additional libraries.
$ sudo apt-get install libatlas-base-dev gfortran



2. Not must be installed but will be helpful library.


Install 
$ sudo apt-get install python-opencv

$ sudo apt-get install libboost-all-dev


3. Install pip, virtualenv , virtualenvwrapper for separate python environments


$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python get-pip.py
$ sudo pip install virtualenv virtualenvwrapper
$ sudo rm -rf get-pip.py ~/.cache/pip


4. Update .bashrc file


# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh


5. Make workplace with virtual environment


$ source ~/.bashrc
$ mkvirtualenv deepLab ( deepLab is name , it means you can name it , after this command run prompt of terminal will change. )
$ workon deepLab
$ sudo apt-get install python2.7-dev
If you want to use python3
$ sudo apt-get install python3.5-dev
$ pip install numpy

And update .bashrc file

$ nano ~/.bashrc
Add following line

export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH

$ source ~/.bashrc


<Tip>
 To remove virtualenv :          $ rmvirtualenv deepLab
 To exit current vitualenv :     $ deactivate

6. Download , extract and compile OpenCV ( Note :  -D WITH_CUDA=OFF )


$ wget -O opencv-2.4.10.zip http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.10/opencv-2.4.10.zip/download
$ unzip opencv-2.4.10.zip
$ cd opencv-2.4.10
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D WITH_CUDA=OFF \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_EXAMPLES=ON ..
$ make -j8
$ sudo make install
$ sudo ldconfig
$ cd ~
$ rm -rf opencv-2.4.10 opencv-2.4.10.zip


<Note>
After build process is completed, you must check 'Interpreter' , 'Libraries', 'numpy', and 'packages path' have all been correctly set.

<Note>
make -jN ( N is cpu core count ,  $ cat /proc/cpuinfo | grep cores | wc -l )

7. Make sym-link for deep learning dev environment


$ cd ~/.virtualenvs/deepLab/lib/python2.7/site-packages/
$ ln -s /usr/local/lib/python2.7/site-packages/cv2.so cv2.so
$ ln -s /usr/local/lib/python2.7/site-packages/cv.py cv.py


8. Test your install


$ cd ~
$ workon deepLab
$ python
>>> import cv2
>>> cv2.__version__


and you can see the output with version number. ( ex> '2.4.10' )




댓글

이 블로그의 인기 게시물

@import' when modules are disabled

MagicaVoxel black screen

[Anaconda][Opencv][Spyder] How to install opencv to anaconda (spyder).