Python Forum
Classifying images using trained model
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Classifying images using trained model
#2
I think I figured out the solution:

new_dir = os.path.join(PATH, 'New') # make sure there is at least one class sub-folder

new_dataset = image_dataset_from_directory(new_dir, shuffle=True, batch_size=BATCH_SIZE, image_size=IMG_SIZE)

new_dataset = new_dataset.prefetch(buffer_size=AUTOTUNE)

#Retrieve a batch of images from the test set
image_batch, label_batch = new_dataset.as_numpy_iterator().next()
predictions = model.predict_on_batch(image_batch).flatten()

# Apply a sigmoid since our model returns logits
predictions = tf.nn.sigmoid(predictions)
predictions = tf.where(predictions < 0.5, 0, 1)

print('Predictions:\n', predictions.numpy()) # drop labels as they are meaningless anyway

plt.figure(figsize=(25, 25))
for i in range(25):
  ax = plt.subplot(5, 5, i + 1)
  plt.imshow(image_batch[i].astype("uint8"))
  plt.title(class_names[predictions[i]])
  plt.axis("off")
Reply


Messages In This Thread
Classifying images using trained model - by kiton - Dec-03-2020, 04:57 PM
RE: Classifying images using trained model - by kiton - Dec-08-2020, 04:17 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Multiprocessing with loading well-trained model. (via Python3) Chris2013 0 2,234 Jun-06-2018, 06:48 AM
Last Post: Chris2013

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020