Skip to content

Commit 95ae284

Browse files
committed
Add simple script to inspect feature files
1 parent 5d405c7 commit 95ae284

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'''
2+
This script will open a feature file (.h5) and show a 3x3 grid of images.
3+
This tool is useful if you suspect that features are not extracted properly, for example due to erroneous mask values/indexing.
4+
'''
5+
6+
import h5py
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
import sys
10+
11+
if len(sys.argv) > 0:
12+
feature_file = sys.argv[1]
13+
else:
14+
feature_file = "features.h5"
15+
16+
# open the file
17+
with h5py.File(feature_file, "r") as f:
18+
# get the images dataset
19+
images = f["images"]
20+
# get the first 9 images
21+
images = images[:9]
22+
# reshape the images to 3x3
23+
#images = np.reshape(images, (3,3,100,100,3))
24+
# transpose the images to 3x3
25+
#images = np.transpose(images, (0,2,1,3,4))
26+
# flatten the images to 9x100x100x3
27+
#images = np.reshape(images, (9,100,100,3))
28+
29+
# hide axis from pyplot
30+
plt.axis('off')
31+
32+
# plot the images
33+
for i in range(9):
34+
plt.subplot(3,3,i+1)
35+
plt.imshow(images[i])
36+
plt.show()
37+
print(f"Image {i+1} is {images[i].shape}")

0 commit comments

Comments
 (0)