Python-Umgebungskonstruktion und TensorFlow

Python-Umgebungskonstruktion und TensorFlow

Es ist ein Protokoll (Gedenknotiz) bei der Installation unter Bezugnahme auf Seite von Karaage-san.

Erstellen Sie eine Python-Umgebung.

Installieren Sie pyenv

$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv

Bearbeiten von .bashrc

$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(pyenv init -)"' >> ~/.bashrc
$ source ~/.bashrc

Python (Anaconda) Installation

Anaconda 2 Serie

$ pyenv install -l | grep "anaconda2-*
anaconda2-2.4.0
anaconda2-2.4.1
anaconda2-2.5.0
anaconda2-4.0.0
anaconda2-4.1.0
anaconda2-4.1.1
anaconda2-4.2.0
anaconda2-4.3.0
anaconda2-4.3.1
anaconda2-4.4.0
anaconda2-5.0.0
anaconda2-5.0.1
anaconda2-5.1.0
anaconda2-5.2.0
anaconda2-5.3.0
anaconda2-5.3.1
anaconda2-2018.12
anaconda2-2019.03
anaconda2-2019.07

$ pyenv install anaconda2-5.3.1
Downloading Anaconda2-5.3.1-Linux-x86_64.sh...
-> https://repo.continuum.io/archive/Anaconda2-5.3.1-Linux-x86_64.sh
Installing Anaconda2-5.3.1-Linux-x86_64...
Installed Anaconda2-5.3.1-Linux-x86_64 to ~/.pyenv/versions/anaconda2-5.3.1

Anaconda 3 Serie

$ pyenv install -l | grep "anaconda3-*
anaconda3-2.0.0
anaconda3-2.0.1
anaconda3-2.1.0
anaconda3-2.2.0
anaconda3-2.3.0
anaconda3-2.4.0
anaconda3-2.4.1
anaconda3-2.5.0
anaconda3-4.0.0
anaconda3-4.1.0
anaconda3-4.1.1
anaconda3-4.2.0
anaconda3-4.3.0
anaconda3-4.3.1
anaconda3-4.4.0
anaconda3-5.0.0
anaconda3-5.0.1
anaconda3-5.1.0
anaconda3-5.2.0
anaconda3-5.3.0
anaconda3-5.3.1
anaconda3-2018.12
anaconda3-2019.03
anaconda3-2019.07
anaconda3-2019.10
anaconda3-2020.02

$ pyenv install anaconda3-5.3.1
Downloading Anaconda3-5.3.1-Linux-x86_64.sh.sh...
-> https://repo.continuum.io/archive/Anaconda3-5.3.1-Linux-x86_64.sh
Installing Anaconda3-5.3.1-Linux-x86_64.sh...
Installed Anaconda3-5.3.1-Linux-x86_64.sh to /home/miyamoto/.pyenv/versions/anaconda3-5.3.1

$ pyenv global anaconda2-5.3.1
$ pyenv versions 
system
* anaconda2-5.3.1 (set by /home/miyamoto/.pyenv/version)
  anaconda3-5.3.1

$ pyenv global anaconda3-5.3.1
$ pyenv versions
system
 anaconda2-5.3.1
* anaconda3-5.3.1 (set by /home/miyamoto/.pyenv/version)

$ pyenv global system
$ pyenv versions
* system (set by /home/miyamoto/.pyenv/version)
 anaconda2-5.3.1
 anaconda3-5.3.1

pyenv-virtualenv Installation

$ git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv

$ echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
$ echo export PYENV_VIRTUALENV_DISABLE_PROMPT=1 >> ~/.bashrc
$ source ~/.bashrc

Virtualenv installieren

$ sudo python3 -m pip install virtualenv
$ virtualenv env

Aufbau einer Lernumgebung

Installation von TensolFlow und OpenCV

$ pyenv global anaconda3-5.3.1
$ conda create -n od anaconda
$ pyenv global anaconda3-5.1.0/envs/od

Wenn es sich um die Python3.8-Serie handelt, kann Tensorflow1.14.0 nicht installiert werden. Verwenden Sie daher die 3.6-Serie. $ conda install python=3.6.6

$ pip install tensorflow==1.14.0
$ pip install opencv-python



$ sudo apt install protobuf-compiler
protoc --version
libprotoc 3.0.0

