Dec-08-2020, 04:17 AM
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")