问题描述:
在使用不同数据集训练同一个网络时,可能遇到两个数据集图片类型不一致的情况,如果程序默认加载jpg数据,而当前数据集图片是png类型,就会报错:
FileNotFoundError: [Errno 2] No such file or directory: 'DOTAv10/data/split_ss_dota_1024_200/trainval/images/P2700__1024__0___1557.jpg'
解决方法
我使用的是mmdet框架,
修改/data/lxy1/pointobb-main/PointOBB/mmdet/datasets/xml_style.py第42行
for img_id in img_ids:
filename = f'JPEGImages/{img_id}.png' #就是这里
# filename = f'JPEGImages/{img_id}.jpg'
xml_path = osp.join(self.img_prefix, 'Annotations',
f'{img_id}.xml')
tree = ET.parse(xml_path)
root = tree.getroot()
size = root.find('size')
if size is not None:
width = int(size.find('width').text)
height = int(size.find('height').text)
else:
img_path = osp.join(self.img_prefix, 'JPEGImages',
'{}.jpg'.format(img_id)) #修改训练数据格式为png
img = Image.open(img_path)
width, height = img.size
data_infos.append(
dict(id=img_id, filename=filename, width=width, height=height))
修改/data/lxy1/pointobb-main/PointOBB/mmdet/datasets/pipelines/loading.py第57行
if results['img_prefix'] is not None:
# filename = osp.join(results['img_prefix'],
# results['img_info']['filename'])
filename = osp.join(results['img_prefix'],
results['img_info']['filename'].replace('jpg', 'png') )
else:
# filename = results['img_info']['filename']
filename = results['img_info']['filename'].replace('jpg', 'png') #训练数据格式为png