Try   HackMD

PyTorch-YOLOv3

tags: 教學 PyTorch YOLOv3

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
作者: neverleave0916
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
聯絡資訊:neverleave0916@gmail.com
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
修改日期: 2020/4/11 22:00

  • 在Docker上使用PyTorch-YOLOv3
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 軟體版本:
Software Version
Ubunut 18.04
Docker 18.09.3
Nividia Driver 410.104
CUDA 10.0

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Using Pytorch-YOLOv3 on Docker

Step 1: 建立Docker容器

Run the commands below to create a docker container,
replacing {user_name} with your user name(directory)
replacing {port} with the external port you wish to use.
replacing {your_container_name} with your container name

Usage

nvidia-docker run --ipc=host -it [OPTION] nvcr.io/nvidia/pytorch:19.02-py3

Options

-v /mnt/MIL/{user_name}:/workspace :掛載本機目錄至/workspace
-p {port}:8888                     :指定容器對外Port(若不使用Jupyter notebook可不使用)
--name={your_container_name}       :為容器指定一個名稱

Step 2: 安裝環境

apt-get update apt-get install sudo sudo apt install python3-pip pip install --upgrade pip

Step 3: 取得檔案

git clone https://github.com/eriklindernoren/PyTorch-YOLOv3 cd PyTorch-YOLOv3/

Step 4: 開啟jupyter-notebook //120.113.173.215

In your host browser, turn on the jupyter notebook interface via copying and pasting the URLs on the message, but replacing the ip such as the example (69886b134214 or 127.0.0.1) with 120.113.173.215.

jupyter notebook --allow-root --no-browser --ip=0.0.0.0

Step 5: 更新requirement.txt

使用jupyter notebook開啟requirement.txt,並將tensorflow更新為以下代碼:

tensorflow-gpu==1.14.0

Step 6: 更新conda

conda update -n base -c defaults conda

原因:PackagesNotFoundError: The following packages are not available from current channels:

conda config --append channels conda-forge

Step 7: 安裝環境

使用conda安装requirement.txt指定的依赖包

while read requirement; do conda install --yes $requirement || pip install $requirement; done < requirements.txt

Step 8: 下載權重

cd weights/ bash download_weights.sh cd ..

Step 9: 下載COCO Data Set

cd data/ bash get_coco_dataset.sh cd ..

Step 10: 將Pillow由7.0降版到6.2.1

原因:ew Pillow version (7.0.0) breaks torchvision (ImportError: cannot import name 'PILLOW_VERSION' from 'PIL')

pip install --upgrade Pillow==6.2.1

Step 11: 測試 GPU 能否被 PyTorch 調用

import torch torch.cuda.is_available() true

若最後輸出false請檢查環境與GPU驅動版本

Step 12: Test

python3 test.py --weights_path weights/yolov3.weights

Step 13: Inference

python3 detect.py --image_folder data/samples/

Step 14: Train

python3 train.py --data_config config/coco.data --pretrained_weights weights/darknet53.conv.74

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
常見問題

1. Jupyter-notebook無回應

將tornado由6.x降版
原因:jupyter notebook connecting to kernel problem

pip install --upgrade tornado==4.5.3

2. 在jupyter-notebook中執行 .py

使用此方法可執行detected檔案(不在github中,自行在jupyter notebook建立)

3. python(.py) 和 ipython notebook (.ipynb) 互轉

參考資料:





















Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
其他(僅供參考)

錯誤(測試作法)

開始執行後,安裝環境時若出現
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ejg24h9w/matplotlib/
他是用anaconda 所以要用conda升級python

python3 --version
conda update python  //會導致conda失效

https://github.com/conda/conda/issues/8920

pip install --upgrade setuptools
sudo apt-get install libpcap-dev libpq-dev
sudo apt install software-properties-common