# PyTorch-YOLOv3 ###### tags: `教學` `PyTorch` `YOLOv3` :::info :boy: **作者:** neverleave0916 :mailbox_closed: **聯絡資訊:<neverleave0916@gmail.com>** :point_right: **<font color="#B24B42">修改日期:** 2020/4/11 22:00</font> ::: > - 在Docker上使用PyTorch-YOLOv3 :video_game: > - 軟體版本: | Software | Version | |:--------------|:--------| | Ubunut | 18.04 | | Docker | 18.09.3 | | Nividia Driver| 410.104 | | CUDA | 10.0 | ## :memo: 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 ```console= 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: 安裝環境 ```console=+ apt-get update apt-get install sudo sudo apt install python3-pip pip install --upgrade pip ``` ### Step 3: 取得檔案 ```console=+ 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. ```console=+ jupyter notebook --allow-root --no-browser --ip=0.0.0.0 ``` ### Step 5: 更新requirement.txt 使用jupyter notebook開啟requirement.txt,並將tensorflow更新為以下代碼: ```console=+ tensorflow-gpu==1.14.0 ``` ### Step 6: 更新conda ```console=+ conda update -n base -c defaults conda ``` 原因:[PackagesNotFoundError: The following packages are not available from current channels:](https://stackoverflow.com/questions/48493505/packagesnotfounderror-the-following-packages-are-not-available-from-current-cha) ```console=+ conda config --append channels conda-forge ``` ### Step 7: 安裝環境 [使用conda安装requirement.txt指定的依赖包](https://blog.csdn.net/Mao_Jonah/article/details/89502380) ```console= while read requirement; do conda install --yes $requirement || pip install $requirement; done < requirements.txt ``` ### Step 8: 下載權重 ```console= cd weights/ bash download_weights.sh cd .. ``` ### Step 9: 下載COCO Data Set ```console= 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')](https://github.com/pytorch/vision/issues/1712) ```console= pip install --upgrade Pillow==6.2.1 ``` ### Step 11: 測試 GPU 能否被 PyTorch 調用 ```console= import torch torch.cuda.is_available() true ``` 若最後輸出`false`請檢查環境與GPU驅動版本 ### Step 12: Test ```console= python3 test.py --weights_path weights/yolov3.weights ``` ### Step 13: Inference ```console= python3 detect.py --image_folder data/samples/ ``` ### Step 14: Train ```console= python3 train.py --data_config config/coco.data --pretrained_weights weights/darknet53.conv.74 ``` ## :memo: 常見問題 ### 1. Jupyter-notebook無回應 將tornado由6.x降版 原因:[jupyter notebook connecting to kernel problem](https://www.cnblogs.com/csu-lmw/p/10502496.html) ```console= pip install --upgrade tornado==4.5.3 ``` ### 2. 在jupyter-notebook中執行 \.py 使用此方法可執行detected檔案(不在github中,自行在jupyter notebook建立) - [How to load/edit/run/save text file(.py) into a jupyter notebook's cell](https://stackoverflow.com/questions/21034373/how-to-load-edit-run-save-text-files-py-into-an-ipython-notebook-cell) ### 3. python(.py) 和 ipython notebook (.ipynb) 互轉 - [.py 和 ipython notebook (.ipynb) 互轉?](http://blog.ittraining.com.tw/2017/11/py-ipython-notebook-ipynb.html) ### 參考資料: - [eriklindernoren/PyTorch-YOLOv3](https://github.com/eriklindernoren/PyTorch-YOLOv3) --- <br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br><br> ## :memo: 其他(僅供參考) ### 錯誤(測試作法) 開始執行後,安裝環境時若出現 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 ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up