【问题标题】:Multiple object detection using a custom model in Python and imageai在 Python 和 imageai 中使用自定义模型进行多对象检测
【发布时间】:2020-07-10 17:34:36
【问题描述】:

我已经使用自己的图像数据集训练了自己的模型,以识别图像中的对象,但它似乎无法识别所有对象。我只有 2 个对象(一个人键入特定字母的不同方式的图像)。例如字母“a”和字母“o”,如下所示。

当我在手写文本样本上运行测试代码时,在一定程度上,它确实说明了它的准确率百分比,但没有边界框。这是手写文字的图片:

这是我得到的输出:

我正在使用 imageai 来训练自定义模型。我想知道是否可以使用这个经过训练的模型在手写图像上运行多个对象检测并可能显示边界框?

这是我的工作目录的样子,以防它提供额外的帮助:

这是我用于训练模型的代码 (custom_detector.py):

from imageai.Prediction.Custom import ModelTraining

# Instanciating the model
model_trainer = ModelTraining()
model_trainer.setModelTypeAsResNet()
# Setting our dataset directyory
model_trainer.setDataDirectory("characters")
# training the model
model_trainer.trainModel(num_objects=2, num_experiments=100, enhance_data=True, batch_size=10)

这是我测试训练模型的代码(test.py):

from imageai.Prediction.Custom import CustomImagePrediction
import os

# get the working directory
execution_path = os.getcwd()
print(execution_path)
# instanciate prediction
prediction = CustomImagePrediction()
prediction.setModelTypeAsResNet()

# Set model path
prediction.setModelPath(os.path.join(execution_path, "characters", "models", "myModel.h5"))

# Set JSON path
# This is how the JSON file looks like:
#{
#   "0" : "A",
#   "1" : "O"
#}
prediction.setJsonPath(os.path.join(execution_path, "characters", "json", "model_class.json"))

# Initialize the number of objects you have retrained
prediction.loadModel(num_objects=2)

# run prediction
predictions, probabilities = prediction.predictImage(os.path.join(execution_path, "HandTextTest.jpg"), result_count=2)

# Print each prediction
for eachPrediction, eachProbability in zip(predictions, probabilities):
    print(eachPrediction, " : ", eachProbability)

任何帮助或建议都将受到高度赞赏。

【问题讨论】:

    标签: python machine-learning deep-learning object-detection imageai


    【解决方案1】:
    # run prediction
    predictions, probabilities = prediction.predictImage(os.path.join(execution_path, "HandTextTest.jpg"), result_count=2)
    

    predictImage 函数负责预测对应图像的边界框。但是这个函数不会在图像上绘制边界框,它只是显示不同类的概率。见predictImage code .

    而detectCustomObjectsFromVideo 函数在结果视频帧上绘制边界框并将结果保存在文件中。请参阅detectCustomObjectsFromVideo code

    所以这不是模型能做什么的问题,因为预测函数不支持在图像上绘制边界框。您可以修改代码以在图像上绘制边界框,也可以使用其他包或框架为您提供带边界框的图像。

    如果您有任何问题,请随时发表评论。

    【讨论】:

    • 完美。这个解释很有帮助。我一直在使用 LabelImg 应用程序,但它确实非常耗时,但我设法得到了我正在寻找的结果,只需要对其进行处理并使其更加准确。谢谢,
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-01
    • 2018-07-03
    • 2021-10-18
    • 1970-01-01
    相关资源
    最近更新 更多