-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated json files to COCO format, updated the height and width for s…
…ome images
- Loading branch information
Showing
7 changed files
with
45 additions
and
41 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Large diffs are not rendered by default.
Oops, something went wrong.