-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
61 lines (44 loc) · 1.47 KB
/
util.py
File metadata and controls
61 lines (44 loc) · 1.47 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import matplotlib.pyplot as plt
def show_images(images: list, axes: bool = True, **kwargs) -> None:
n = len(images)
cols = int(n ** 0.5)
rows = n // cols + (1 if n % cols > 0 else 0)
fig = plt.figure(figsize=(8, 8))
for i in range(n):
ax = fig.add_subplot(rows, cols, i + 1)
if not axes:
ax.axis('off')
plt.imshow(images[i], **kwargs)
plt.show()
def dataset_stats(images: list, labels: list) -> None:
min_size = 100000
max_size = 0
x, y = 0, 0
for image in images:
size = image.shape[0] * image.shape[1]
if size < min_size:
min_size = size
min_height = image.shape[0]
min_width = image.shape[1]
elif size > max_size:
max_size = size
max_height = image.shape[0]
max_width = image.shape[1]
x += image.shape[0]
y += image.shape[1]
x /= len(images)
y /= len(images)
print(f'Number of images: {len(images)}')
print(f'Min size: {min_height}x{min_width}px')
print(f'Max size: {max_height}x{max_width}px')
print(f'Average size: {x}x{y}px')
def hist_values(labels: list, classes: int, print_coordinates=False) -> list:
counts = [0 for _ in range(classes)]
for label in labels:
counts[int(label)] += 1
if print_coordinates:
print('coordinates{')
for i in range(classes):
print(f'({i}, {counts[i]})')
print('};')
return counts