$ cd ~ 
$ git clone https://github.com/tensorflow/models
$ cd ~/model/research
$ protoc object_detection/protos/*.proto --python_out=.

Funktionsprüfung

$ cd model/research
$ export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
$ python object_detection/builders/model_builder_test.py
Running tests under Python 3.6.6: ~/.pyenv/versions/anaconda3- 
5.1.0/envs/od/bin/python
[ RUN      ] ModelBuilderTest.test_create_experimental_model
[       OK ] ModelBuilderTest.test_create_experimental_model 
[ RUN      ] ModelBuilderTest.test_create_faster_rcnn_model_from_config_with_example_miner
[       OK ] ModelBuilderTest.test_create_faster_rcnn_model_from_config_with_example_miner
[ RUN      ] ModelBuilderTest.test_create_faster_rcnn_models_from_config_faster_rcnn_with_matmul
[       OK ] ModelBuilderTest.test_create_faster_rcnn_models_from_config_faster_rcnn_with_matmul
[ RUN      ] ModelBuilderTest.test_create_faster_rcnn_models_from_config_faster_rcnn_without_matmul
[       OK ] ModelBuilderTest.test_create_faster_rcnn_models_from_config_faster_rcnn_without_matmul
[ RUN      ] ModelBuilderTest.test_create_faster_rcnn_models_from_config_mask_rcnn_with_matmul
[       OK ] ModelBuilderTest.test_create_faster_rcnn_models_from_config_mask_rcnn_with_matmul
[ RUN      ] ModelBuilderTest.test_create_faster_rcnn_models_from_config_mask_rcnn_without_matmul
[       OK ] ModelBuilderTest.test_create_faster_rcnn_models_from_config_mask_rcnn_without_matmul
[ RUN      ] ModelBuilderTest.test_create_rfcn_model_from_config
[       OK ] ModelBuilderTest.test_create_rfcn_model_from_config
[ RUN      ] ModelBuilderTest.test_create_ssd_fpn_model_from_config
[       OK ] ModelBuilderTest.test_create_ssd_fpn_model_from_config  
[ RUN      ] ModelBuilderTest.test_create_ssd_models_from_config
[       OK ] ModelBuilderTest.test_create_ssd_models_from_config
[ RUN      ] ModelBuilderTest.test_invalid_faster_rcnn_batchnorm_update
[       OK ] ModelBuilderTest.test_invalid_faster_rcnn_batchnorm_update
[ RUN      ] ModelBuilderTest.test_invalid_first_stage_nms_iou_threshold
[       OK ] ModelBuilderTest.test_invalid_first_stage_nms_iou_threshold
[ RUN      ] ModelBuilderTest.test_invalid_model_config_proto
[       OK ] ModelBuilderTest.test_invalid_model_config_proto
[ RUN      ] ModelBuilderTest.test_invalid_second_stage_batch_size
[       OK ] ModelBuilderTest.test_invalid_second_stage_batch_size
[ RUN      ] ModelBuilderTest.test_session
[  SKIPPED ] ModelBuilderTest.test_session
[ RUN      ] ModelBuilderTest.test_unknown_faster_rcnn_feature_extractor
[       OK ] ModelBuilderTest.test_unknown_faster_rcnn_feature_extractor
[ RUN      ] ModelBuilderTest.test_unknown_meta_architecture
[       OK ] ModelBuilderTest.test_unknown_meta_architecture
[ RUN      ] ModelBuilderTest.test_unknown_ssd_feature_extractor
[       OK ] ModelBuilderTest.test_unknown_ssd_feature_extractor
----------------------------------------------------------------------
Ran 17 tests in 0.197s
OK (skipped=1)

Cocoapi installieren

$ pip install git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI

OpenCV-Installation

$ conda install -c conda-forge opencv

Core Dump mit Import matplotlib.pyplot

$ python
Python 3.6.6 |Anaconda, Inc.| (default, Oct  9 2018, 12:34:16) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import  matplotlib.pyplot
Segmentation fault (core dumped)
Dies scheint die Ursache zu sein.
 $ conda install -c conda-forge opencv
Die Gegenmaßnahme ist
import matplotlib as mpl
mpl.use('TkAgg')
import matplotlib.pyplot as plt

Dies wird das Problem beheben (dies ist besser) </ b>

conda install qt
conda remove opencv
pip install opencv-python

Fehler mit cap = cv2.VideoCapture (DEVICE_ID)

Dieser Fehler kann auch durch Neuinstallation von OpenCV mit pip </ B> behoben werden

Traceback (most recent call last):
  File "./detect.py", line 104, in <module>
    height, width, channels = c_frame.shape
AttributeError: 'NoneType' object has no attribute 'shape'

Referenz

https://www.petitmonte.com/python/object_detection_api.html https://qiita.com/sage-git/items/aa3d2acd93cded4be2e8

Recommended Posts