text_plain_output_1.png
from glob import glob

from keras import layers

from keras.applications.resnet50 import preprocess_input

from keras.applications.vgg16 import VGG16

from keras.layers import Input, Dense

from keras.models import Sequential

from keras.preprocessing.image import ImageDataGenerator, img_to_array, load_img

import matplotlib.pyplot as plt

train_path = '/kaggle/input/signature/signature/Train/'
test_path = '/kaggle/input/signature/signature/Test/'

img = load_img(train_path + 'forged/f138.png')
x = img_to_array(img)
img = load_img(train_path + '/forged/f98.png')
x = img_to_array(img)
numberOfClass = len(glob(train_path + '/*'))

train_data = ImageDataGenerator().flow_from_directory(train_path, target_size=(224, 224), class_mode='binary')
test_data = ImageDataGenerator().flow_from_directory(test_path, target_size=(224, 224), class_mode='binary')

train_datagen = ImageDataGenerator(shear_range=10, zoom_range=0.2, horizontal_flip=True, preprocessing_function=preprocess_input)
train_generator = train_datagen.flow_from_directory(train_path, batch_size=32, class_mode='binary', target_size=(224, 224))
test_datagen = ImageDataGenerator(preprocessing_function=preprocess_input)
test_generator = test_datagen.flow_from_directory(test_path, shuffle=False, class_mode='binary', target_size=(224, 224))

vgg = VGG16()
vgg_layer_list = vgg.layers
model = Sequential()
for i in range(len(vgg_layer_list) - 1):
    model.add(vgg_layer_list[i])
for layers in model.layers:
    layers.trainable = False
model.add(Dense(numberOfClass, activation='softmax'))

model.compile(loss='sparse_categorical_crossentropy', optimizer='SGD', metrics=['accuracy'])
batch_size = 32
history = model.fit_generator(train_data, steps_per_epoch=1600 / batch_size, epochs=5, validation_data=test_data, validation_steps=800 / batch_size)

model.compile(loss='sparse_categorical_crossentropy', optimizer='SGD', metrics=['accuracy'])
batch_size = 32
history = model.fit_generator(train_generator, steps_per_epoch=1600 / batch_size, epochs=5, validation_data=test_generator, validation_steps=800 / batch_size)

plt.figure(figsize=(30, 5))
plt.subplot(121)
plt.suptitle('Model:VGG16 Epoch:5 Optimizer:SDG Veri Çoğaltma:Var')
plt.plot(history.history['accuracy'])
plt.plot(history.history['val_accuracy'])
plt.title('Model doğruluğu')
plt.ylabel('Doğruluk')
plt.xlabel('Epoch')
plt.legend(['Train', 'Test'], loc='upper left')
plt.subplot(122)
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.title('Model kaybı')
plt.ylabel('Kayıp')
plt.xlabel('Epoch')
plt.legend(['Train', 'Test'], loc='upper left')
plt.savefig('SGD_5_1_vgg')
plt.show()