# 暫存文字 > #### **Linux** - 照[官方的說明](https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md),安裝相關套件。 ``` pip install protobuf (版本 3.12.0) sudo apt-get install python3-tk (版本 8.6) pip install pillow (版本 7.1.2) pip install lxml (版本 4.5.0) pip install tf-slim (版本 1.1.0) pip install matplotlib (版本 3.2.1) pip install Cython (版本 0.29.17) pip install contextlib2 (版本 0.6.0.post1) pip install pyqt5 (版本 5.15.0) pip install opencv-python (版本 4.2.0) pip install numpy (版本 1.17,原本anaconda太新會有問題) pip install scipy (版本 1.5.0) pip install labelme (版本 4.5.6) ``` - Linux ``` git clone https://github.com/cocodataset/cocoapi.git cd cocoapi/PythonAPI make ``` - Linux - **直接編譯**,在 ./models/research/ 目錄下執行以下指令: ``` protoc object_detection/protos/*.proto --python_out=. ``` 若有錯誤訊息,請使用以下手動編譯。 - **手動編譯**,下載 protobuf.zip,解壓縮後於 ./models/research/ 執行。 ``` wget -O protobuf.zip https://github.com/google/protobuf/releases/download/v3.0.0/protoc-3.0.0-linux-x86_64.zip unzip protobuf.zip ./bin/protoc object_detection/protos/*.proto --python_out=. ``` - **Linux** ``` export PYTHONPATH=$PYTHONPATH:<path to research>:<path to research>/slim ``` > pwd : 為路徑 > 以下為實際運行指令: ``` # Training set python create_labelme_tf_record.py \ --images_dir=/home/<virtual env folder>/models/research/object_detection/myMaskrcnn/ITRI_dataset/train/train_img --annotations_json_dir=/home/<virtual env folder>/models/research/object_detection/myMaskrcnn/ITRI_dataset/train/train_json --label_map_path=/home/<virtual env folder>/research/object_detection/myMaskrcnn/wrench_label.pbtxt --output_path=/home/<virtual env folder>/models/research/object_detection/myMaskrcnn/ # Validation set python create_labelme_tf_record.py \ --images_dir=/home/<virtual env folder>/models/research/object_detection/myMaskrcnn/ITRI_dataset/val/val_img --annotations_json_dir=/home/<virtual env folder>/models/research/object_detection/myMaskrcnn/ITRI_dataset/val/val_json --label_map_path=/home/<virtual env folder>/models/research/object_detection/myMaskrcnn/unknown_label.pbtxt --output_path=/home/<virtual env folder>/models/research/object_detection/myMaskrcnn/ ``` :::warning ##### 若無法使用GPU訓練資料,請確認是否無法順利開啟CUDA相關檔案,若無法開啟並產生以下訊息,請設定環境變數,便能順利開啟檔案使用GPU運行 (以下為Linux使用情境): - ++錯誤訊息++ `Cannot dlopen some GPU libraries. Skipping registering GPU devices` - ++設定環境變數++ ``` export PATH=$PATH:/usr/local/cuda-10.0/bin export CUDADIR=/usr/local/cuda-10.0 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-10.0/lib64 ``` ::: 以下為實際運行指令: ``` python export_inference_graph.py \ --pipeline_config_path=/home/<virtual env folder>/models/research/object_detection/myMaskrcnn/wrench_itri/pipeline.config --trained_checkpoint_prefix=/home/<virtual env folder>/models/research/object_detection/myMaskrcnn/wrench_itri/model.ckpt-25503 --output_directory=/home/<virtual env folder>/models/research/object_detection/myMaskrcnn/test2.0.0 ``` 以下為實際運行指令: ``` python legacy/train.py \ --train_dir=/home/<virtual env folder>/models/research/object_detection/myMaskrcnn/wrench_itri --pipeline_config_path=/home/<virtual env folder>/models/research/object_detection/myMaskrcnn/mask_rcnn_inception_v2_coco_2018_01_28/pipeline.config ``` ``` python mo_tf.py \ --input_model=C:/Users/<username>/Desktop/test2.0.0/frozen_inference_graph.pb --model_name=maskrcnn_v3 --output_dir=C:/Users/<username>/Desktop/test2.0.0 --tensorflow_use_custom_operations_config=C:/"Program Files (x86)"/IntelSWTools/openvino_2020.1.033/deployment_tools/model_optimizer/extensions/front/tf/mask_rcnn_support_api_v1.15.json --tensorflow_object_detection_api_pipeline_config=C:/Users/<username>/Desktop/test2.0.0/pipeline.config --log_level=ERROR ``` #### **Linux** - **Virtualenv (Linux 建議使用)** Virtualenv 屬於Python套件,直接於Terminal執行。 - 安裝Virtualenv `pip install vitrualenv` - 建立虛擬環境 `virtualenv -p python3.7 myenv` >-p : 選擇Python版本 >環境名稱之命名 ``` python m.py \ --train_dir=path to train direction --pipeline_config=path to configuration file (檔案名稱 *.config) ``` > train_dir : 訓練產生檔案的位置。 > pipeline_config : 參數組態檔案。 以下為實際運行指令: ![](https://i.imgur.com/8vzbMEH.png) ### [5] [COCO API](https://github.com/cocodataset/cocoapi) 安裝 ``` ```