I have built a model and saved its weights as 'first_try.h5' but I am not able to load the model & run it on any random image. My problem is how to use model.predict_generator or model.predict or model.predict_on_batch methods. I have read the documentation, but I need one small example to do so. Sorry, I am new to this. It is a binary classifier.
I am using CNTK as my backend. I am following this tutorial.
Need little help.
EDIT: I am trying the following way, but the output is just [[0.]]
'model.load_weights('first_try.h5')
img = Image.open("data/predict/T160305M-0222c_5.jpg")
a = array(img).reshape(1,512,512,3)
score = model.predict(a, batch_size=32, verbose=0)
print(score)'
I had same problem.
I was not saving the weights properly but now everything seem fine.
Please add the save_weights code so that we can know where the problem is.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed.
Probably you have to normalise the numpy array by 255.
import numpy as np
model.predict(np.expand_dims(img, axis=0))
Let me know if you need a complete example on training, saving model+weight and prediction.
@punnerud where can I get the complete example??
I also encounter the preprocess problem, i am not sure what shall i do in preprocess
Sorry, I have moved most of my work to PyTorch now. Don鈥檛 think I still have the complete example in Keras.
Most helpful comment
Let me know if you need a complete example on training, saving model+weight and prediction.