Skip to content

Instantly share code, notes, and snippets.

@jkmackie
Created October 1, 2022 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkmackie/f4b51bafcb65e65cb398d220870b5b95 to your computer and use it in GitHub Desktop.
Save jkmackie/f4b51bafcb65e65cb398d220870b5b95 to your computer and use it in GitHub Desktop.
from keras.applications.vgg16 import VGG16
#Create dataset. The file_paths method shows train_ds and val_ds are mutually exclusive.
train_ds = tf.keras.utils.image_dataset_from_directory(
'./images/train/',
labels='inferred',
shuffle=True,
seed=8,
image_size=(224, 224),
batch_size=32)
val_ds = tf.keras.utils.image_dataset_from_directory(
'./images/valid/',
labels='inferred',
shuffle=True,
seed=8,
image_size=(224, 224),
batch_size=32)
class_names = train_ds.class_names
plt.figure(figsize=(10, 10))
for images, labels in train_ds.take(1):
for i in range(6):
ax = plt.subplot(3, 3, i + 1)
plt.imshow(images[i].numpy().astype("uint8")) #uint is 0 to 255.
plt.title(class_names[labels[i]]); plt.axis("off");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment