application_vnd.jupyter.stderr_output_2.png text_plain_output_3.png text_plain_output_1.png
from tensorflow.keras import layers

from tensorflow.keras.preprocessing.image import ImageDataGenerator

import tensorflow as tf

import tensorflow_hub as hub

train_dir = '../input/yoga-poses-dataset/DATASET/TRAIN'
test_dir = '../input/yoga-poses-dataset/DATASET/TEST'

from tensorflow.keras.preprocessing.image import ImageDataGenerator
IMAGE_SHAPE = (224, 224)
BATCH_SIZE = 32
train_datagen = ImageDataGenerator(rescale=1 / 255.0)
test_datagen = ImageDataGenerator(rescale=1 / 255.0)
train_data = train_datagen.flow_from_directory(train_dir, target_size=IMAGE_SHAPE, batch_size=BATCH_SIZE, class_mode='categorical')
test_data = test_datagen.flow_from_directory(test_dir, target_size=IMAGE_SHAPE, batch_size=BATCH_SIZE, class_mode='categorical')

import tensorflow_hub as hub
from tensorflow.keras import layers
efficientnet_url = 'https://tfhub.dev/tensorflow/efficientnet/b0/feature-vector/1'
resnet_url = 'https://tfhub.dev/google/imagenet/resnet_v2_50/feature_vector/5'
def create_model(model_url, num_classes=5):
    feature_extractor_layer = hub.KerasLayer(model_url, trainable=False, name='feature_extraction_layer', input_shape=IMAGE_SHAPE + (3,))
    model = tf.keras.Sequential([feature_extractor_layer, layers.Dense(num_classes, activation='softmax', name='output_layer')])
    return model

resnet_model = create_model(resnet_url, num_classes=train_data.num_classes)
resnet_model.compile(loss=tf.keras.losses.CategoricalCrossentropy(), optimizer=tf.keras.optimizers.Adam(), metrics=['accuracy'])
resnet_history = resnet_model.fit(train_data, epochs=5, steps_per_epoch=len(train_data), validation_data=test_data, validation_steps=len(test_data))

efficientnet_model = create_model(efficientnet_url, num_classes=train_data.num_classes)
efficientnet_model.compile(loss=tf.keras.losses.CategoricalCrossentropy(), optimizer=tf.keras.optimizers.Adam(), metrics=['accuracy'])
efficientnet_history = efficientnet_model.fit(train_data, epochs=5, steps_per_epoch=len(train_data), validation_data=test_data, validation_steps=len(test_data))