Spaces:
Running
Running
File size: 886 Bytes
2ff9250 d8a4180 2ff9250 d8a4180 2ff9250 c469f55 c3cd511 d8a4180 |
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 |
import cv2
import numpy as np
import keras.models as models
IMAGE_SIZE = (224, 224)
class_names = ['Tubercolosi', 'No_Tubercolosi', 'Pneumonia', 'No_Pneumonia']
BASE_PATH = './data/'
MODEL = BASE_PATH + 'model/'
def image_predict(numpy_image, model_path):
image = cv2.resize(numpy_image, IMAGE_SIZE)
images = []
images.append(image)
images = np.array(images, dtype='float32')
model = models.load_model(model_path, compile=False)
predictions = model.predict(images) # Vector of probabilities
#pred_labels = np.argmax(predictions, axis= 1)
return predictions#, pred_labels
def image_classification(numpy_image):
model = MODEL + 'medical-image-classification.h5'
labels = image_predict(numpy_image, model)
response = {}
for i, label in enumerate(labels[0]):
response[class_names[i]] = "%.4f" % float(label)
return response |