Skip to content

Instantly share code, notes, and snippets.

@Praveen76
Last active July 29, 2020 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Praveen76/3a10586da18dcf286d2e0309a637b985 to your computer and use it in GitHub Desktop.
Save Praveen76/3a10586da18dcf286d2e0309a637b985 to your computer and use it in GitHub Desktop.
pngPath='C:/Users/PraveenKumar/RetinaNet//maskDetectorJPEGImages/'
annotPath='C:/Users/PraveenKumar/RetinaNet//maskDetectorXMLfiles/'
data=pd.DataFrame(columns=['fileName','xmin','ymin','xmax','ymax','class'])
os.getcwd()
#read All files
allfiles = [f for f in listdir(annotPath) if isfile(join(annotPath, f))]
#Read all pdf files in images and then in text and store that in temp folder
#Read all pdf files in images and then in text and store that in temp folder
for file in allfiles:
#print(file)
if (file.split(".")[1]=='xml'):
fileName='C:/Users/PraveenKumar/RetinaNet/maskDetectorJPEGImages/'+file.replace(".xml",'.jpg')
tree = ET.parse(annotPath+file)
root = tree.getroot()
for obj in root.iter('object'):
cls_name = obj.find('name').text
xml_box = obj.find('bndbox')
xmin = xml_box.find('xmin').text
ymin = xml_box.find('ymin').text
xmax = xml_box.find('xmax').text
ymax = xml_box.find('ymax').text
# Append rows in Empty Dataframe by adding dictionaries
data = data.append({'fileName': fileName, 'xmin': xmin, 'ymin':ymin,'xmax':xmax,'ymax':ymax,'class':cls_name}, ignore_index=True)
data.shape
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment