Skip to content

Commit

Permalink
Fix coco_tools errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobholamovic committed Nov 8, 2022
1 parent a4957b2 commit ce7863b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
17 changes: 9 additions & 8 deletions tools/coco_tools/json_AnnoSta.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def check_dir(check_path, show=True):
check_directory = check_path
else:
check_directory = os.path.dirname(check_path)
if not os.path.exists(check_directory):
if len(check_directory) > 0 and not os.path.exists(check_directory):
os.makedirs(check_directory)
if show:
print('make dir:', check_directory)
Expand All @@ -60,7 +60,7 @@ def js_anno_sta(js_path, csv_path, png_shape_path, png_shapeRate_path,
data = json.load(load_f)

df_img = pd.DataFrame(data[image_keyname])
sns.jointplot('height', 'width', data=df_img, kind='hex')
sns.jointplot(y='height', x='width', data=df_img, kind='hex')
plt.close()
df_img = df_img.rename(columns={
"id": "image_id",
Expand All @@ -78,15 +78,15 @@ def js_anno_sta(js_path, csv_path, png_shape_path, png_shapeRate_path,

if png_shape_path is not None:
check_dir(png_shape_path)
sns.jointplot('height', 'width', data=df_merge, kind='hex')
sns.jointplot(y='height', x='width', data=df_merge, kind='hex')
plt.savefig(png_shape_path)
plt.close()
print('png save to', png_shape_path)
if get_relative:
png_shapeR_path = png_shape_path.replace('.png', '_Relative.png')
df_merge['heightR'] = df_merge['height'] / df_merge['image_height']
df_merge['widthR'] = df_merge['width'] / df_merge['image_width']
sns.jointplot('heightR', 'widthR', data=df_merge, kind='hex')
sns.jointplot(y='heightR', x='widthR', data=df_merge, kind='hex')
plt.savefig(png_shapeR_path)
plt.close()
print('png save to', png_shapeR_path)
Expand All @@ -105,23 +105,23 @@ def js_anno_sta(js_path, csv_path, png_shape_path, png_shapeRate_path,

if png_pos_path is not None:
check_dir(png_pos_path)
sns.jointplot('pox_y', 'pox_x', data=df_merge, kind='hex')
sns.jointplot(y='pox_y', x='pox_x', data=df_merge, kind='hex')
plt.savefig(png_pos_path)
plt.close()
print('png save to', png_pos_path)
if get_relative:
png_posR_path = png_pos_path.replace('.png', '_Relative.png')
df_merge['pox_yR'] = df_merge['pox_y'] / df_merge['image_height']
df_merge['pox_xR'] = df_merge['pox_x'] / df_merge['image_width']
sns.jointplot('pox_yR', 'pox_xR', data=df_merge, kind='hex')
sns.jointplot(y='pox_yR', x='pox_xR', data=df_merge, kind='hex')
plt.savefig(png_posR_path)
plt.close()
print('png save to', png_posR_path)
if png_posEnd_path is not None:
check_dir(png_posEnd_path)
df_merge['pox_y_end'] = df_merge['pox_y'] + df_merge['height']
df_merge['pox_x_end'] = df_merge['pox_x'] + df_merge['width']
sns.jointplot('pox_y_end', 'pox_x_end', data=df_merge, kind='hex')
sns.jointplot(y='pox_y_end', x='pox_x_end', data=df_merge, kind='hex')
plt.savefig(png_posEnd_path)
plt.close()
print('png save to', png_posEnd_path)
Expand All @@ -131,7 +131,8 @@ def js_anno_sta(js_path, csv_path, png_shape_path, png_shapeRate_path,
'image_height']
df_merge['pox_x_endR'] = df_merge['pox_x_end'] / df_merge[
'image_width']
sns.jointplot('pox_y_endR', 'pox_x_endR', data=df_merge, kind='hex')
sns.jointplot(
y='pox_y_endR', x='pox_x_endR', data=df_merge, kind='hex')
plt.savefig(png_posEndR_path)
plt.close()
print('png save to', png_posEndR_path)
Expand Down
4 changes: 2 additions & 2 deletions tools/coco_tools/json_ImgSta.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def check_dir(check_path, show=True):
check_directory = check_path
else:
check_directory = os.path.dirname(check_path)
if not os.path.exists(check_directory):
if len(check_directory) > 0 and not os.path.exists(check_directory):
os.makedirs(check_directory)
if show:
print('make dir:', check_directory)
Expand All @@ -51,7 +51,7 @@ def js_img_sta(js_path, csv_path, png_shape_path, png_shapeRate_path,

if png_shape_path is not None:
check_dir(png_shape_path)
sns.jointplot('height', 'width', data=df_img, kind='hex')
sns.jointplot(y='height', x='width', data=df_img, kind='hex')
plt.savefig(png_shape_path)
plt.close()
print('png save to', png_shape_path)
Expand Down
4 changes: 3 additions & 1 deletion tools/coco_tools/json_Split.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@


def get_annno(df_img_split, df_anno):
df_merge = pd.merge(df_img_split, df_anno, on="image_id")
df_merge = pd.merge(
df_img_split, df_anno, on="image_id", suffixes=(None, '_r'))
df_merge = df_merge[[c for c in df_merge.columns if not c.endswith('_r')]]
df_anno_split = df_merge[df_anno.columns.to_list()]
df_anno_split = df_anno_split.sort_values(by='id')
return df_anno_split
Expand Down

0 comments on commit ce7863b

Please sign in to comment.