0
votes

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!

1
Keras allows you to save the results of trained models and load them again later, I suggest reading the documentation. As for your second question, that's a more general Python question. Have you taken a look at what data type result actually is?AdmiralWen
How do you get result?sentence
I get result by using result = classifier.predict(sample). @AdmiralWen I should read up on the documentation yes, I pretty much stumbled into that whole topic with little to no prior knowledge of tensorflow and only some of python1337_N00B

1 Answers

5
votes

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).