I'm just getting started at learning how to use image recognition so I started by following this tutorial a few days ago. Since I'm new at this, I decided to use the same group of images that's used in the tutorial to make sure I'm doing everything right. After spending a while getting it to train a model, I've been trying to run tests on different images I've downloaded from Google to see if any of the tests work. So far the prediction model only gives the exact same false positive (shown below) no matter what image I show it.
-- After Classification --
mechanic : 100.0
waiter : 0.0
police : 0.0
pilot : 0.0
judge : 0.0
firefighter : 0.0
farmer : 0.0
engineer : 0.0
doctor : 0.0
chef : 0.0
In this specific test I was running it against an image of a doctor in scrubs, but it's had the same reaction when shown firefighters and police officers and I don't have a clue what I'm doing wrong. I've attempted to search for other people with similar problems, but my Google skills seem to be failing me. I also attempted to build and test the same model on 3 different computers with the same result each time. Here's all of the code I'm using:
from imageai.Classification.Custom import ClassificationModelTrainer
from imageai.Classification.Custom import CustomImageClassification
# === Variables === #
modelDir = "idenprof-jpg\\idenprof\\models\\model_ex-009_acc-0.658504.h5"
jsonDir = "idenprof-jpg\\idenprof\\json\\model_class.json"
imageToTestDir = "doctorImg.jpg"
def Train(trainDirectory_):
model_trainer = ClassificationModelTrainer()
model_trainer.setModelTypeAsResNet50()
model_trainer.setDataDirectory(trainDirectory_)
model_trainer.trainModel(num_objects=10, num_experiments=200, enhance_data=True, batch_size=16, show_network_summary=True)
def Test(modelDir_, jsonDir_, imageToTestDir_):
prediction = CustomImageClassification()
prediction.setModelTypeAsResNet50()
prediction.setModelPath(modelDir_)
prediction.setJsonPath(jsonDir_)
prediction.loadModel(num_objects = 10, classification_speed = 'fastest')
predictions, probabilities = prediction.classifyImage(imageToTestDir_, result_count = 10)
print("-- After Classification --")
for eachPrediction, eachProbability in zip(predictions, probabilities):
print(eachPrediction, " : ", eachProbability)
#Train("idenprof-jpg\\idenprof")
Test(modelDir, jsonDir, imageToTestDir)
Using Python v3.8, ImageAI v2.1.6, Keras v2.6.0, TensorFlow v2.6.0. All of the file paths are correct (I shortened them in this code snippet) and no errors are being thrown so it should be logic error. Also, I know that the model I have here just has a 65.85% accuracy, but I don't think that's where the problem lies either because I made a model yesterday with only 2 object types and 97% accuracy but it would only output the same "100.0 match" false positive no matter what image I showed it. If I had to guess, there might be something about the tutorial that's out of date and not working (or at least not working the way it used to), but I have no idea what it could be. If anyone might know what it could be, I'd be incredibly grateful! Thanks