-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.py
44 lines (31 loc) · 1.17 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
42
43
44
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import tensorflow as tf
__author__ = "Alexander Soroka"
__copyright__ = "L2labs, LLC [email protected]"
__year__ = "2020"
def main():
# Parse application arguments
args = argparse.ArgumentParser()
args.add_argument(
'-m', '--model', type=str, default='pretrained',
help='Pretrained model directory path'
)
args.add_argument('image', type=str, help='Image to be processed')
args = args.parse_args()
# Load model first
model = tf.keras.models.load_model(args.model)
# load image
image = tf.keras.preprocessing.image.load_img(
args.image, target_size=[224, 224]
)
image = tf.keras.preprocessing.image.img_to_array(image) / 255.
# Add batch dimension
image = tf.expand_dims(image, 0)
# Model output is multidimensional array with first axis for image number in batch,
# and second for probabilities of two classes: PPE is not presented and PPE is presented
print('Probability of PPE presence: {}'.format(model(image).numpy()[0, 1]))
if __name__ == "__main__":
main()