[英]Multiple object detection using a custom model in Python and imageai
我已經用自己的圖像數據集訓練了自己的模型,用於圖像中的對象識別,但它似乎無法識別所有對象。 我只有 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)
任何幫助或建議將受到高度贊賞。
# run prediction
predictions, probabilities = prediction.predictImage(os.path.join(execution_path, "HandTextTest.jpg"), result_count=2)
predictImage 函數負責預測相應圖像的邊界框。 但是這個函數不會在圖像上繪制邊界框,它只是顯示不同類別的概率。 請參閱predictImage 代碼。
而detectCustomObjectsFromVideo 函數在結果視頻幀上繪制邊界框並將結果保存在文件中。 請參閱detectCustomObjectsFromVideo 代碼。
所以這不是模型可以做什么的問題,因為預測函數不支持在圖像上繪制邊界框。 您可以修改代碼以在圖像上繪制邊界框,也可以使用其他一些包或框架來為您提供帶有邊界框的圖像。
如果您有任何問題,請隨時發表評論。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.