레이블이 jupyter인 게시물을 표시합니다. 모든 게시물 표시
레이블이 jupyter인 게시물을 표시합니다. 모든 게시물 표시

2018년 3월 14일 수요일

ppc64le에서 PyCaffe를 이용한 Image Classification demo

여기서는 caffe가 이미 설치되어 있고, anaconda2도 설치된 상태부터 시작합니다.

[user1@gpusvr ~]$ which python
~/anaconda2/bin/python

먼저, caffe의 source code가 있는 CAFFE_ROOT 디렉토리로 가서 make pycaffe를 수행합니다.

[user1@gpusvr caffe]$ make pycaffe
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
touch python/caffe/proto/__init__.py
PROTOC (python) src/caffe/proto/caffe.proto

이렇게 빌드된 pycaffe는 python/caffe 디렉토리 밑에 다음과 같이 설치됩니다.

[user1@gpusvr caffe]$ ls -l python/caffe
total 2016
-rw-rw-r--. 1 user1 user1   21363 Mar 13 10:50 _caffe.cpp
-rwxrwxr-x. 1 user1 user1 1897912 Mar 14 15:17 _caffe.so
-rw-rw-r--. 1 user1 user1    3546 Mar 13 10:50 classifier.py
-rw-rw-r--. 1 user1 user1    3278 Mar 14 15:53 classifier.pyc
-rw-rw-r--. 1 user1 user1    6721 Mar 13 10:50 coord_map.py
-rw-rw-r--. 1 user1 user1    8549 Mar 13 10:50 detector.py
-rw-rw-r--. 1 user1 user1    7335 Mar 14 15:53 detector.pyc
-rw-rw-r--. 1 user1 user1   11174 Mar 13 10:50 draw.py
drwxrwxr-x. 2 user1 user1      34 Mar 13 10:50 imagenet
-rw-rw-r--. 1 user1 user1     552 Mar 13 10:50 __init__.py
-rw-rw-r--. 1 user1 user1    1206 Mar 14 15:16 __init__.pyc
-rw-rw-r--. 1 user1 user1   13079 Mar 13 10:50 io.py
-rw-rw-r--. 1 user1 user1   13576 Mar 14 15:28 io.pyc
-rw-rw-r--. 1 user1 user1    8277 Mar 13 10:50 net_spec.py
-rw-rw-r--. 1 user1 user1   10008 Mar 14 15:53 net_spec.pyc
drwxrwxr-x. 2 user1 user1      86 Mar 14 15:53 proto
-rw-rw-r--. 1 user1 user1   11615 Mar 13 10:50 pycaffe.py
-rw-rw-r--. 1 user1 user1   12179 Mar 14 15:16 pycaffe.pyc
drwxrwxr-x. 2 user1 user1     256 Mar 13 10:50 test

이걸 다음과 같이 PYTHONPATH로 지정된 ~/anaconda2/lib/python2.7/site-packages 밑으로 copy 합니다.  그냥 현재의 저 python/caffe directory를 PYTHONPATH에 추가하는 방법도 있겠습니다만, 저는 해보니 왜인지는 모르겠으나 자꾸 no module named caffe 라는 error가 나더라구요.

[user1@gpusvr caffe]$ cp -r python/caffe /home/user1/anaconda2/lib/python2.7/site-packages

그리고 libcaffe.so file not found 등의 error를 피하기 위해서 다음과 같이 LD_LIBRARY_PATH를 제대로 지정해줍니다.

[user1@gpusvr caffe]$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/caffe/.build_release/lib:/usr/local/lib:/usr/local/lib64:/usr/lib:/usr/lib64

이제 jupyter notebook을 설치하고, 설정도 해준 뒤 구동합니다.

[user1@gpusvr ~]$ conda install jupyter

[user1@gpusvr ~]$ jupyter notebook --generate-config
Writing default config to: /home/user1/.jupyter/jupyter_notebook_config.py

