import numpy as np
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Flatten
from keras.layers.convolutional import Conv2D
from keras.layers.convolutional import MaxPooling2D
from keras.preprocessing.image import ImageDataGenerator
import matplotlib.pyplot as plt
np.random.seed(3)
train_datagen = ImageDataGenerator(rescale=1./255)
train_generator = train_datagen.flow_from_directory(
'/content/drive/MyDrive/handwriting_shape/train',
target_size=(24,24),
batch_size = 3,
class_mode='categorical'
)
test_datagen = ImageDataGenerator(rescale=1./255)
test_generator = test_datagen.flow_from_directory(
'/content/drive/MyDrive/handwriting_shape/test',
target_size=(24,24),
batch_size = 3,
class_mode='categorical'
)
model = Sequential()
model.add(Conv2D(32, kernel_size=(3,3), activation = 'relu', input_shape=(24,24,3)))
model.add(Conv2D(64,(3,3),activation = 'relu'))
#model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dense(3,activation='softmax'))
Epoch 49/50
15/15 [==============================] - 1s 43ms/step - loss: 5.2955e-06 - accuracy: 1.0000 - val_loss: 0.2440 - val_accuracy: 0.9333
Epoch 50/50
15/15 [==============================] - 1s 36ms/step - loss: 4.9405e-06 - accuracy: 1.0000 - val_loss: 0.2473 - val_accuracy: 0.9333
--Evaluate--
[0.24732321500778198, 0.9333333373069763]
--predict
{'circle': 0, 'rectangle': 1, 'triangle': 2}
0
0
2
0
2
2
1
1
2
1
1
0
0
2
1