forked from rcmalli/keras-squeezenet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
41 lines (36 loc) · 1.47 KB
/
test.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
import numpy as np
from keras_squeezenet import SqueezeNet
from keras.applications.imagenet_utils import preprocess_input, decode_predictions
from keras.preprocessing import image
import keras
import unittest
class SqueezeNetTests(unittest.TestCase):
def testModelInit(self):
model = SqueezeNet()
self.assertIsNotNone(model)
def testTFwPrediction(self):
keras.backend.set_image_dim_ordering('tf')
model = SqueezeNet()
img = image.load_img('images/cat.jpeg', target_size=(227, 227))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
preds = model.predict(x)
decoded_preds = decode_predictions(preds)
#print('Predicted:', decoded_preds)
self.assertIn(decoded_preds[0][0][1], 'tabby')
#self.assertAlmostEqual(decode_predictions(preds)[0][0][2], 0.82134342)
def testTHPrediction(self):
keras.backend.set_image_dim_ordering('th')
model = SqueezeNet()
img = image.load_img('images/cat.jpeg', target_size=(227, 227))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
preds = model.predict(x)
decoded_preds = decode_predictions(preds)
#print('Predicted:', decoded_preds)
self.assertIn(decoded_preds[0][0][1], 'tabby')
#self.assertAlmostEqual(decode_predictions(preds)[0][0][2], 0.82134342)
if __name__ == '__main__':
unittest.main()