我用Keras训练了9类图像识别(带有边界框)模型。验证精度为0.85
我曾尝试使用预报类,但由于该模型不是顺序的,因此无法正常工作。另外,我尝试将匹配预测数组匹配到带有按字母顺序排序的标签的列表。但是它都行不通。
预测:
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