Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3. test_image = cv2.imread(r'C:UsersShahinur ShakibDownloadsspyder2Datasetstest_setDogelephant.jpg')
  4.  
  5. test_image=cv2.cvtColor(test_image, cv2.COLOR_BGR2GRAY)
  6. test_image=cv2.resize(test_image,(200,200))
  7. test_image = np.array(test_image)
  8. test_image = test_image.astype('float32')
  9. test_image /= 255
  10. print (test_image.shape)
  11.  
  12. if img_channels==1:
  13. if K.image_dim_ordering()=='th':
  14. test_image= np.expand_dims(test_image, axis=0)
  15. test_image= np.expand_dims(test_image, axis=0)
  16. print (test_image.shape)
  17. else:
  18. test_image= np.expand_dims(test_image, axis=3)
  19. test_image= np.expand_dims(test_image, axis=0)
  20. print (test_image.shape)
  21. else:
  22. if K.image_dim_ordering()=='th':
  23. test_image=np.rollaxis(test_image,2,0)
  24. test_image= np.expand_dims(test_image, axis=0)
  25. print (test_image.shape)
  26. else:
  27. test_image= np.expand_dims(test_image, axis=0)
  28. print (test_image.shape)
  29.  
  30. print((model.predict(test_image)))
  31. print(model.predict_classes(test_image))
  32. result=model.predict_classes(test_image)
  33. if(result==0):
  34. print("Cat")
  35. elif(result==1):
  36. print("Dog")
  37. elif(result==2):
  38. print("Elephant")
  39. elif(result==3):
  40. print("Hen")
  41. elif(result==4):
  42. print("Horse")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement