ubuntu上训练yolov3: Caught ValueError in DataLoader worker process 0. string indices must be integers.
最后train的代碼:
python3 train.py --model_def config/yolov3-custom.cfg --data_config config/custom.data
按資料下載yolov3進行模型訓練和檢測,下載了好幾份代碼,有一份官方的一直有問題。有一份很快跑起來了(網址忘記了,可以百度網盤分享),明明都是yolov3的pytorch版本但代碼差別很大。記錄遇到的問題和一些測試。
遇到的報錯有:
pip’s dependency resolver does not currently take into account all the
packages that are installed. This behaviour is the source of the
following dependency conflicts. launchpadlib 1.10.6 requires
testresources, which is not installed.
正在保存至: “train2014.zip”
train2014.zip 17%[+++ ] 2.17G 15.7KB/s 剩余
8d 11hget_coco_dataset.sh: 行 13: 31298 段錯誤 (核心已轉儲) wget
-c “https://pjreddie.com/media/files/train2014.zip” --header “Referer: pjreddie.com”
–2021-03-14 10:04:08-- https://pjreddie.com/media/files/val2014.zip 正在解析主機 pjreddie.com (pjreddie.com)… 128.208.4.108 正在連接 pjreddie.com
(pjreddie.com)|128.208.4.108|:443… 已連接。 已發出 HTTP 請求,正在等待回應… 206
Partial Content 長度: 6645013297 (6.2G),剩余 6628416607 (6.2G)
[application/zip] 正在保存至: “val2014.zip”
val2014.zip 0%[ ] 19.08M 2.01KB/s 用時
7m 15sh
2021-03-14 10:11:34 (7.66 KB/s) - 在 20004216 字節處連接關閉。 重試中。
python3 test.py --weights_path weights/yolov3.weights Namespace(batch_size=8, class_path='data/coco.names', conf_thres=0.5, data_config='config/coco.data', img_size=416, iou_thres=0.5, model_def='config/yolov3.cfg', n_cpu=8, nms_thres=0.5, weights_path='weights/yolov3.weights') Compute mAP... Traceback (most recent call last):File "test.py", line 109, in <module>batch_size=opt.batch_size,File "test.py", line 28, in evaluatedataset = ListDataset(path, img_size=img_size, multiscale=False, transform=DEFAULT_TRANSFORMS)File "/home/heziyi/桌面/PyTorch-YOLOv3/utils/datasets.py", line 68, in __init__with open(list_path, "r") as file: FileNotFoundError: [Errno 2] No such file or directory: 'data/coco/5k.txt'推測上面的報錯是因為train2014.zip和val2014.zip 一直沒法下載的原因,可能是占的空間太大下載不了?
測試時:python3 detect.py --image_folder data/samples/
報錯:
QObject::moveToThread: Current thread (0x42dc8a0) is not the object’s thread (0x6442460).
Cannot move to target thread (0x42dc8a0)
原因:opencv-python版本高。辦法:
sudo pip uninstall opencv-python
Successfully uninstalled opencv-python-4.5.1.48
heziyi@heziyi-ZenBook-UX425IA-U4700IA:~/桌面/PyTorch-YOLOv3$ pip install opencv-python==4.1.0.25 -i https://pypi.tuna.tsinghua.edu.cn/simple
再次運行python3 detect.py --image_folder data/samples/
且可以看到輸出:
pip install pyqt -i https://pypi.tuna.tsinghua.edu.cn/simple
ERROR: Could not find a version that satisfies the requirement pyqt
ERROR: No matching distribution found for pyqt
改為:pip install pyqt5 -i https://pypi.tuna.tsinghua.edu.cn/simple
ubuntu的輸入法打字容易錯字,還是截圖把。
試圖訓練自己引入的圖片。過程:
bash create_custom_model.sh
create_custom_model.sh: 行 1: [net]: 未找到命令
原因:bash格式錯誤,應該加:
#!/bin/bash
NUM_CLASSES=$1
echo "
改為了用yolov3-tiny.cfg
key, value = line.split("=")
ValueError: not enough values to unpack (expected 2, got 1)
推測是自己的config寫的錯誤之類的,把空行和多余的符號都刪掉了。
目前的config:
create_custom_model.sh
執行 bash create_custom_model.sh
可以看到生成了yolov3-custom.cfg
Could not read image ‘data/images/BloodImage_00274.jpg’.
Could not read image ‘data/images/BloodImage_00308.jpg’.
這問題找了很久,終于知道了還是圖片位置的原因,需要放在custom下才行,預測是代碼中有設定讀取的是同級文件夾。
只能讀取這個里面的images而不能讀取下面這個images文件夾的:
于是把train.txt內容改為:
現在能運行成功了:
最后一輪epoch
---- mAP 0.6698849929680083
還是挺低的,估計跟圖片過少有關系。
輸入
tensorboard --logdir=‘logs’ --port=6006
打開6006:
總結
以上是生活随笔為你收集整理的ubuntu上训练yolov3: Caught ValueError in DataLoader worker process 0. string indices must be integers.的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【练习】不同排序算法执行时间比较
- 下一篇: 【yolo】yolov3的pytorch