-
Notifications
You must be signed in to change notification settings - Fork 1
/
model.py
36 lines (30 loc) · 1.13 KB
/
model.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
# dependencies
import numpy as np
from PIL import Image
import tensorflow as tf
from tensorflow.keras import models
print("Version: ", tf.__version__) # Check tf version
print("GPU is",
"available" if tf.config.experimental.list_physical_devices("GPU") else "NOT AVAILABLE") # Check GPU status
physical_devices = tf.config.experimental.list_physical_devices('GPU') # Config GPU
tf.config.experimental.set_memory_growth(physical_devices[0], True)
class Model:
def __init__(self):
pass
# Image Processing
def process(self, image):
img = Image.fromarray(image)
img_array = np.asarray(img)
img_normalized = img_array / 255.0
img_nparray = np.asarray(img_normalized).astype('float16')
img_dim = np.expand_dims(img_nparray, axis=0)
return img_dim
# Model
def create_model(self):
model = models.load_model('model.h5')
return model
# Predictions
def predictor(self, model, img):
prediction = model.predict(img)
#return np.argmax(prediction[0])
return prediction[0][0], prediction[0][1]