-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfood101Work.py
28 lines (24 loc) · 992 Bytes
/
food101Work.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
@author: Robert Kamunde
"""
# Helper method to split dataset into train and test folders
from shutil import copy
from collections import defaultdict
import os
#function to help preparing tarining set and test set....ONLY RUN ONCE
def prepare_data(filepath, src,dest):
classes_images = defaultdict(list)
with open(filepath, 'r') as txt:
paths = [read.strip() for read in txt.readlines()]
for p in paths:
food = p.split('/')
classes_images[food[0]].append(food[1] + '.jpg')
for food in classes_images.keys():
print("\nCopying images into ",food)
if not os.path.exists(os.path.join(dest,food)):
os.makedirs(os.path.join(dest,food))
for i in classes_images[food]:
copy(os.path.join(src,food,i), os.path.join(dest,food,i))
print("Copying Done!")
prepare_data('food-101/meta/train.txt', 'food-101/images', 'food-101/train')
prepare_data('food-101/meta/test.txt', 'food-101/images', 'food-101/test')