text_plain_output_1.png
from keras.models import Model, load_model

from tensorflow.keras.applications import ResNet50

from tensorflow.keras.applications.resnet50 import ResNet50

from tensorflow.keras.layers import Dense, Flatten, GlobalAveragePooling2D, Dropout

from tensorflow.keras.layers import Dense, Input, Conv2D, MaxPool2D, Flatten ,Activation,Dropout,BatchNormalization

from tensorflow.keras.models import Model

from tensorflow.keras.models import Sequential

from tensorflow.keras.models import Sequential

import matplotlib.pyplot as plt

import tensorflow as tf

import os
import cv2
import pickle
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import tensorflow as tf
from tqdm import tqdm
from sklearn.preprocessing import OneHotEncoder
from sklearn.metrics import confusion_matrix
from keras.models import Model, load_model
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.models import Sequential
from tensorflow.keras import layers
from tensorflow.keras import activations
from tensorflow.keras.layers import Dense, Input, Conv2D, MaxPool2D, Flatten, Activation, Dropout, BatchNormalization
import glob
import skimage
plt.rc('font', size=14)
plt.rc('axes', labelsize=14, titlesize=14)
plt.rc('legend', fontsize=14)
plt.rc('xtick', labelsize=10)
plt.rc('ytick', labelsize=10)

data_dir = '/kaggle/input/rgb-arabic-alphabets-sign-language-dataset-jpg/images_after'
images = tf.keras.utils.image_dataset_from_directory(data_dir, labels='inferred', label_mode='int', class_names=None, color_mode='rgb', batch_size=32, image_size=(256, 256), shuffle=True, seed=123, validation_split=0.2, subset='training', interpolation='bilinear')

data_dir = '/kaggle/input/rgb-arabic-alphabets-sign-language-dataset-jpg/images_after'
images_validation = tf.keras.utils.image_dataset_from_directory(data_dir, labels='inferred', label_mode='int', class_names=None, color_mode='rgb', batch_size=32, image_size=(256, 256), shuffle=True, seed=123, validation_split=0.2, subset='validation', interpolation='bilinear')

class_names = images.class_names
class_names

plt.figure(figsize=(10, 10))
for image, label in images.take(1):
  for i in range(25):
    ax = plt.subplot(5, 5, i +1)
    plt.imshow(image[i].numpy().astype("uint8"))
    plt.title(class_names[label[i]])
    plt.axis("off")

early_stop = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=2, restore_best_weights=True)

from tensorflow.keras.applications.resnet50 import ResNet50
from tensorflow.keras.models import Model
import tensorflow.keras as keras
resnet = ResNet50(include_top=False, weights='imagenet', input_shape=(256, 256, 3), pooling='max')
output = resnet.layers[-1].output
output = tf.keras.layers.Flatten()(output)
resnet = Model(resnet.input, output)
res_name = []
for layer in resnet.layers:
    res_name.append(layer.name)

set_trainable = False
for layer in resnet.layers:
    if layer.name in res_name[-22:]:
        set_trainable = True
    if set_trainable:
        layer.trainable = True
    else:
        layer.trainable = False

from tensorflow.keras.applications import ResNet50
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Flatten, GlobalAveragePooling2D, Dropout
model6 = Sequential()
model6.add(resnet)
model6.add(BatchNormalization())
model6.add(Dense(2048, activation='relu'))
model6.add(Dropout(0.2))
model6.add(Dense(1024, activation='relu'))
model6.add(Dropout(0.2))
model6.add(Dense(512, activation='relu'))
model6.add(Dropout(0.2))
model6.add(Dense(256, activation='relu'))
model6.add(Dropout(0.2))
model6.add(Dense(128, activation='relu'))
model6.add(Dropout(0.2))
model6.add(Dense(64, activation='relu'))
model6.add(Dropout(0.2))
model6.add(Dense(31, activation='softmax'))

model6.summary()

model6.compile(optimizer='adam', loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=False), metrics=['accuracy'])

EPOCHS = 25
BATCH_SIZE = 64
history6 = model6.fit(images, epochs=EPOCHS, batch_size=BATCH_SIZE, verbose=1, validation_data=images_validation, callbacks=[early_stop])