Skip to content

Commit cf574a4

Browse files
committed
Updated Model and fixed error
1 parent a0af3c9 commit cf574a4

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

Section #4 - Capstone/simpsons.py

+32-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
import matplotlib.pyplot as plt
1414
from tensorflow.keras.utils import to_categorical
1515
from tensorflow.keras.callbacks import LearningRateScheduler
16+
from tensorflow.keras.models import Sequential
17+
from tensorflow.keras.layers import Dense, Flatten, Dropout, Conv2D, MaxPooling2D
18+
from tensorflow.keras.optimizers.legacy import SGD
1619

1720
IMG_SIZE = (80,80)
1821
channels = 1
@@ -59,7 +62,7 @@
5962

6063

6164
# Creating train and validation data
62-
x_train, x_val, y_train, y_val = caer.train_test_split(featureSet, labels, val_ratio=.2)
65+
x_train, x_val, y_train, y_val = caer.train_val_split(featureSet, labels, val_ratio=.2)
6366

6467
# Deleting variables to save memory
6568
del train
@@ -76,14 +79,38 @@
7679
train_gen = datagen.flow(x_train, y_train, batch_size=BATCH_SIZE)
7780

7881
# Create our model (returns the compiled model)
79-
model = canaro.models.createSimpsonsModel(IMG_SIZE=IMG_SIZE, channels=channels, output_dim=len(characters),
80-
loss='binary_crossentropy', decay=1e-7, learning_rate=0.001, momentum=0.9,
81-
nesterov=True)
82+
output_dim=10
83+
84+
w, h = IMG_SIZE[:2]
85+
86+
model = Sequential()
87+
model.add(Conv2D(32, (3, 3), activation='relu', padding='same', input_shape=(w, h,channels)))
88+
model.add(Conv2D(32, (3, 3), activation='relu'))
89+
model.add(MaxPooling2D(pool_size=(2, 2)))
90+
model.add(Dropout(0.2))
91+
92+
model.add(Conv2D(64, (3, 3), padding='same', activation='relu'))
93+
model.add(Conv2D(64, (3, 3), activation='relu'))
94+
model.add(MaxPooling2D(pool_size=(2, 2)))
95+
model.add(Dropout(0.2))
96+
97+
model.add(Conv2D(256, (3, 3), padding='same', activation='relu'))
98+
model.add(Conv2D(256, (3, 3), activation='relu'))
99+
model.add(MaxPooling2D(pool_size=(2, 2)))
100+
model.add(Dropout(0.2))
101+
102+
model.add(Flatten())
103+
model.add(Dropout(0.5))
104+
model.add(Dense(1024, activation='relu'))
105+
106+
# Output Layer
107+
model.add(Dense(output_dim, activation='softmax'))
82108

83109
model.summary()
84110

85111
# Training the model
86-
112+
optimizer = SGD(learning_rate=0.001, decay=1e-7, momentum=0.9, nesterov=True)
113+
model.compile(loss='binary_crossentropy', optimizer=optimizer, metrics=['accuracy'])
87114
callbacks_list = [LearningRateScheduler(canaro.lr_schedule)]
88115
training = model.fit(train_gen,
89116
steps_per_epoch=len(x_train)//BATCH_SIZE,

0 commit comments

Comments
 (0)