Skip to content

Instantly share code, notes, and snippets.

@dissagaliyeva
Created January 23, 2022 18:43
Show Gist options
  • Select an option

  • Save dissagaliyeva/b813e351479d1c36edd93ecd3745292b to your computer and use it in GitHub Desktop.

Select an option

Save dissagaliyeva/b813e351479d1c36edd93ecd3745292b to your computer and use it in GitHub Desktop.
# download the necessary functionality
%cd /content/
!rm -rf VIA2COCO
!git clone https://github.com/woctezuma/VIA2COCO
%cd VIA2COCO/
!git checkout fixes
# set class index (can be either 0 or 1)
first_class_index = 0
import convert as via2coco
data_path = '/content/annotations/output/'
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