Skip to content

Instantly share code, notes, and snippets.

@saurabhpal97
Created May 31, 2019 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saurabhpal97/df345d3ebba15f4b64903eb1eddaaaf3 to your computer and use it in GitHub Desktop.
Save saurabhpal97/df345d3ebba15f4b64903eb1eddaaaf3 to your computer and use it in GitHub Desktop.
from keras.models import Sequential
from keras.layers import Input,Conv2D,BatchNormalization,MaxPooling2D,Dropout,Activation,Flatten
from keras import regularizers
from keras import models
from keras.callbacks import ModelCheckpoint
num_classes = 10
weight_decay = 1e-4
img_input = Input(shape=(32,32,3))
x = Conv2D(32, (3,3), padding='same', input_shape=x_train.shape[1:])(img_input)
x = SqueezeExcite(x,name='se1')
x = Activation('elu')(x)
x = BatchNormalization()(x)
x = Conv2D(32, (3,3), padding='same')(x)
x = SqueezeExcite(x,name='se2')
x = Activation('elu')(x)
x = BatchNormalization()(x)
x = MaxPooling2D(pool_size=(2,2))(x)
x = Dropout(0.2)(x)
x = Conv2D(64, (3,3), padding='same')(x)
x = SqueezeExcite(x,name='se3')
x = Activation('elu')(x)
x = BatchNormalization()(x)
x = Conv2D(64, (3,3), padding='same')(x)
x = SqueezeExcite(x,name='se4')
x = Activation('elu')(x)
x = BatchNormalization()(x)
x = MaxPooling2D(pool_size=(2,2))(x)
x = Dropout(0.3)(x)
x = Conv2D(128, (3,3), padding='same')(x)
x = SqueezeExcite(x,name='se5')
x = Activation('elu')(x)
x = BatchNormalization()(x)
x = Conv2D(128, (3,3), padding='same')(x)
x = SqueezeExcite(x,name='se6')
x = Activation('elu')(x)
x = BatchNormalization()(x)
x = MaxPooling2D(pool_size=(2,2))(x)
x = Dropout(0.4)(x)
x = Flatten()(x)
x = Dense(num_classes, activation='softmax')(x)
model = models.Model(img_input, x, name='test_model')
#define format for saving weight files
filepath="weights-improvement-{epoch:02d}-{val_acc:.2f}.hdf5"
checkpoint = ModelCheckpoint(filepath, monitor='val_acc', verbose=1, save_best_only=True, mode='max')
callbacks_list = [checkpoint]
model.compile(optimizer='adam',loss='categorical_crossentropy',metrics=['accuracy'])
#train the model
model.fit(x_train,y_train,validation_data=(x_val,y_val),epochs=150,callbacks=callbacks_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment