EfficientDet代码:https://github.com/zylo117/Yet-Another-EfficientDet-Pytorch
针对训练时efficientdet目录下的dataset.py文件中第52,53行中cv2.imread数据读取时出现None这个问题,首先检查了图片路径并没有问题,之后也没有找出是什么原因,通过如下方式解决:
将下面代码
def load_image(self, image_index):
image_info = self.coco.loadImgs(self.image_ids[image_index])[0]
path = os.path.join(self.root_dir, self.set_name, image_info['file_name'])
img = cv2.imread(path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
return img.astype(np.float32) / 255.
替换为
def load_image(self, image_index):
image_info = self.coco.loadImgs(self.image_ids[image_index])[0]
path = os.path.join(self.root_dir, self.set_name, image_info['file_name'])
while True:
try:
img = cv2.imread(path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
except Exception as e:
print("=====================read image error============================")
print(e)
print("=================================================================")
else:
break
return img.astype(np.float32) / 255.
实际就是读取失败时再读取,直至成功为止,通常读取第二遍时就会成功.