ds.create_tensor('frames', htype = 'sequence[image]', sample_compression = 'jpg')
ds.create_tensor('boxes', htype = 'sequence[bbox]')
ds.create_tensor('ids', htype = 'sequence[]', dtype = 'uint32') # Ids are not uploaded as htype = 'class_labels' because they don't contain information about the class of an object.
ds.boxes.info.update(coords = {'type': 'pixel', 'mode': 'LTWH'}) # Bounding box format is left, top, width, height
# Iterate through each sequence
for sequence in sequences:
# Define root directory for that sequence
root_local = os.path.join(dataset_folder,sequence, 'img1')
# Get a list of all the image paths
img_paths = [os.path.join(root_local, item) for item in sorted(os.listdir(root_local))]
# Read the annotations and convert to dataframe
with open(os.path.join(dataset_folder,sequence, 'gt', 'gt.txt')) as f:
anns = [line.rstrip('\n') for line in f]
anns_df = pd.read_csv(os.path.join(dataset_folder, sequence, 'gt', 'gt.txt'), header = None)
# Get the frames from the annotations and make sure they're of equal length as the images
frames = pd.unique(anns_df[0])
assert len(frames) == len(img_paths)
# Iterate through each frame and add data to sequence
ann_df = anns_df[anns_df[0] == frame] # Find annotations in the specific frame
boxes_seq.append(ann_df.loc[:, [2, 3, 4, 5]].to_numpy().astype('float32')) # Box coordinates are in the 3rd-6th column
ids_seq.append(ann_df.loc[:, 1].to_numpy().astype('uint32')) # ids are in the second column
# Append the sequences to the hub dataset
"frames": [hub.read(path) for path in img_paths],