using reticulate with plaidML

Published by onesixx on

https://onesixx.com/reticulate/

Install reticulate package

install.packages('reticulate')
library(reticulate)

Install miniconda

install_miniconda()

정보확인

default path는 ~/Library/r-miniconda
default env는 ~/Library/r-miniconda/envs/r-reticulate
phython은 default env내에 ~/Library/r-miniconda/envs/r-reticulate/bin/python

# 설치된 miniconda 정보
conda_version()
#[1] "conda 4.8.5"
miniconda_path()                        # minicoda의 default path
#[1] "/Users/onesixx/Library/r-miniconda"
conda_binary()
#[1] "/Users/onesixx/Library/r-miniconda/bin/conda"
conda_python()
#[1] "/Users/onesixx/Library/r-miniconda/envs/r-reticulate/bin/python"

miniconda 설정

conda init 은 ~/.bashrc 에 아래 내용을 추가

$➜ cd /Users/onesixx/.local/share/r-miniconda/bin
$➜ ./conda init zsh

Terminal을 restart하고, 가상환경을 활성화해서 잘 적용됐는지 확인

$➜ source ~/.bashrc
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/oschung_skcc/.local/share/r-miniconda/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/oschung_skcc/.local/share/r-miniconda/etc/profile.d/conda.sh" ]; then
        . "/home/oschung_skcc/.local/share/r-miniconda/etc/profile.d/conda.sh"
    else
        export PATH="/home/oschung_skcc/.local/share/r-miniconda/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

설치된 miniconda update

# 설치된 miniconda update
miniconda_update()
$➜ conda update conda

User conda(virtual)env 설치 (sixxDL)

특정 conda env을 복제(clone)해 conda env 생성

~$➜  conda create --name sixxDL --clone r-reticulate
$ conda create --name [NEW_ENV_NAME] --clone [ENV_NAME]

update pip

pip가 pip를 업그레드 한다. pip install –upgrade pip
python -m과 같이 쓰면, 실행할 모듈인 pip를 sys.path에서 찾아서 실행시키는 것

~$➜  conda activate sixxDL
~$➜  python -m pip install --upgrade pip

참고> conda 사용

# Python Configuration ---------------------------------------------------------
use_miniconda()   # miniconda가 default path(~/Library/r-miniconda)가 아닐때 사용
#=> use_condaenv(condaenv, conda = "/Users/onesixx/Library/r-miniconda/bin/conda", required=F)
\tuse_condaenv()
\t#=> use_python("/Users/onesixx/Library/r-miniconda/envs/sixxTS/bin/python", required=F)\t
\t\tuse_python()

# 정보 ---------------------------------------\t\t
py_config()

# conda 명령어 : 가상환경 list, 생성, 삭제 -------------------------------------
conda_list() 
conda_create()
conda_remove()

User env구성 및 사용

myENV='sixxDL'
use_condaenv(myENV)

패키지 추가설치

conda_install()

#conda_install(envname=myEnvname, "scikit-learn")  #sklearn
conda_install(envname=myENV, c("matplotlib","pandas","seaborn","scikit-learn"))
conda_install(envname=myENV, packages = "plaidml-keras", pip=T)
$➜  conda info --env
$➜  conda activate sixxDL
$➜  conda install matplotlib
# $➜  conda install matplotlib pandas seaborn scikit-learn
# $➜  conda install -c conda-forge sklearn

macos : install plaidML

conda_install(envname=myENV, packages = "plaidml-keras", pip=T)

Keras설치

library(keras)
install_keras(method="conda", tensorflow="gpu")
#install_keras(method="conda", tensorflow="2.1.2-gpu")
use_backend(backend="tensorflow") 

macos : use plaidML

library(keras)
install_keras(method="conda", tensorflow="gpu")
use_backend(backend=c("plaidml")

TEST

keras::k_backend()                     # The name of the backend Keras is currently using
system("plaidbench keras mobilenet")   # 설치확인

Categories: DeepLearning

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x