get_openimages_dataset.py 1.1 KB

12345678910111213141516171819
  1. import csv
  2. import os
  3. #select classes you want to download at https://github.com/openimages/dataset/blob/master/dict.csv
  4. CLASS_LIST = ('/m/01g317','/m/04yx4')
  5. img_name = "111111111111"
  6. #download csv from https://storage.googleapis.com/openimages/web/download.html
  7. with open('path\\train-annotations-bbox.csv', newline='') as csvfile:
  8. bboxs = csv.reader(csvfile, delimiter=',', quotechar='|')
  9. for bbox in bboxs:
  10. if bbox[2] in CLASS_LIST:
  11. if img_name != bbox[0]:
  12. if not os.path.isfile("destination_path\\%s.jpg"%bbox[0]):
  13. os.system("gsutil cp gs://open-images-dataset/train/%s.jpg destination_path"%bbox[0])
  14. out_file = open("destination_path\\%s.txt"%bbox[0], 'w')
  15. img_name = bbox[0]
  16. if img_name == bbox[0]:
  17. out_file.write(str(CLASS_LIST.index(bbox[2])) + " " + str(float(bbox[4])+(float(bbox[5])-float(bbox[4]))/2) + " " + str(float(bbox[6])+(float(bbox[7])-float(bbox[6]))/2)+ " " + str(float(bbox[5])-float(bbox[4])) + " " + str(float(bbox[7])-float(bbox[6])) + '\n')