|
13 | 13 | import matplotlib.pyplot as plt
|
14 | 14 | from tensorflow.keras.utils import to_categorical
|
15 | 15 | 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 |
16 | 19 |
|
17 | 20 | IMG_SIZE = (80,80)
|
18 | 21 | channels = 1
|
|
59 | 62 |
|
60 | 63 |
|
61 | 64 | # 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) |
63 | 66 |
|
64 | 67 | # Deleting variables to save memory
|
65 | 68 | del train
|
|
76 | 79 | train_gen = datagen.flow(x_train, y_train, batch_size=BATCH_SIZE)
|
77 | 80 |
|
78 | 81 | # 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')) |
82 | 108 |
|
83 | 109 | model.summary()
|
84 | 110 |
|
85 | 111 | # 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']) |
87 | 114 | callbacks_list = [LearningRateScheduler(canaro.lr_schedule)]
|
88 | 115 | training = model.fit(train_gen,
|
89 | 116 | steps_per_epoch=len(x_train)//BATCH_SIZE,
|
|
0 commit comments