Reputation: 57
I'm trying to get an Image Classifier to work. So far the model does seem to work but now every time I want to test an image to see if it is being recognized appropriately I have to do the whole training all over. I'm very new to this but I suppose there should be another way to only test the images without the training right?
I also have one further question concerning the code itself.
if result [0][0] >= 0.5:
prediction = "cogwheel"
else:
prediction = "not a cogwheel"
print(prediction)
I am trying to differentiate between images that represent cogwheels and those that don't. I understand that if the probability is > 0,5 it is a cogwheel and else it is not. But what does [0][0] here mean?
Thank you so much for your help!
Upvotes: 0
Views: 183
Reputation: 14993
Since you are a beginner, you may not know that you actually do not need to retrain the model in order to test :D. Your hunch is right, and we will see down below how you can do that.
You can save the weights of your model in a specific file format. In Keras, it is a file with the extension .hdf5.
from tensorflow.keras.models import load_model
##Do some stuff, train model
model.save(model_name)
##Do some stuff
loaded_model = load_model(model_name)
Please make sure that "model_name" includes .hdf5. For example, "my_model.hdf5".
Although it is not clear what you used to get the result (I assume result = model.predict(sample), where sample is a test sample), the first index corresponds to the class(label) and the second label corresponds to the probability of that specific class.
Test to see result[0][0] (probability of class 0), result[1][0] (probability of class 1).
Upvotes: 5