Skip to content

Instantly share code, notes, and snippets.

@salman-ghauri
Created November 30, 2018 05:06
Show Gist options
  • Save salman-ghauri/7c09137671928e935c81474cbf351d50 to your computer and use it in GitHub Desktop.
Save salman-ghauri/7c09137671928e935c81474cbf351d50 to your computer and use it in GitHub Desktop.
s = class_descriptions[class_descriptions['class']\
.isin(classes)]\
.set_index('name').T.to_dict()
train_df = pd.DataFrame(columns=['FileName', 'XMin', 'XMax',
'YMin', 'YMax',
'ClassName'])
# Find boxes in each image and put them in a dataframe
train_imgs = os.listdir(train_path)
train_imgs = [name[0:16] for name in train_imgs\
if not name.startswith('.')]
df = annotations_bbox[annotations_bbox.ImageID\
.isin(train_imgs)]
df = df[df.LabelName.isin(label_names)]
dd = df.groupby("ImageID")
for ii in train_imgs:
cc = dd.get_group(ii)
for index, row in cc.iterrows():
train_df = train_df.append({'FileName': '{}.jpg'\
.format(ii),
'XMin': row['XMin'],
'XMax': row['XMax'],
'YMin': row['YMin'],
'YMax': row['YMax'],
'ClassName': \
s[row['LabelName']]['class']},
ignore_index=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment