目标检测实验问题记录(三)mmdet图片类型jpg/png切换

问题描述:

在使用不同数据集训练同一个网络时,可能遇到两个数据集图片类型不一致的情况,如果程序默认加载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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值