Skip to content

Commit 34251e4

Browse files
committed
Added CIFAR 10 weights
1 parent d656757 commit 34251e4

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

cifar10.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
batch_size = 100
1818
nb_classes = 10
19-
nb_epoch = 300
19+
nb_epoch = 200
2020

2121
img_rows, img_cols = 32, 32
2222
img_channels = 3
@@ -25,12 +25,12 @@
2525
alpha = 1
2626
depth_multiplier = 1
2727

28-
model = MobileNets(img_dim, alpha=1, depth_multiplier=1, classes=nb_classes)
28+
model = MobileNets(img_dim, alpha=1, depth_multiplier=1, classes=nb_classes, weights=None)
2929
print("Model created")
3030

3131
model.summary()
3232

33-
optimizer = Adam(lr=1e-3) # Using Adam instead of SGD to speed up training
33+
optimizer = Adam(lr=5e-4) # Using Adam instead of SGD to speed up training
3434
model.compile(loss='categorical_crossentropy', optimizer=optimizer, metrics=["accuracy"])
3535
print("Finished compiling")
3636
print("Building model...")
@@ -40,8 +40,16 @@
4040
trainX = trainX.astype('float32')
4141
testX = testX.astype('float32')
4242

43-
trainX /= 255.
44-
testX /= 255.
43+
44+
def preprocess(x):
45+
x /= 255.
46+
x -= 0.5
47+
x *= 2.
48+
return x
49+
50+
51+
trainX = preprocess(trainX)
52+
testX = preprocess(testX)
4553

4654
Y_train = np_utils.to_categorical(trainY, nb_classes)
4755
Y_test = np_utils.to_categorical(testY, nb_classes)
@@ -65,10 +73,11 @@
6573
print("Model loaded.")
6674

6775
lr_reducer = ReduceLROnPlateau(monitor='val_loss', factor=np.sqrt(0.1),
68-
cooldown=0, patience=10, min_lr=1e-6)
76+
cooldown=0, patience=5, min_lr=1e-6)
6977

7078
model_checkpoint = ModelCheckpoint(weights_file, monitor="val_acc", save_best_only=True,
71-
save_weights_only=True, mode='auto', verbose=True)
79+
save_weights_only=True, mode='max', verbose=True)
80+
7281

7382
callbacks = [lr_reducer, model_checkpoint]
7483

@@ -77,7 +86,7 @@
7786
epochs=nb_epoch,
7887
callbacks=callbacks,
7988
validation_data=(testX, Y_test),
80-
validation_steps=testX.shape[0] // batch_size, verbose=1)
89+
validation_steps=testX.shape[0] // batch_size, verbose=2)
8190

8291
yPreds = model.predict(testX)
8392
yPred = np.argmax(yPreds, axis=1)

mobilenets.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ def __create_mobilenet(classes, img_input, include_top, alpha, depth_multiplier)
196196
return x
197197

198198
if __name__ == "__main__":
199-
model = MobileNets(alpha=1, depth_multiplier=1)
199+
from keras import backend as K
200+
K.set_image_data_format('channels_first')
201+
model = MobileNets(alpha=1, depth_multiplier=1, weights=None)
200202

201203
model.summary()

weights/mobilenet_cifar.h5

12.5 MB
Binary file not shown.

0 commit comments

Comments
 (0)