Guest User

Untitled

a guest
Jan 22nd, 2020
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. from keras.models import load_model
  2. import cv2
  3. import numpy as np
  4.  
  5. model = load_model('pneumonia_pred_new.h5')
  6. '''
  7. model.compile(loss='binary_crossentropy',
  8.              optimizer='rmsprop',
  9.              metrics=['accuracy'])
  10. '''
  11. imageee = 'your_image.jpeg'
  12. img = cv2.imread(imageee)
  13. img = cv2.resize(img,(64,64))
  14. img = np.reshape(img,[1,64,64,3])
  15.  
  16. classes = model.predict_classes(img)
  17. probabilities = model.predict_proba(img)
  18. print(classes)
  19.  
  20. from google.colab.patches import cv2_imshow
  21. cvimg = cv2.imread(imageee)
  22. cv2_imshow(cvimg)
  23. if classes == [[1]]:
  24.   pred = 'POSITIVE'
  25. else:
  26.   pred = 'NEGATIVE'
  27.   probabilities = 1 - probabilities
  28.  
  29.  
  30.  
  31. print("------------PREDICTION--------------")
  32. print()
  33. print("PNEUMONIA TEST RESULT : ",pred)
  34. print('The probability of the test being {} is {}% '.format(pred,int(probabilities*100)))
  35. print("------------------------------------")
Add Comment
Please, Sign In to add comment