how to model predict in all images in a DB?

Viewed 113

i built a model to do multiclass semantic segmentation, already trained. But now i want to predict all images patches in my TEST DB thats already loaded and save the output prediction patch to put back together as a full image later...

im using this code below, it runs but doesnt save the output predicted image... the indicator changes lines when runnin' but i got nothing on the output... can someone help me? sorry about my bad english

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
1 Answers

Sample code to predict test images.

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)))

Output

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.
Related