Construction d'environnement Python et TensorFlow

Construction d'environnement Python et TensorFlow

Il s'agit d'un journal (mémorial) lors de l'installation en se référant à la page de Karaage-san.

Créez un environnement Python.

Installez pyenv

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

Modification de .bashrc

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

installation de python (Anaconda)

Série Anaconda 2

$ 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

Série Anaconda 3

$ 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

installation de pyenv-virtualenv

$ 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

Installation de virtualenv

$ sudo python3 -m pip install virtualenv
$ virtualenv env

Créer un environnement d'apprentissage

Installation de TensolFlow et OpenCV

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

S'il s'agit de la série python3.8, tensorflow1.14.0 ne peut pas être installé, utilisez donc la série 3.6. $ 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=.

Contrôle de fonctionnement

$ 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)

Installez Cocoapi

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

Installation d'OpenCV

$ conda install -c conda-forge opencv

Vidage de mémoire avec 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)
Cela semble être la cause.
 $ conda install -c conda-forge opencv
La méthode de contre-mesure est
import matplotlib as mpl
mpl.use('TkAgg')
import matplotlib.pyplot as plt

Cela résoudra le problème (c'est mieux) </ b>

conda install qt
conda remove opencv
pip install opencv-python

Erreur avec cap = cv2.VideoCapture (DEVICE_ID)

Cette erreur peut également être résolue en réinstallant OpenCV avec pip </ B>

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'

référence

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

Recommended Posts