Import numpy Import Skimage.io import Matplotlib.pyplot as plt from keras.models import sequential from Keras.layers Imp
ORT dense from keras.layers import dropout to keras.layers import flatten from keras.layers.convolutional import conv2d From keras.layers.convolutional import maxpooling2d to keras.models import Load_model #if The picture is bigger than 28 *28 'll get below error #ValueError: cannot reshape array of size 775440 into shape (1,28,28,1) image = ' d:\\sthself\\ml \\reshape7.jpg ' Img2 = Skimage.io.imread (image,as_grey=true) skimage.io.imshow (IMG2) plt.show () #img3 is a matrix IMG3 = Numpy.reshape (Img2, (1,28,28,1)). Astype (' float32 ') print (IMG3) # Rebuild the model, do we need to add the layer? Attributeerror: ' Sequential ' object has no attribute ' Load_model ' #If you stored the complete model, not only the weights , in the HDF5 file, then it are as simple as #from keras.models import Load_model #model = Load_model (' model.h5 ') # example S https://stackoverflow.com/questions/35074549/how-to-load-a-model-from-an-hdf5-file-in-keras modeltrained = Load_model (' D:\\works\\ Jetbrians\\pycharmprojects\\trypicture\\my_model.h5 ') # We should get a correct answer is 2 predict = Modeltrained.predi CT (IMG3, verbose=0) #list of predicted labels and their probabilities print (predict[0]) #[0.04785086 0.02547075 0.06954 221 0.03620625 0.01439319 0.03016909 0.03120618 0.00815302 ' 0.70513636 0.03187207] # attributeerror: ' Sequential ' object has no attribute ' prediect_classes ' result = Modeltrained.predict_proba (img3,batch_size=1, verbose=0) print ( Result) print ("TensorFlow Hello word being done")
Numbers that colleagues help write
I wrote the numbers myself.
Program Print Log
Highlights: Our own pictures should be black background white to be recognized
D:\applications\Anaconda3\python.exe d:/works/jetbrians/pycharmprojects/trypicture/showpicture/showpicture.py
Using TensorFlow backend.
2018-03-08 20:43:29.102800:w C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\36\tensorflow\core\platform\cpu_ FEATURE_GUARD.CC:45] The TensorFlow library wasn ' t compiled to use AVX instructions, but this are available on your machi NE and could speed up CPU computations.
2018-03-08 20:43:29.102800:w C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\36\tensorflow\core\platform\cpu_ FEATURE_GUARD.CC:45] The TensorFlow library wasn ' t compiled to use AVX2 instructions, but this are available on your Mach INE and could speed up CPU computations.
[1.17482814e-05 1.08457927e-03 2.43252050e-02 3.06303948e-02
1.07244858e-04 1.54377140e-05 1.01265108e-07 9.38272536e-01
4.20123106e-04 5.13266213e-03]
[[1.17482814e-05 1.08457927e-03 2.43252050e-02 3.06303948e-02
1.07244858e-04 1.54377140e-05 1.01265108e-07 9.38272536e-01
4.20123106e-04 5.13266213e-03]]
TensorFlow Hello Word is done
Process finished with exit code 0