[user1@gpusvr ~]$ vi /home/user1/.jupyter/jupyter_notebook_config.py
...
#c.NotebookApp.ip = 'localhost'
c.NotebookApp.ip = '*'

[user1@gpusvr ~]$ jupyter notebook &
...
http://localhost:8888/?token=9b9c684173d7883ae7431c02d3e8dfe831cf790322737d16

이제 다른 PC의 laptop의 웹브라우저에서 http://GPU서버주소:8888/?token=9b9c684173d7883ae7431c02d3e8dfe831cf790322737d16 를 입력창에 넣고 접속합니다.



접속해보면 jupyter를 구동한 그 홈디렉토리가 보일 겁니다.  여기서 click-click하여 caffe/examples 디렉토리를 찾아들어간 뒤, 00-classification.ipynb 라는 파일을 클릭합니다.



Jupyter 메뉴바의 play (오른쪽 삼각형) 버튼을 클릭하여 각 섹션을 넘어가다보면 다음처럼 "6. Try your own image"라는 섹션이 나옵니다.  여기서 코드 속의 my_image_url = 오른쪽 부분에 인터넷에서 구글링으로 찾은 적절한 jpg 파일의 URL을 복사해 붙여봅니다.  저는 전함 미주리호의 사진 주소를 붙여보았습니다.

# download an image
my_image_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/9/92/USS_Missouri_HNL.jpg/220px-USS_Missouri_HNL.jpg"  # paste your URL here



Jupyter 메뉴바의 play 버튼을 클릭하면 다음과 같이 49.4%의 확률로 항공모함, 11.7%의 확률로 스페이스 셔틀, 9.2% 확률로 군용 항공기라고 나옵니다.  아마 갑판에서 바라본 포탑과 함교의 모습을 전함으로 인식하지는 못하나봅니다.

[(0.49434182,
  'n02687172 aircraft carrier, carrier, flattop, attack aircraft carrier'),
 (0.11762773, 'n04266014 space shuttle'),
 (0.092569701, 'n04552348 warplane, military plane'),
 (0.081569709, 'n04008634 projectile, missile'),
 (0.078422301,
  'n04389033 tank, army tank, armored combat vehicle, armoured combat vehicle')]



다음과 같이 전체 전함의 모습을 담은 사진을 넣어도 여전히 99.9% 확률로 항공모함이라고 나옵니다.  아마도 ImageNet 2012 training dataset으로 훈련된 이 모델에는 전함과 항공모함을 구별해서 labeling이 되어있지는 않은 모양입니다.



이 데모의 웹 버전은 다음 URL에 준비되어 있으니 언제든 테스트해보실 수 있습니다.

http://demo.caffe.berkeleyvision.org/



2017년 10월 25일 수요일

Minsky에서의 Caffe2 설치 및 jupyter notebook에서 MNIST 돌려보기


PyTorch와 함께 Caffe2를 찾으시는 고객분들도 점점 늘고 계십니다.  PyTorch처럼 Caffe2도 아직 PowerAI 속에 포함되어 있지는 않지만, 그래도 ppc64le 아키텍처에서도 소스에서 빌드하면 잘 됩니다.  현재의 최신 Caffe2 소스코드에서는 딱 한군데, benchmark 관련 모듈에서 error가 나는 부분이 있는데, 거기에 대해서 IBM이 patch를 제공합니다.  아래를 보시고 따라 하시면 됩니다.

먼저, 기본적인 caffe2의 build는 caffe2 홈페이지에 나온 안내(아래 링크)를 그대로 따르시면 됩니다.

https://caffe2.ai/docs/getting-started.html?platform=ubuntu&configuration=compile

저는 아래와 같은 환경에서 빌드했습니다.  CUDA 8.0과 libcuDNN이 설치된 Ubuntu 16.04 ppc64le 환경입니다.   특기할 부분으로는, caffe2는 Anaconda와는 뭔가 맞지 않습니다.  Anaconda가 혹시 설치되어 있다면 관련 PATH를 모두 unset하시고 빌드하시기 바랍니다.

