1

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

字母“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)

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

4

1 回答 1

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

predictImage 函数负责预测相应图像的边界框。但是这个函数不会在图像上绘制边界框,它只是显示不同类的概率。请参阅predictImage 代码

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

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

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

于 2020-03-31T09:17:41.657 回答