-
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.
- Loading branch information
Showing
2 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
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,36 @@ | ||
import os | ||
|
||
DATA_DIR = 'data/tiny-imagenet-200/' | ||
VALID_DIR = DATA_DIR + 'val' | ||
|
||
# Create separate validation subfolders for the validation images based on | ||
# their labels indicated in the val_annotations txt file | ||
val_img_dir = os.path.join(VALID_DIR, 'images') | ||
fp = open(os.path.join(VALID_DIR, 'val_annotations.txt'), 'r') | ||
data = fp.readlines() | ||
|
||
# Create dictionary to store img filename (word 0) and corresponding | ||
# label (word 1) for every line in the txt file (as key value pair) | ||
val_img_dict = {} | ||
for line in data: | ||
words = line.split('\t') | ||
val_img_dict[words[0]] = words[1] | ||
fp.close() | ||
|
||
# Create subfolders (if not present) for validation images based on label , | ||
# and move images into the respective folders | ||
for img, folder in val_img_dict.items(): | ||
newpath = (os.path.join(val_img_dir, folder)) | ||
if not os.path.exists(newpath): | ||
os.makedirs(newpath) | ||
if os.path.exists(os.path.join(val_img_dir, img)): | ||
os.rename(os.path.join(val_img_dir, img), os.path.join(newpath, img)) | ||
|
||
# Save class names (for corresponding labels) as dict from words.txt file | ||
class_to_name_dict = dict() | ||
fp = open(os.path.join(DATA_DIR, 'words.txt'), 'r') | ||
data = fp.readlines() | ||
for line in data: | ||
words = line.strip('\n').split('\t') | ||
class_to_name_dict[words[0]] = words[1].split(',')[0] | ||
fp.close() |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
wget -nc http:https://cs231n.stanford.edu/tiny-imagenet-200.zip | ||
unzip tiny-imagenet-200.zip -d data/ | ||
unzip tiny-imagenet-200.zip -d data/ | ||
python modules/base_utils/fix_val.py |