u0017649@sys-89697:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.2 LTS
Release:        16.04
Codename:       xenial

u0017649@sys-89697:~$ dpkg -l | grep cuda | head -n 4
ii  cuda                                                     8.0.61-1                                   ppc64el      CUDA meta-package
ii  cuda-8-0                                                 8.0.61-1                                   ppc64el      CUDA 8.0 meta-package
ii  cuda-command-line-tools-8-0                              8.0.61-1                                   ppc64el      CUDA command-line tools
ii  cuda-core-8-0                                            8.0.61-1                                   ppc64el      CUDA core tools

u0017649@sys-89697:~$ dpkg -l | grep libcudnn
ii  libcudnn6                                                6.0.21-1+cuda8.0                           ppc64el      cuDNN runtime libraries
ii  libcudnn6-dev                                            6.0.21-1+cuda8.0                           ppc64el      cuDNN development libraries and headers

위에서 언급한 대로, python이든 pip든 모두 Anaconda가 아닌, OS에서 제공하는 것을 사용하십시요.  여기서는 python 2.7을 썼습니다.

u0017649@sys-89697:~$ which python
/usr/bin/python


먼저, 기본적으로 아래의 Ubuntu OS package들을 설치하십시요.

u0017649@sys-89697:~$ sudo apt-get install -y --no-install-recommends build-essential cmake git libgoogle-glog-dev libprotobuf-dev protobuf-compiler

u0017649@sys-89697:~$ sudo apt-get install -y --no-install-recommends libgtest-dev libiomp-dev libleveldb-dev liblmdb-dev libopencv-dev libopenmpi-dev libsnappy-dev openmpi-bin openmpi-doc  python-pydot libgflags-dev

그리고 PowerAI에서 제공하는 openblas와 nccl도 설치하십시요.

u0017649@sys-89697:~$ sudo dpkg -i mldl-repo-local_4.0.0_ppc64el.deb

u0017649@sys-89697:~$ sudo apt-get update

u0017649@sys-89697:~$ sudo apt-get install libnccl-dev
u0017649@sys-89697:~$ sudo apt-get install libopenblas-dev libopenblas

그리고 아래의 pip package들을 설치하십시요.

u0017649@sys-89697:~$ pip install flask future graphviz hypothesis jupyter matplotlib pydot python-nvd3 pyyaml requests scikit-image scipy setuptools six tornado protobuf

이제 caffe2의 source를 download 받습니다.

