OlafenwaMoses / ImageAI

A python library built to empower developers to build applications and systems with self-contained Computer Vision capabilities
https://www.genxr.co/#products
MIT License
8.56k stars 2.19k forks source link

The custom prediction result always points to one result. #150

Closed woshichuanqilz closed 5 years ago

woshichuanqilz commented 5 years ago
  1. To make the train quicker I reduce the num_objects to 2 and batch_size(which solve this issue,

My train code:

    # -*- coding: utf-8 -*-
    from imageai.Prediction.Custom import ModelTraining
    model_trainer = ModelTraining()
    model_trainer.setModelTypeAsResNet()
    model_trainer.setDataDirectory("heros_img")
    model_trainer.trainModel(num_objects=2, num_experiments=50, enhance_data=True, batch_size=7, show_network_summary=True)

test code:

    # -*- coding: utf-8 -*-
    from imageai.Prediction.Custom import CustomImagePrediction
    import os
    execution_path = os.getcwd()
    prediction = CustomImagePrediction()
    prediction.setModelTypeAsResNet()
    prediction.setModelPath(os.path.join(execution_path, "model_ex-050_acc-0.476190.h5"))
    prediction.setJsonPath(os.path.join(execution_path, "model_class.json"))
    prediction.loadModel(num_objects=2)
    predictions, probabilities = prediction.predictImage(os.path.join(execution_path, "test.png"), result_count=5)
    for eachPrediction, eachProbability in zip(predictions, probabilities):
        print(eachPrediction + " : " + eachProbability)

Whatever image I put in always give one test of one result, like, apple always be 99%+: apple : 99.97028708457947 banana : 0.02971168141812086

  1. I just crop the image with the apple, is it can predict with large background?
  2. After training I get so many h5 files which one should I use?

My goal is to use the imageai to recognize the heros in dota. Because dota images is much simpler than the real world, I guess less train will be work. One hero just has several images from some visual angles. Am I right, hope can get some advice from you, thank you ~

LittleOrangeC commented 5 years ago

For your question #3 I believe you should use the .h5 file with the highest accuracy (acc) score.

OlafenwaMoses commented 5 years ago

How many images did you use to train your model? It is paramount that your training images for each type of objects should be up to 500 numbers or more to ensure your generated models can predict new images correctly.

andersffs commented 5 years ago

Getting the same error with >900 train images.