Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # load data
- (X_train, y_train), (X_test, y_test) = cifar10.load_data()
- X_train = X_train.astype('float32')/256
- X_test = X_test.astype('float32')/256
- y_train = keras.utils.to_categorical(y_train)
- y_test = keras.utils.to_categorical(y_test)
- # build a model
- def res_unit(x):
- x_shortcut = x
- x = Conv2D(16, (1, 1), padding='same')(x)
- x = BatchNormalization()(x)
- x = Activation('relu')(x)
- x = Conv2D(16, (3, 3), padding='same')(x)
- x = BatchNormalization()(x)
- x = Activation('relu')(x)
- x = Conv2D(32, (1, 1), padding='same')(x)
- x = BatchNormalization()(x)
- x = Add()([x_shortcut, x])
- x = Activation('relu')(x)
- return x
- X_input = Input((X_train.shape[1:]))
- X = Conv2D(32, (3, 3), padding='same')(X_input)
- X = BatchNormalization()(X)
- X = Activation('relu')(X)
- X = res_unit(X)
- X = res_unit(X)
- X = res_unit(X)
- X = Flatten()(X)
- X = Dense(32)(X)
- X = Activation('relu')(X)
- X = Dense(10)(X)
- X = Activation('softmax')(X)
- model = Model(inputs=X_input, outputs=X)
- model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
- # run model
- model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=5)
Add Comment
Please, Sign In to add comment