Skip to content

Commit

Permalink
Updated json files to COCO format, updated the height and width for s…
Browse files Browse the repository at this point in the history
…ome images
  • Loading branch information
bmlutz committed Jul 16, 2021
1 parent 00dae2d commit cb8079c
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 41 deletions.
36 changes: 0 additions & 36 deletions cnn/image_size.py

This file was deleted.

File renamed without changes.
44 changes: 44 additions & 0 deletions cnn/json_tools/image_size.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os
from PIL import Image
from pathlib import Path
import json

img_dir = './sherd_datasets/validation/'

# opening json file in read mode
json_file = open('./sherd_datasets/validation/val_annotations_coco.json', 'r')

# converting json file to python dictionary
data = json.load(json_file)

# closing json file
json_file.close()
print('json_file closed\n')

# this loop iterates the jpg files
pathlist = Path(img_dir).glob('*.jpg')
for path in pathlist:
path_str = str(path)
img = Image.open(path)
for i in data['images']:
if i['file_name'] == path_str[24:]:
i['width'] = img.size[0]
i['height'] = img.size[1]

# this loop iterates the png files
pathlist = Path(img_dir).glob('*.png')
for path in pathlist:
path_str = str(path)
img = Image.open(path)
for i in data['images']:
if i['file_name'] == path_str[24:]:
i['width'] = img.size[0]
i['height'] = img.size[1]

# opening json file in write mode and overwriting data
json_file = open('./sherd_datasets/validation/val_annotations_coco.json', 'w')
print('\nvia.json file opened\n')
json.dump(data, json_file)
print('via.json file overwritten\n')
json_file.close()
print('via.json file closed\n')
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 1 addition & 5 deletions cnn/sherd_datasets/training/train_annotations_coco.json

Large diffs are not rendered by default.

0 comments on commit cb8079c

Please sign in to comment.