u0017649@sys-89697:~$ git clone --recursive https://github.com/caffe2/caffe2.git
Cloning into 'caffe2'...
remote: Counting objects: 36833, done.
remote: Compressing objects: 100% (64/64), done.
remote: Total 36833 (delta 37), reused 34 (delta 12), pack-reused 36757
Receiving objects: 100% (36833/36833), 149.17 MiB | 11.42 MiB/s, done.
Resolving deltas: 100% (26960/26960), done.
Checking connectivity... done.
Submodule 'third_party/NNPACK' (https://github.com/Maratyszcza/NNPACK.git) registered for path 'third_party/NNPACK'
Submodule 'third_party/NNPACK_deps/FP16' (https://github.com/Maratyszcza/FP16.git) registered for path 'third_party/NNPACK_deps/FP16'
...
remote: Counting objects: 353, done.
remote: Total 353 (delta 0), reused 0 (delta 0), pack-reused 353
Receiving objects: 100% (353/353), 119.74 KiB | 0 bytes/s, done.
Resolving deltas: 100% (149/149), done.
Checking connectivity... done.
Submodule path 'third_party/pybind11/tools/clang': checked out '254c7a91e3c6aa254e113197604dafb443f4d429'

이제 ppc64le를 위한 source 수정을 하나 하겠습니다.  Patch가 필요한 부분은 주요 부분은 아니고, 벤치마크를 위한 third party 모듈 중 하나입니다.

u0017649@sys-89697:~$ cd caffe2/third_party/benchmark/src

u0017649@sys-89697:~/caffe2/third_party/benchmark/src$ vi cycleclock.h
...
#elif defined(__powerpc__) || defined(__ppc__)
  // This returns a time-base, which is not always precisely a cycle-count.
  int64_t tbl, tbu0, tbu1;
  asm("mftbu %0" : "=r"(tbu0));
  asm("mftb  %0" : "=r"(tbl));
  asm("mftbu %0" : "=r"(tbu1));
  tbl &= -static_cast<long long>(tbu0 == tbu1);
//  tbl &= -static_cast<int64_t>(tbu0 == tbu1);

수정의 핵심은 저 int64 대신 long long을 넣는 것입니다.

** 그 사이에 하나 더 늘었네요.  아래와 같이 third_party/NNPACK/CMakeLists.txt의 30번째 줄에 ppc64le를 넣어줍니다.

u0017649@sys-89697:~/caffe2/build# vi ../third_party/NNPACK/CMakeLists.txt
...
ELSEIF(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(i686|x86_64|armv5te|armv7-a|armv7l|aarch64|ppc64le)$")
  MESSAGE(FATAL_ERROR "Unrecognized CMAKE_SYSTEM_PROCESSOR = ${CMAKE_SYSTEM_PROCESSOR}")
...

그 다음으로는 나중에 cblas 관련 error를 없애기 위해, 아래와 같이 Dependencies.cmake 파일에서 cblas 관련 1줄을 comment-out 시킵니다.

u0017649@sys-89697:~/caffe2/cmake$ vi Dependencies.cmake
...
elseif(BLAS STREQUAL "OpenBLAS")
  find_package(OpenBLAS REQUIRED)
  caffe2_include_directories(${OpenBLAS_INCLUDE_DIR})
  list(APPEND Caffe2_DEPENDENCY_LIBS ${OpenBLAS_LIB})
#  list(APPEND Caffe2_DEPENDENCY_LIBS cblas)
...

그리고 OpenBLAS_HOME을 아래와 같이 PowerAI에서 제공하는 openblas로 설정합니다.

u0017649@sys-89697:~/caffe2/cmake$ export OpenBLAS_HOME=/opt/DL/openblas/

또 하나 고칩니다.  FindNCCL.cmake에서 아래 부분을 PowerAI의 NCCL directory로 명기하면 됩니다.

root@26aa285b6c46:/data/imsi/caffe2/cmake# vi Modules/FindNCCL.cmake
...
#set(NCCL_ROOT_DIR "" CACHE PATH "Folder contains NVIDIA NCCL")
set(NCCL_ROOT_DIR "/opt/DL/nccl" CACHE PATH "Folder contains NVIDIA NCCL")
...

이제 cmake 이후 make를 돌리면 됩니다.  단, default인 /usr/local이 아닌, /opt/caffe2에 caffe2 binary가 설치되도록 CMAKE_INSTALL_PREFIX 옵션을 줍니다.

u0017649@sys-89697:~$ cd caffe2
u0017649@sys-89697:~/caffe2$ mkdir build
u0017649@sys-89697:~/caffe2$ cd build

u0017649@sys-89697:~/caffe2/build$ cmake -DCMAKE_INSTALL_PREFIX=/opt/caffe2 ..

u0017649@sys-89697:~/caffe2/build$ make

약 1시간 넘게 꽤 긴 시간이 걸린 뒤에 make가 완료됩니다.  이제 make install을 하면 /opt/caffe2 밑으로 binary들이 설치됩니다.

u0017649@sys-89697:~/caffe2/build$ sudo make install

u0017649@sys-89697:~/caffe2/build$ ls -l /opt/caffe2
total 28
drwxr-xr-x  2 root root 4096 Oct 25 03:16 bin
drwxr-xr-x  3 root root 4096 Oct 25 03:16 caffe
drwxr-xr-x 24 root root 4096 Oct 25 03:16 caffe2
drwxr-xr-x  4 root root 4096 Oct 25 03:16 include
drwxr-xr-x  2 root root 4096 Oct 25 03:16 lib
drwxr-xr-x  3 root root 4096 Oct 25 03:16 share
drwxr-xr-x  2 root root 4096 Oct 25 03:16 test

다른 일반 user들도 사용할 수 있도록 필요에 따라 /opt/caffe2의 ownership을 바꿔줍니다.  (optional)

u0017649@sys-89697:~/caffe2/build$ sudo chown -R u0017649:u0017649 /opt/caffe2

이제 테스트를 해봅니다.  먼저, PYTHONPATH를 설정해줍니다.

u0017649@sys-89697:~/caffe2/build$ export PYTHONPATH=/opt/caffe2

다음과 같이 기본 테스트를 2가지 해봅니다.  먼저 import core를 해봅니다. 

u0017649@sys-89697:~/caffe2/build$ python -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure"
Success

다음으로는 operator_test.relu_op_test를 수행해봅니다.   제가 가진 환경은 GPU가 안 달린 환경이라서 아래 붉은색의 warning이 있습니다만, 여기서는 무시하십시요.

u0017649@sys-89697:~/caffe2/build$ pip install hypothesis

u0017649@sys-89697:~$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/caffe2/lib

u0017649@sys-89697:~$ python -m caffe2.python.operator_test.relu_op_test
NVIDIA: no NVIDIA devices found
WARNING: Logging before InitGoogleLogging() is written to STDERR
E1025 05:09:33.528787 12222 common_gpu.cc:70] Found an unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. I will set the available devices to be zero.
Trying example: test_relu(self=<__main__.TestRelu testMethod=test_relu>, X=array([ 0.], dtype=float32), gc=, dc=[], engine=u'')
Trying example: test_relu(self=<__main__.TestRelu testMethod=test_relu>, X=array([[[-0.03770517, -0.03770517, -0.03770517, -0.03770517],
        [-0.03770517, -0.03770517, -0.03770517, -0.03770517],
        [-0.03770517, -0.03770517, -0.03770517, -0.03770517]],
...
        [ 0.96481699,  0.96481699,  0.96481699,  0.96481699],
        [ 0.96481699,  0.96481699,  0.96481699, -0.74859387]]], dtype=float32), gc=, dc=[], engine=u'')
Trying example: test_relu(self=<__main__.TestRelu testMethod=test_relu>, X=array([ 0.61015409], dtype=float32), gc=, dc=[], engine=u'CUDNN')
.
----------------------------------------------------------------------
Ran 1 test in 0.957s

OK

테스트도 정상적으로 완료되었습니다.   이제 jupyter notebook에서 MNIST를 수행해보시지요.

먼저 jupyter notebook을 외부 browser에서 접속할 수 있도록 config를 수정합니다.

u0017649@sys-89697:~$  jupyter notebook --generate-config
Writing default config to: /home/u0017649/.jupyter/jupyter_notebook_config.py

u0017649@sys-89697:~$ vi /home/u0017649/.jupyter/jupyter_notebook_config.py
...
#c.NotebookApp.ip = 'localhost'
c.NotebookApp.ip = '*'

jupyter notebook을 kill 했다가 다시 띄웁니다.   이제 아래 붉은색처럼 token이 display 됩니다.

u0017649@sys-89697:~$ jupyter notebook &

[I 05:13:29.492 NotebookApp] Writing notebook server cookie secret to /home/u0017649/.local/share/jupyter/runtime/notebook_cookie_secret
[W 05:13:29.578 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 05:13:29.665 NotebookApp] Serving notebooks from local directory: /home/u0017649
[I 05:13:29.666 NotebookApp] 0 active kernels
[I 05:13:29.666 NotebookApp] The Jupyter Notebook is running at: http://[all ip addresses on your system]:8888/?token=ca44acc48f0f2daa6dc9d935904f1de9a1496546efc95768
[I 05:13:29.666 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 05:13:29.667 NotebookApp] No web browser found: could not locate runnable browser.
[C 05:13:29.667 NotebookApp]

    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://localhost:8888/?token=ca44acc48f0f2daa6dc9d935904f1de9a1496546efc95768

이 token을 복사해서 외부의 browser에서 입력하면 됩니다.  여기서 사용된 서버의 ip가 172.29.160.94이므로, 먼저 browser에서 http://172.29.160.94:8888의 주소를 찾아들어갑니다.



접속이 완료되면 다시 명령어 창에서 아래의 MNIST python notebook을 download 받습니다.

u0017649@sys-89697:~$ wget https://raw.githubusercontent.com/caffe2/caffe2/master/caffe2/python/tutorials/MNIST.ipynb


이 MNIST.ipynb이 jupyter 화면에 뜨면, 그걸 클릭합니다.




이제 문단 하나하나씩 play button을 누르면서 진행해보실 수 있습니다.







2017년 8월 2일 수요일

Minsky 서버에서의 jupyter notebook 설치/사용

Minsky 등 ppc64le 환경에서도 당연히 jupyter notebook 사용이 가능합니다.    Miniconda를 이용하여 간단히 설치가 가능한데, Miniconda 자체의 설치에 대해서는 여기를 클릭하세요.

일단 Miniconda가 설치되어 conda를 쓸 수 있게 되면 아래와 같이 하면 됩니다.

mirhenge@powerai:~/miniconda2$ conda install jupyter
Fetching package metadata .........
Solving package specifications: .

Package plan for installation in environment /home/mirhenge/miniconda2:

The following NEW packages will be INSTALLED:

    backports:          1.0-py27_0
    backports_abc:      0.5-py27_0
    bleach:             1.5.0-py27_0
    configparser:       3.5.0-py27_0
    decorator:          4.0.11-py27_0
    entrypoints:        0.2.2-py27_1
    functools32:        3.2.3.2-py27_0
    get_terminal_size:  1.0.0-py27_0
    html5lib:           0.999-py27_0
    ipykernel:          4.6.1-py27_0
    ipython:            5.3.0-py27_0
    ipython_genutils:   0.2.0-py27_0
    ipywidgets:         6.0.0-py27_0
    jinja2:             2.9.6-py27_0
    jsonschema:         2.6.0-py27_0
    jupyter:            1.0.0-py27_3
    jupyter_client:     5.0.1-py27_0
    jupyter_console:    5.1.0-py27_0
    jupyter_core:       4.3.0-py27_0
    libsodium:          1.0.10-0
    markupsafe:         0.23-py27_2
    mistune:            0.7.4-py27_0
    nbconvert:          5.1.1-py27_0
    nbformat:           4.3.0-py27_0
    notebook:           5.0.0-py27_0
    pandocfilters:      1.4.1-py27_0
    path.py:            10.3.1-py27_0
    pathlib2:           2.2.1-py27_0
    pexpect:            4.2.1-py27_0
    pickleshare:        0.7.4-py27_0
    prompt_toolkit:     1.0.14-py27_0
    ptyprocess:         0.5.1-py27_0
    pygments:           2.2.0-py27_0
    python-dateutil:    2.6.0-py27_0
    pyzmq:              16.0.2-py27_0
    scandir:            1.5-py27_0
    simplegeneric:      0.8.1-py27_1
    singledispatch:     3.4.0.3-py27_0
    ssl_match_hostname: 3.4.0.2-py27_1
    terminado:          0.6-py27_0
    testpath:           0.3-py27_0
    tornado:            4.5.1-py27_0
    traitlets:          4.3.2-py27_0
    wcwidth:            0.1.7-py27_0
    widgetsnbextension: 2.0.0-py27_0
    zeromq:             4.1.5-0

The following packages will be UPDATED:

    conda:              4.3.14-py27_0  --> 4.3.21-py27_0

Proceed ([y]/n)? y
...
entrypoints-0. 100% |#########################################| Time: 0:00:00  15.14 MB/s
jupyter_core-4 100% |#########################################| Time: 0:00:00 304.20 kB/s
pickleshare-0. 100% |#########################################| Time: 0:00:00  23.47 MB/s
testpath-0.3-p 100% |#########################################| Time: 0:00:00  35.33 MB/s
tornado-4.5.1- 100% |#########################################| Time: 0:00:00 613.23 kB/s
ipython-5.3.0- 100% |#########################################| Time: 0:00:01 851.46 kB/s
jupyter_client 100% |#########################################| Time: 0:00:00 329.04 kB/s
nbformat-4.3.0 100% |#########################################| Time: 0:00:00 360.09 kB/s
terminado-0.6- 100% |#########################################| Time: 0:00:00  20.31 MB/s
conda-4.3.21-p 100% |#########################################| Time: 0:00:01 503.31 kB/s
ipykernel-4.6. 100% |#########################################| Time: 0:00:00 249.29 kB/s
nbconvert-5.1. 100% |#########################################| Time: 0:00:00 465.37 kB/s
jupyter_consol 100% |#########################################| Time: 0:00:00  39.17 MB/s
notebook-5.0.0 100% |#########################################| Time: 0:00:02   2.07 MB/s
widgetsnbexten 100% |#########################################| Time: 0:00:01 762.68 kB/s
ipywidgets-6.0 100% |#########################################| Time: 0:00:00 167.32 kB/s
jupyter-1.0.0- 100% |#########################################| Time: 0:00:00  11.56 MB/s


이제 다시 login을 하든가 ~/.bashrc를 새로 수행하면 PATH 환경변수가 잡히면서 jupyter 사용이 가능합니다.

mirhenge@powerai:~/miniconda2$ which jupyter
/home/mirhenge/miniconda2/bin/jupyter

Web browser로는 firefox를 사용하시면 됩니다.   여기서는 X 환경을 위해 tightvncviewer를 이용하므로 DISPLAY를 unix:0으로 설정합니다.

mirhenge@powerai:~/miniconda2$ export BROWSER=/usr/bin/firefox
mirhenge@powerai:~/miniconda2$ export DISPLAY=unix:0

이제 jupyter notebook를 구동하면 다음과 같은 메시지가 나옵니다.

mirhenge@powerai:~/miniconda2$ jupyter notebook
[I 13:40:32.487 NotebookApp] Serving notebooks from local directory: /home/mirhenge/miniconda2
[I 13:40:32.488 NotebookApp] 0 active kernels
[I 13:40:32.488 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/?token=9d13bb86a1a68d0c408740c877045adb2278535287737f5f
[I 13:40:32.488 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 13:40:32.488 NotebookApp]

    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://localhost:8888/?token=9d13bb86a1a68d0c408740c877045adb2278535287737f5f
[I 13:40:35.286 NotebookApp] Accepting one-time-token-authenticated connection from 127.0.0.1

이때 tightvncserver를 설정해 놓았다면 그 화면을 통해 vncviewer에서 browser가 열립니다.




이후로는 vncviewer를 통하지 않고도 remote에서도 web browser를 이용해 접속할 수 있도록 아래와 같이 설정 파일을 생성하고 이어서 수정해줍니다.

mirhenge@powerai:~$ jupyter notebook --generate-config

mirhenge@powerai:~$ vi /home/mirhenge/.jupyter/jupyter_notebook_config.py
...
## The IP address the notebook server will listen on.
#c.NotebookApp.ip = 'localhost'
c.NotebookApp.ip = '*'


이제 다시 start해주면 굳이 local server에서 띄운 browser 뿐만 아니라 외부 PC에서 띄운 browser로도 접속이 가능합니다.

mirhenge@powerai:~$ jupyter notebook
[W 13:57:17.150 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 13:57:17.158 NotebookApp] Serving notebooks from local directory: /home/mirhenge
[I 13:57:17.158 NotebookApp] 0 active kernels
[I 13:57:17.158 NotebookApp] The Jupyter Notebook is running at: http://[all ip addresses on your system]:8888/?token=acde16ba9020fd7cc174d894f760772af7257c619579519d
[I 13:57:17.158 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 13:57:17.159 NotebookApp]

    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://localhost:8888/?token=acde16ba9020fd7cc174d894f760772af7257c619579519d
[I 13:57:18.245 NotebookApp] Accepting one-time-token-authenticated connection from 127.0.0.1
[I 13:57:32.011 NotebookApp] 302 GET / (211.109.178.33) 0.33ms
[I 13:57:32.165 NotebookApp] 302 GET /tree? (211.109.178.33) 0.54ms


이때 처음 접속할 때는 위에 display된 token(위의 붉은색 부분)을 copy & paste 해서 넣어야 합니다.







한번 테스트를 해봅니다.   다음과 같이 IBM lab service에서 만든 demo용 English --> French 번역 deep learning용 package를 다운로드 받습니다.

mirhenge@powerai:~$ git clone https://github.com/ppradhan01/dl-language-translation.git
Cloning into 'dl-language-translation'...
remote: Counting objects: 13, done.
remote: Total 13 (delta 0), reused 0 (delta 0), pack-reused 13
Unpacking objects: 100% (13/13), done.
Checking connectivity... done.


mirhenge@powerai:~$ cd dl-language-translation/
mirhenge@powerai:~/dl-language-translation$ ls
code.ipynb  data  helper.py  problem_unittests.py  README.md

mirhenge@powerai:~/dl-language-translation$ cd data

mirhenge@powerai:~/dl-language-translation/data$ ls
small_vocab_en  small_vocab_fr

mirhenge@powerai:~/dl-language-translation/data$ head small_vocab_en
new jersey is sometimes quiet during autumn , and it is snowy in april .
the united states is usually chilly during july , and it is usually freezing in november .
california is usually quiet during march , and it is usually hot in june .
the united states is sometimes mild during june , and it is cold in september .
your least liked fruit is the grape , but my least liked is the apple .
his favorite fruit is the orange , but my favorite is the grape .
paris is relaxing during december , but it is usually chilly in july .
new jersey is busy during spring , and it is never hot in march .
our least liked fruit is the lemon , but my least liked is the grape .
the united states is sometimes busy during january , and it is sometimes warm in november .

mirhenge@powerai:~/dl-language-translation/data$ head small_vocab_fr
new jersey est parfois calme pendant l' automne , et il est neigeux en avril .
les états-unis est généralement froid en juillet , et il gèle habituellement en novembre .
california est généralement calme en mars , et il est généralement chaud en juin .
les états-unis est parfois légère en juin , et il fait froid en septembre .
votre moins aimé fruit est le raisin , mais mon moins aimé est la pomme .
son fruit préféré est l'orange , mais mon préféré est le raisin .
paris est relaxant en décembre , mais il est généralement froid en juillet .
new jersey est occupé au printemps , et il est jamais chaude en mars .
notre fruit est moins aimé le citron , mais mon moins aimé est le raisin .
les états-unis est parfois occupé en janvier , et il est parfois chaud en novembre .


이제 browser의 notebook에서, 위에서 download 받은 dl-language-translation directory로 찾아내려가 code.ipynb를 클릭하면 됩니다.




그러면 이제 notebook이 열리고, 필요시 위쪽 메뉴 bar에 있는 play 버튼 (player의 삼각형 버튼)을 눌러서 해당 code 부분을 직접 수행해볼 수도 있습니다.