-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompute_average_resolution.py
More file actions
36 lines (30 loc) · 1.17 KB
/
compute_average_resolution.py
File metadata and controls
36 lines (30 loc) · 1.17 KB
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
29
30
31
32
33
34
35
36
import os
from skimage.io import imread, imshow, show
from typing import List
path = './tmp/Food_101_Dataset/food-101/'
def get_files_recursive(filepath: str) -> List[str]:
# Get the list of all files in directory tree at given path
listOfFiles = list()
for i, (dirpath, dirnames, filenames) in enumerate(os.walk(filepath)):
if i%250 == 0:
print(i, 'folders sprocessed')
listOfFiles += [os.path.join(dirpath, file) for file in filenames]
print(f'Found {len(listOfFiles)} files')
cleaned = [file for file in listOfFiles if file.endswith('.jpg')]
print(f'{len(cleaned)} of whitch are actually jpg-files ({round(len(cleaned) / len(listOfFiles), 5)*100}%)')
return cleaned
cleaned = get_files_recursive(path)
ressult = []
for i, img in enumerate(cleaned):
if i%1000 == 0:
print(100*round(i / len(cleaned), 5), '% processed', i, 'of', len(cleaned), 'Images')
try:
im = imread(img, as_gray=True)
#imshow(im)
#show()
#break
ressult.append(list(im.shape))
except:
print('Error reading ', img)
import numpy as np
print('Average Resolution is', np.mean(ressult, axis=0))