Skip to content

Instantly share code, notes, and snippets.

@Akash-Rawat
Created July 13, 2021 05:03
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 Akash-Rawat/d67bc1cce20694831f21ea49326e1ada to your computer and use it in GitHub Desktop.
Save Akash-Rawat/d67bc1cce20694831f21ea49326e1ada to your computer and use it in GitHub Desktop.
def load_data():
datasets = ['Pedestrian-Detection/Train/Train', 'Pedestrian-Detection/Test/Test', 'Pedestrian-Detection/Val/Val']
output = []
for dataset in datasets:
imags = []
labels = []
directoryA = dataset +"/Annotations"
directoryIMG = dataset +"/JPEGImages/"
file = os.listdir(directoryA)
img = os.listdir(directoryIMG)
file.sort()
img.sort()
i = 0
for xml in file:
xmlf = os.path.join(directoryA,xml)
dom = ElementTree.parse(xmlf)
vb = dom.findall('object')
label = vb[0].find('name').text
labels.append(class_names_label[label])
img_path = directoryIMG + img[i]
curr_img = cv2.imread(img_path)
curr_img = cv2.resize(curr_img, size)
imags.append(curr_img)
i +=1
imags = np.array(imags, dtype='float32')
imags = imags / 255
labels = np.array(labels, dtype='int32')
output.append((imags, labels))
return output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment