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