current_labels = [] // The list where we collect all ground truth boxes for a given image
for idx, i in enumerate(data):
if current_file == "": // If this is the first image file
current_file = i[0]
current_labels.append(i[1:])
if len(data) == 1: // If there is only one box in the CVS file
self.labels.append(np.stack(current_labels, axis=0))
self.filenames.append(os.path.join(self.images_path, current_file))
else:
if i[0] == current_file: // If this box (i.e. this line of the CSV file) belongs to the current image file
current_labels.append(i[1:])
After Change
with open(self.labels_path, newline="") as csvfile:
csvread = csv.reader(csvfile, delimiter=",")
next(csvread) // Skip the header row.
for row in csvread: // For every line (i.e for every bounding box) in the CSV file...
if self.include_classes == "all" or int(row[self.input_format.index("class_id")].strip()) in self.include_classes: // If the class_id is among the classes that are to be included in the dataset...
box = [] // Store the box class and coordinates here