我用Keras训练了一个9类的图像识别(带边界框)模型。验证精度为0.85
我试过使用predict\u类,但是因为模型不是连续的,所以它不起作用。此外,我还尝试将预测数组与按字母顺序排序的标签列表相匹配。但都没用
预测:
kategoriler = ['category0', 'category1', 'category2', 'category3', 'category4', 'category5', 'category6', 'category7', 'category8']
def load_image(img_path, show=False):
img = image.load_img(img_path, target_size=(200, 200))
img_tensor = image.img_to_array(img)
img_tensor = np.expand_dims(img_tensor, axis=0)
img_tensor /= 255.
return img_tensor
def predict_labels (event,context):
img_url = event['imageUrl']
img_id = event['id']
human_id = event['humanId']
img_path = '/tmp/img'
os.system('curl -o ' + img_path + ' ' + img_url)
new_image = load_image(img_path)
# check prediction
pred = model.predict(new_image)
sonuc = kategoriler[np.argmax(pred[0])]
response = {
'id' : img_id,
'humanId' : human_id,
'clothes' : {
'category' : sonuc,
'subCategory' : '-'
},
'pred': str(pred)
}
return json.dumps(response)
我期望输出category6
,但实际输出是0.05920969
目前没有回答
相关问题 更多 >
编程相关推荐