Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from keras.models import Sequential
from keras.layers import Dense, Activation, Flatten
from keras.layers import Convolution2D, MaxPooling2D
from keras.optimizers import Adamax
import numpy as np
from keras.preprocessing.image import ImageDataGenerator
def main():
model = Sequential()
model.add(Convolution2D(32, 3, 3, border_mode='valid', input_shape=(1, 300, 400)))
model.add(Activation('relu'))
model.add(Convolution2D(32, 3, 3))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Convolution2D(64, 3, 3, border_mode='valid'))
model.add(Activation('relu'))
model.add(Convolution2D(64, 3, 3))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Convolution2D(64, 3, 3, border_mode='valid'))
model.add(Activation('relu'))
model.add(Convolution2D(64, 3, 3))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Convolution2D(128, 3, 3, border_mode='valid'))
model.add(Activation('relu'))
model.add(Convolution2D(128, 3, 3))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Convolution2D(128, 3, 3, border_mode='valid'))
model.add(Activation('relu'))
model.add(Convolution2D(128, 3, 3))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(128))
model.add(Activation('relu'))
model.add(Dense(128))
model.add(Activation('relu'))
model.add(Dense(4))
model.add(Activation('linear'))
model.summary()
adam = Adamax()
model.compile(loss='mean_squared_error', optimizer=adam)
X_train = np.zeros((1067, 1, 300, 400), dtype=np.float32)
Y_train = np.zeros((1067, 4), dtype=np.float32)
ret_valid = {}
ret_valid['X'] = np.zeros((356, 1, 300, 400), dtype=np.float32)
ret_valid['y'] = np.zeros((356, 4), dtype=np.float32)
datagen = ImageDataGenerator(featurewise_center=False, featurewise_std_normalization=False)
datagen.fit(X_train)
model.fit_generator(
datagen.flow(X_train, Y_train, batch_size=8),
samples_per_epoch=len(X_train),
nb_epoch=200,
validation_data=(ret_valid['X'], ret_valid['y']))
# model.fit(
# X_train, Y_train, batch_size=8,
# nb_epoch=200,
# validation_data=(ret_valid['X'], ret_valid['y']))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.