Skip to content

Instantly share code, notes, and snippets.

@xiaoli
Created June 10, 2023 13:30
Show Gist options
  • Save xiaoli/e136b5d63b82854b06066218038f2d90 to your computer and use it in GitHub Desktop.
Save xiaoli/e136b5d63b82854b06066218038f2d90 to your computer and use it in GitHub Desktop.
Filtering bdd100k dataset by timeofday attribute
import json
def filter_train():
data = []
with open('bdd100k_labels/bdd100k_labels_images_train.json') as f:
train = json.load(f)
for image in train:
if image['attributes']['timeofday'] == 'daytime':
data.append(image)
new_file = open('bdd100k_labels/bdd100k_labels_images_train_daytime.json', 'w')
json.dump(data, new_file, indent=4)
new_file.close()
def filter_val():
data = []
with open('bdd100k_labels/bdd100k_labels_images_val.json') as f:
train = json.load(f)
for image in train:
if image['attributes']['timeofday'] == 'daytime':
data.append(image)
new_file = open('bdd100k_labels/bdd100k_labels_images_val_daytime.json', 'w')
json.dump(data, new_file, indent=4)
new_file.close()
if __name__ == '__main__':
filter_train()
filter_val()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment