一、文档认识:
1、工程文件
https://github.com/lufficc/SSD
整个工程文件:在这里插入图片描述
2、数据集和标签文件
我们需要认识下整个项目,我们以voc2007数据集为例子,这儿贴出数据集下载地方:
VOC数据集下载地址如下,里面已经包括了训练集、测试集、验证集(与测试集一样),无需再次划分:
链接: https://pan.baidu.com/s/1-1Ej6dayrx3g0iAA88uY5A
提取码: ph32
下载后直接放到根目录下,新建一个datasets,如图所示
3、yaml文件
在:configs/vgg_ssd300_voc0712.yaml
切记不要漏掉TRAIN里面的逗号,BATCH_SIZE根据自己设备调节,NUM_CLASSES这个要在自己标注的种类上加一,也就是加上背景
4、配置文件
在ssd/config/defaults.py和ssd/config/path_catlog.py
defaults.py中:
_C.DATA_LOADER.NUM_WORKERS = 0
path_catlog.py中:
如果向我一样命名数据集就不用更改,主要是更改数据集的位置
5、模型文件
这个主要是以vgg为主干网络,这个它会自动生成在这个文件下,运行train.py文件会有,不然.torch文件夹不会生成,你也可以自己新建然后自己找一个vgg的模型。
二、问题
有了认识就来解决问题:
问题1:line 88, in main
cfg.merge_from_file(args.config_file)
File “D:\software\anaconda\anaconda_setting\lib\site-packages\yacs\config.py”, line 211, in merge_from_file
with open(cfg_filename, “r”) as f:
FileNotFoundError: [Errno 2] No such file or directory: ‘’
找不到路径,手动添加即可:
parser.add_argument(
"--config-file",
default="configs/vgg_ssd300_voc0712.yaml",
metavar="FILE",
help="path to config file",
type=str,
)
问题2:报错 UserWarning: No NMS is available. Please upgrade torchvision to 0.3.0+的解决办法
参考博客:https://www.cnblogs.com/herd/p/16090042.html
找到文件:ssd/utils/nms.py,注释即可
问题3:File “E:\code\SSD-master\train.py”, line 89, in main
cfg.merge_from_file(args.config_file)
File “D:\software\anaconda\anaconda_setting\lib\site-packages\yacs\config.py”, line 212, in merge_from_file
cfg = self.load_cfg(f)
File “D:\software\anaconda\anaconda_setting\lib\site-packages\yacs\config.py”, line 363, in load_cfg
return cls._load_cfg_from_file(cfg_file_obj_or_str)
File “D:\software\anaconda\anaconda_setting\lib\site-packages\yacs\config.py”, line 372, in _load_cfg_from_file
return cls._load_cfg_from_yaml_str(file_obj.read())
UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xad in position 13: illegal multibyte sequence
这个项目使用yacs包,我看了vgg_ssd300_voc0712.yaml文件是utf-8的格式,但是就是读不出来,然后我下载的是这个版本,
报错,卸载重找没用
如图,自己写个函数
问题4:AttributeError: module ‘numpy‘ has no attribute ‘bool‘.
参考博客:https://blog.csdn.net/weixin_44716485/article/details/130554982
问题5:RuntimeError: Trying to resize storage that is not resizable
参考文献:https://blog.csdn.net/qq_38308388/article/details/134017869
将ssd/config/defaults.py文件中如图修改为0
然后不出意外的话应该可以运行,整体的环境是:
print(torch.__version__)
1.12.1+cu113
print(torch.cuda_version)
11.3
print(torch.backends.cudnn.version())
8302
问题6:raise RuntimeError(‘Error(s) in loading state_dict for {}:\n\t{}’.format(
RuntimeError: Error(s) in loading state_dict for SSDDetector:
这个问题出自将自己的数据集和标签进行训练时候,只需要将outputs文件夹里面已经训练好的模型删除即可
参考文献:
https://blog.51cto.com/u_16213592/11777787
https://zhuanlan.zhihu.com/p/98059235
https://zhuanlan.zhihu.com/p/62725380