Skip to content

Commit 5512f5a

Browse files
committed
keep info in coco dataset, which is necessary for newer pycocotools versions; also allow num_channels to be set in voc dataset
1 parent afdb7d9 commit 5512f5a

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

yolox/data/datasets/coco.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def remove_useless_info(coco):
1919
"""
2020
if isinstance(coco, COCO):
2121
dataset = coco.dataset
22-
dataset.pop("info", None)
2322
dataset.pop("licenses", None)
2423
for img in dataset["images"]:
2524
img.pop("license", None)
@@ -147,7 +146,7 @@ def load_image(self, index):
147146

148147
img_file = os.path.join(self.data_dir, self.name, file_name)
149148

150-
img = cv2.imread(img_file, cv2.IMREAD_COLOR_BGR if self.num_channels == 3 else cv2.IMREAD_GRAYSCALE)
149+
img = cv2.imread(img_file, cv2.IMREAD_COLOR if self.num_channels == 3 else cv2.IMREAD_GRAYSCALE)
151150
assert img is not None, f"file named {img_file} not found"
152151

153152
return img

yolox/data/datasets/voc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def __init__(
108108
dataset_name="VOC0712",
109109
cache=False,
110110
cache_type="ram",
111+
num_channels=3
111112
):
112113
self.root = data_dir
113114
self.image_set = image_sets
@@ -131,6 +132,7 @@ def __init__(
131132
):
132133
self.ids.append((rootpath, line.strip()))
133134
self.num_imgs = len(self.ids)
135+
self.num_channels = num_channels
134136

135137
self.annotations = self._load_coco_annotations()
136138

@@ -184,7 +186,7 @@ def load_resized_img(self, index):
184186

185187
def load_image(self, index):
186188
img_id = self.ids[index]
187-
img = cv2.imread(self._imgpath % img_id, cv2.IMREAD_COLOR)
189+
img = cv2.imread(self._imgpath % img_id, cv2.IMREAD_COLOR if self.num_channels == 3 else cv2.IMREAD_GRAYSCALE)
188190
assert img is not None, f"file named {self._imgpath % img_id} not found"
189191

190192
return img

0 commit comments

Comments
 (0)