-
Notifications
You must be signed in to change notification settings - Fork 0
/
npy_to_jpg.py
34 lines (29 loc) · 919 Bytes
/
npy_to_jpg.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
#%%
import os
import numpy as np
from PIL import Image
from tqdm import tqdm
import matplotlib.pyplot as plt
# %%
img_name = '2007_000129'
npys_dir = 'attention_maps_progression/split-10-30-30-30/fold0'
save_dir = 'attention_maps_progression/split-10-30-30-30/fold0-pngs'
#%%
fnames = os.listdir(npys_dir)
fnames = sorted([file for file in fnames if img_name in file], key=lambda x: (len(x), x))
# arrs = [np.load(os.path.join(npys_dir, npy)) for npy in fnames]
#%%
for j, fname in enumerate(tqdm(fnames)):
arr = np.load(os.path.join(npys_dir, fname))
fig, axs = plt.subplots(2,3, figsize=(9,6))
axs = axs.flatten()
for h in range(6):
axs[h].imshow(arr[h])
axs[h].axis('off')
plt.suptitle(fname[:-4])
plt.tight_layout()
plt.savefig(os.path.join(save_dir, fname[:-4]+'.png'),
bbox_inches='tight',
pad_inches=0)
plt.close()
# %%