Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import pickle
  2. from os.path import exists
  3.  
  4. import pandas as pd
  5.  
  6. import constants
  7.  
  8.  
  9. def create_annotations_dict():
  10. columns = ['filename', 'xmin', 'ymin', 'xmax', 'ymax', 'label']
  11. annotations_df = pd.read_csv(constants.LABELS_PATH, sep=';', names=columns)
  12. annotations_dict = {}
  13. for index, bbox in annotations_df.iterrows():
  14. image_name = bbox.at['filename'].replace('.ppm', '')
  15. annotations_df.at[index, 'filename'] = image_name
  16. if image_name not in annotations_dict:
  17. annotations_dict[image_name] = []
  18.  
  19. annotations_dict[image_name].append(
  20. list(annotations_df.iloc[index][['xmin', 'ymin', 'xmax', 'ymax', 'label']]))
  21.  
  22. pickle.dump(annotations_dict, open(constants.ANNOTATIONS_DICT, "wb"))
  23. return annotations_dict
  24.  
  25.  
  26. def get_annotations_dict():
  27. if exists(constants.ANNOTATIONS_DICT):
  28. return pickle.load(open(constants.ANNOTATIONS_DICT, "rb"))
  29. else:
  30. return create_annotations_dict()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement