It's about the virtual environment of Python. We will derail from the middle and start building Tensorflow.
virtualenv is one of the packages that builds a lightweight virtual environment within Python.
When developing with Python, you tend to stumble when building an environment. pip or pip or pip. For me as a beginner, environment construction is always the last boss. Really scary.
This is where you talk about yourself, and as one of the uses of this virtualenv, you can manage the packages introduced by the interpreter and pip at the same time. It's a very useful module.
This time I would like to talk about the difficulties when introducing TensorFlow to Raspberry Pi. Rather than a difficult story, is it a series of flows that can be built smoothly with virtualenv?
The goal is to build an environment to move the sample.
First of all, prepare the Raspberry Pi that everyone loves. It is assumed that the initial settings have been completed. It doesn't matter if it's SSH or VNC, so for the time being, just open the terminal.
Tool | Ver |
---|---|
Python | 3.5.3 |
Tensorflow | 1.11.0 |
I think you can install it without any problems.
sudo apt install libatlasbase-dev
pip install tensorflow
I can't say I stumbled at this point at the time.
I wish I could install it without any problems, but in my case, I couldn't install only a specific package.
Here is the main issue. It was a mess until I got to know virtualenv.
Install virtualenv.
pip install virtualenv
Execute the following in the current directory to create an environment called hoge.
virtualenv --system-site-packages -p python3 ./hoge
Activate the built environment.
source ./hoge/bin/activate
When enabled, the beginning of the terminal
(hoge)$
So that's it.
Install the required modules for Tensorflow. Let's install it individually. If Python2 and Python3 coexist, you can install it with pip3.
Install Cython, contextlib2, pillow, lxml, jupyter, matplotlib.
pip install --user Cython
pip install --user contextlib2
pip install --user pillow
pip install --user lxml
pip install --user jupyter
pip install --user matplotlib2
Install these with the virtual environment enabled. Also, the explanation of each module is omitted.
In order to detect an object, it is necessary to install "Object Detection API". I will omit the details, but if you want to detect objects right away, please introduce it. It is also needed to train your own dataset. This time, I will try to build the environment until the sample is executed.
This time I will rely on the sample. I'm sorry. First, clone this.
git clone https://github.com/tensorflow/models.git
When the clone is finished
models/research
Please move to.
Therefore
#Compiler installation
sudo apt-get install protobuf-compiler
#compile
protoc object_detection/protos/*.proto --python_out=.a
When you do these, the protbuf library will be compiled without any response.
Next you need to specify the environment variables.
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
As a caveat, it may be better to write to the bash file in advance because it needs to be rewritten every time the terminal is started.
Finally, clone the following trained data.
https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/d
etection_model_zoo.md
Now you are ready. After that, I think it's a good idea to execute the code written in Python.
After all it is quick to put it back in.
When re-installing Python and Tensorflow
sudo apt-get install python-pip python3-pip
sudo pip uninstall tensorflow
git clone https://github.com/PINTO0309/Tensorflow-bin.git
cd Tensorflow-bin
sudo pip install tensorflow-1.11.0-cp35-cp35m-linux_armv7l.whl
When introducing Tensorflow individually
https://www.piwheels.org/simple/tensorflow/
I think you should refer to here.
This time, it is an experience story that I escaped from the predicament of environment construction using virtualenv. Without virtualenv, I would probably have been frustrated. Thank you virtualenv.
I also used these to create a simple thing to figure out how many people are there. I won't write it because it's not particularly attractive, but at that time I was working on an experiment to see if it could be operated with a small hardware called Raspberry Pi, so I'd like to talk about that later, but probably not.
-github tensorflow https://github.com/tensorflow/models.git
-piwheels https://www.piwheels.org/
Recommended Posts