下载yolov7源码之后,发现有很多坑,估计一一记录。
1. 在train.py中的参数与配置文件中的参数的优先级?
如图所示,我将yaml文件的地址如下parser.add_argument('--data', type=str, default='NEU-DET/data.yaml', help='data.yaml path')
,对应的yaml文件如下图所示。
#yaml
train: D:\\python\\yolov7-main\\NEU-DET\\train\\images
val: D:\\python\\yolov7-main\\NEU-DET\\valid\\images
nc: 6
names: ['crazing', 'inclusion', 'patches', 'pitted_surface', 'rolled-in_scale', 'scratches']
结果训练时候却报错,说找不到train.txt文件。
train.txt也没有发现问题:
这个坑头有点大,我找变了所有的py文件,搜索之下没有任何D:\\PycharmProject\\yolov7-main\\NEU-DET\\train.txt
这个路径的结果。于是我查看了打开了train.py的配置文件。我发现这里有一个配置的脚本为:
--workers
1
--device
0
--batch-size
4
--data
data/neu.yaml
--cfg
cfg/training/yolov7.yaml
--weights
yolov7.pt
--name
yolov7
--hyp
data/hyp.scratch.p5.yaml
--epochs
20
我打开了对应的--data data/neu.yaml
文件,发现如下:。原来问题出现在配置脚本中。最后得出结论,这个配置文件优先级高于train.py中的配置参数。
# COCO 2017 dataset http://cocodataset.org
# download command/URL (optional)
download: bash ./scripts/get_coco.sh
# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/]
train: D:\\PycharmProject\\yolov7-main\\NEU-DET\\train.txt
val: D:\\PycharmProject\\yolov7-main\\NEU-DET\\val.txt
#test: ./coco/test-dev2017.txt # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794
# number of classes
nc: 6
# class names
names: ['crazing', 'inclusion', 'patches', 'pitted_surface', 'rolled-in_scale', 'scratches']
2.报错如下,这是因为numpy的版本问题,早期版本使用的np.int已经被弃用。
AttributeError: module 'numpy' has no attribute 'int'.
`np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
按照如下方式进行一一改进(主要是dataset.py和general有这种书写问题)
# Old code
x = np.array([1, 2, 3], dtype=np.int)
# New code
x = np.array([1, 2, 3], dtype=int)
OK终于开始跑了