[英]how to model predict in all images in a DB?
我建立了一個模型來進行多類語義分割,已經訓練過了。 但是現在我想預測我的 TEST DB 中已經加載的所有圖像補丁並保存輸出預測補丁以便稍后重新組合為完整圖像......
我使用下面的這段代碼,它運行但不保存輸出預測圖像......運行時指示器會改變行,但我沒有輸出任何內容......有人可以幫助我嗎? 抱歉我的英語不好
img_number = 1
for image in range(test_images.shape[0]):
input_img = [test_images] #(test_images) e [test_images]roda mais nao salva
y_pred = model.predict(input_img)
y_pred_argmax=np.argmax(y_pred, axis=3)
prediction = y_pred_argmax[image]
cv2.imwrite('/content/drive/MyDrive/BD_filtred/ok'+str(img_number)+".png", prediction) #prediciton
img_number +=1
預測測試圖像的示例代碼。
test_images = ['flower3.jpg', 'flower.jpg', 'flower1.jpg', 'flower2.jpg']
for i in test_images:
img = tf.keras.utils.load_img(i, target_size=(img_height, img_width))
img_array = tf.keras.utils.img_to_array(img)
img_array = tf.expand_dims(img_array, 0) # Create a batch
predictions = model.predict(img_array)
score = tf.nn.softmax(predictions[0])
print(
"This image most likely belongs to {} with a {:.2f} percent confidence."
.format(class_names[np.argmax(score)], 100 * np.max(score)))
輸出
This image most likely belongs to tulips with a 99.19 percent confidence.
This image most likely belongs to daisy with a 99.84 percent confidence.
This image most likely belongs to roses with a 98.29 percent confidence.
This image most likely belongs to roses with a 98.61 percent confidence.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.