相比于官方给出的基于darknet框架的YOLOv3,基于PyTorch的YOLOv3源码易懂,使用更方便。我将自己在学习和探索过程中遇到的问题和解决的经验在这里与大家分享,希望能为初学者提供一些帮助。
1. 运行detect.py 时,出现RuntimeError:Invalid DISPLAY variable
解决方法:给detect.py的 import matplotlib 后面line22加
plt.switch_backend(‘agg’)
2. 训练时出现 UserWarning: indexing with dtype torch.uint8 is now deprecated, please use a dtype torch.bool instead
解决方法:将utils/utils.py 第269行
ByteTensor = torch.cuda.ByteTensor if pred_boxes.is_cuda else torch.ByteTensor
修改为:
BoolTensor = torch.cuda.BoolTensor if pred_boxes.is_cuda else torch.BoolTensor
并将278, 279行修改为:
obj_mask = BoolTensor(nB, nA, nG, nG).fill_(0)
noobj_mask = BoolTensor(nB, nA, nG, nG).fill_(1)
3. Out of memory tried to allocate xxxx bytes
解决方法:将train.py中batch_size调小。
4. OSError: image file is truncated (98 bytes not processed)
解决方法:给train.py中加这两行代码
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
5. Traceback (most recent call last): File “train_yolov3.py”, line 176, in ap_table += [[c, class_names[c], “%.5f” % AP[i]]]
IndexError: list index out of range
后来发现是因为自己的*.names文件中最后一行少了一个换行符 ~~~~~~~~愚蠢至极
6. 训练第一个epoch时,test.py中ValueError: not enough values to unpack (expected 3, got 0)
解决方法:修改代码增加判断条件
7. AttributeError: module ‘tensor board.summary._tf.summary’ has no attribute ‘FileWriter’
原因:tensorflow版本问题
解决方案:修改utils/logger.py
8. metric_table = [[“Metrics”, *[f"YOLO Layer {i}" for i in range(len(model.yolo_layers))]]]
SyntaxError: invalid syntax
解决方案:使用python3.6以上版本
[1] https://github.com/eriklindernoren/PyTorch-YOLOv3
[2] https://pjreddie.com/darknet/yolo/