-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmake_predictions.py
More file actions
32 lines (27 loc) · 909 Bytes
/
make_predictions.py
File metadata and controls
32 lines (27 loc) · 909 Bytes
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
import keras
from keras.models import load_model
import numpy as np
from PIL import Image
import sys
def predict(model, input_image):
predictions = model.predict(input_image)
return predictions
def image_process(filename):
im=Image.open(filename)
im = im.resize((100,100),Image.ANTIALIAS)
w, h = im.size
cropped_image = im.crop((10, 10, w-10, h-10))
numpy_arr = np.asarray(cropped_image)
return numpy_arr
input_file = sys.argv[1]
model = load_model('melanoma.h5')
image = image_process(input_file)
image = np.reshape(image, (1,image.shape[0], image.shape[1], image.shape[2]))
prediction = predict(model, image)
percentage = np.max(prediction) * 100
pred_class = np.argmax(prediction)
if pred_class == 0:
output_string = "Benign"
else:
output_string = "Malignant"
print "From the looks of this patch of skin, it is {} with {}%".format(output_string,percentage)