yolo系列-如何加载中文格式的数据

opencv不能直接加载中文路径下的文件或者不能直接导入含有中文名称的数据。
这里使用pillow包,完成中文数据导入步骤。
对应修改yolox/data/datasets/coco.py文件中的代码

from PIL import Image, ImageFile#导入pillow,这里注意是Image

def load_resized_img(self, index):
        img = self.load_image(index)
         # 将图像转换为 RGB 格式(3 通道),因为pillow默认是4通道
        if img.mode == 'RGBA':
            img = img.convert('RGB')
        r = min(self.img_size[0] / img.size[0], self.img_size[1] / img.size[1])#不能使用.shape(),pillow不支持,这里换成.size()
        img = np.array(img)  # 转换为 NumPy 数组
        resized_img = cv2.resize(
            img,
            (int(img.shape[1] * r), int(img.shape[0] * r)),#因为已经转为数组所以这里可以直接使用.resize()和.shape()
            interpolation=cv2.INTER_LINEAR,
        ).astype(np.uint8)
        return resized_img

    def load_image(self, index):
        file_name = self.annotations[index][3]

        img_file = os.path.join(self.data_dir, self.name, file_name)
        # 允许加载截断的图像
        ImageFile.LOAD_TRUNCATED_IMAGES = True
        # img = cv2.imread(img_file)#原cv加载图片的代码
        img=Image.open(img_file).convert('RGB')
        assert img is not None, f"file named {img_file} not found"
        return img

报错
1、ModuleNotFoundError: No module named ‘yolox.layers.fast_cocoeval’
版本问题,将yolox\layers\jit_ops.py中的fast_cocoeval改为fast_coco_eval_api

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值