|
16 | 16 |
|
17 | 17 | batch_size = 100
|
18 | 18 | nb_classes = 10
|
19 |
| -nb_epoch = 300 |
| 19 | +nb_epoch = 200 |
20 | 20 |
|
21 | 21 | img_rows, img_cols = 32, 32
|
22 | 22 | img_channels = 3
|
|
25 | 25 | alpha = 1
|
26 | 26 | depth_multiplier = 1
|
27 | 27 |
|
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) |
29 | 29 | print("Model created")
|
30 | 30 |
|
31 | 31 | model.summary()
|
32 | 32 |
|
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 |
34 | 34 | model.compile(loss='categorical_crossentropy', optimizer=optimizer, metrics=["accuracy"])
|
35 | 35 | print("Finished compiling")
|
36 | 36 | print("Building model...")
|
|
40 | 40 | trainX = trainX.astype('float32')
|
41 | 41 | testX = testX.astype('float32')
|
42 | 42 |
|
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) |
45 | 53 |
|
46 | 54 | Y_train = np_utils.to_categorical(trainY, nb_classes)
|
47 | 55 | Y_test = np_utils.to_categorical(testY, nb_classes)
|
|
65 | 73 | print("Model loaded.")
|
66 | 74 |
|
67 | 75 | 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) |
69 | 77 |
|
70 | 78 | 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 | + |
72 | 81 |
|
73 | 82 | callbacks = [lr_reducer, model_checkpoint]
|
74 | 83 |
|
|
77 | 86 | epochs=nb_epoch,
|
78 | 87 | callbacks=callbacks,
|
79 | 88 | 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) |
81 | 90 |
|
82 | 91 | yPreds = model.predict(testX)
|
83 | 92 | yPred = np.argmax(yPreds, axis=1)
|
|
0 commit comments