Skip to content

Instantly share code, notes, and snippets.

View srishilesh's full-sized avatar
🤖

Srishilesh P S srishilesh

🤖
View GitHub Profile
@srishilesh
srishilesh / sample.xml
Created January 23, 2022 16:26
A sample XML for PASCAL VOC dataset
<annotation verified="yes">
<folder>MARMOT_ANNOTATION</folder>
<filename>10.1.1.1.2006_3.bmp</filename>
<path>MARMOT_ANNOTATION/10.1.1.1.2006_3.bmp</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>793</width>
<height>1123</height>
@srishilesh
srishilesh / PASCAL_VOC_Validator.py
Created January 23, 2022 17:09
Validate dataset - PASCAL VOC
import xmltodict
import xml.etree.ElementTree as ET
dataset_file = r'/content/sample.xml' # The path to the XML file
xml_tree = ET.parse(dataset_file) # Parse the XML file
root = xml_tree.getroot() # Find the root element
assert root.tag == 'annotation' or root.attrib['verified'] == 'yes', "PASCAL VOC does not contain a root element" # Check if the root element is "annotation"
assert len(root.findtext('folder')) > 0, "XML file does not contain a 'folder' element"
@srishilesh
srishilesh / COCO_validator.py
Created February 28, 2022 17:08
COCO Dataset validator
import json
coco_file = r'/content/sample.json'
with open(coco_file) as json_file:
coco_data = json.load(json_file)
def assertions(key, values, required_keys, unique_key=None):
unique_key_id_mapper = {}
for value in values:
@srishilesh
srishilesh / sample.json
Created February 28, 2022 17:09
Sample COCO dataset
{
"images": [{
"file_name": "10.1.1.1.2006_3.bmp",
"height": 1123,
"width": 793,
"id": "10.1.1.1.2006_3"
}],
"type": "instances",
"annotations": [{
"area": 4560,