-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats_hw.py
52 lines (44 loc) · 1.16 KB
/
stats_hw.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
# Author: Armit
# Create Time: 2024/03/15
from data import *
from tqdm import tqdm
import matplotlib.pyplot as plt
import imagesize
log_dp = IMG_PATH / 'hw'
log_dp.mkdir(exist_ok=True)
DATASETS_IGNORE = [
'Emotion6Dim7',
'Emotion6VA',
]
for name in DATASETS:
if name in DATASETS_IGNORE: continue
save_fp = log_dp / f'{name}.png'
if save_fp.exists():
print(f'>> ignore {name} due to file exists')
continue
print(f'>> process {name}')
dataset_cls = get_dataset_cls(name)
try:
plt.clf()
plt.figure(figsize=(8, 4))
for idx, (split, cmap) in enumerate(zip(['train', 'valid'], ['blue', 'red'])):
hs, ws = [], []
dataset: BaseDataset = dataset_cls(split)
for fp in tqdm(dataset.get_fps()):
w, h = imagesize.get(fp)
hs.append(h)
ws.append(w)
plt.subplot(120 + idx + 1)
plt.scatter(ws, hs, c=cmap, alpha=0.5, label=split)
plt.xlabel('width')
plt.ylabel('height')
if not hs: continue
plt.tight_layout()
plt.savefig(save_fp)
plt.close()
except KeyboardInterrupt:
exit(-1)
except Exception as e:
print(e)
print(f'>> {name} failed')