Skip to content

Instantly share code, notes, and snippets.

@dissagaliyeva
Created January 24, 2022 16:22
Show Gist options
  • Save dissagaliyeva/9264455dd07afa4ebf52387d941b8c41 to your computer and use it in GitHub Desktop.
Save dissagaliyeva/9264455dd07afa4ebf52387d941b8c41 to your computer and use it in GitHub Desktop.
import convert as via2coco
# set class index (can be either 0 or 1)
first_class_index = 0
# for those who decided to go with their own annotations
# data_path = '/content/annotations/output/'
# for those who downloaded from github
data_path = '/content/scrapped_data'
for keyword in ['train', 'val']:
input_dir = data_path + '/' + keyword + '/'
input_json = input_dir + 'via_region_data.json'
categories = ['cigarette']
super_categories = ['N/A']
# save the standard as custom_train or custom_val
output_json = input_dir + 'custom_' + keyword + '.json'
print('Converting {} from VIA format to COCO format'.format(input_json))
coco_dict = via2coco.convert(
imgdir=input_dir,
annpath=input_json,
categories=categories,
super_categories=super_categories,
output_file_name=output_json,
first_class_index=first_class_index,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment