Advertisement
pdpd123

Untitled

Jul 26th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import matplotlib.image as mpimg
  3. import numpy as np
  4.  
  5. def rgb2gray(rgb):
  6.     return np.dot(rgb[...,:3], [0.299, 0.587, 0.114])
  7.  
  8. FILE = '0.png'
  9. source = rgb2gray(mpimg.imread(FILE))
  10.  
  11. picture = np.zeros([1,784])
  12.  
  13. for i in range(28):
  14.   for j in range(28):
  15.     picture[0][i*28 + j] = source[i][j]
  16.  
  17. result = model.predict(picture)
  18.  
  19. max_val, max_class = 0, 0
  20. for i in range(num_classes):
  21.   if result[0][i] > max_val:
  22.     max_val, max_class = result[0][i], i
  23.  
  24. print(result[0])
  25. print('Result:', max_class, '\n')
  26. print('Picutre from source:')
  27. plt.imshow(mpimg.imread(FILE))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement