Spaces:
Running
Running
| 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 |