In 72p "3.6.2 Neural network inference processing" of "Deep Learning from scratch", the pickle file of python is called. This pickle file is a raw binary, so it's not easy to call. So, try importing the pickle file from the forbidden PyCall.
#Install pycall
$ gem install pycall
#Incorporation of pyenv
$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
# .bash_Reuptake profile
$ source ~/.bash_profile
#python version check
$ python3 --version
3.7.3
#pyenv shared library installation
$ CONFIGURE_OPTS="--enable-shared" pyenv install 3.7.3
#numpy installation
$ pip install numpy
Now ready
require 'pycall/import'
include PyCall::Import
pyimport :numpy
pyimport :pickle
pkl = open("sample_weight.pkl", "rb")
network = pickle.load(pkl)
I was angry that I just called pycall normally.
> require 'pycall/import'
true
> include PyCall::Import
Object
> hoge = PyCall.eval('0')
Traceback (most recent call last):
9: from /usr/local/bin/irb:23:in `<main>'
8: from /usr/local/bin/irb:23:in `load'
7: from /usr/local/lib/ruby/gems/2.7.0/gems/irb-1.2.1/exe/irb:11:in `<top (required)>'
6: from (irb):3
5: from /usr/local/bundle/gems/pycall-1.3.0/lib/pycall.rb:39:in `eval'
4: from /usr/local/bundle/gems/pycall-1.3.0/lib/pycall.rb:62:in `import_module'
3: from /usr/local/bundle/gems/pycall-1.3.0/lib/pycall/init.rb:16:in `const_missing'
2: from /usr/local/bundle/gems/pycall-1.3.0/lib/pycall/init.rb:35:in `init'
1: from /usr/local/bundle/gems/pycall-1.3.0/lib/pycall/libpython/finder.rb:95:in `find_libpython'
PyCall::PythonNotFound (PyCall::PythonNotFound)
I was able to solve it by installing the shared library of pyenv referring to the following article
Install pyenv and pyenv-virtualenv https://qiita.com/shigechioyo/items/198211e84f8e0e9a5c18 [Ruby] Machine learning ①: Introduction to Ruby https://qiita.com/chamao/items/cd62715c6be2fad2f8e7
Recommended Posts