model.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:behavioral 作者: gilcarmel 项目源码 文件源码
def train_simple_cnn():
    model = Sequential(name='model')
    shape = X_train[0].shape
    topCropPixels = int(float(shape[0] * 0.3))
    model.add(Cropping2D(cropping=((topCropPixels, 0), (0, 0)), input_shape=shape))

    model.add(Convolution2D(24, 5, 5, subsample=(2, 2), border_mode='same'))
    model.add(MaxPooling2D())
    model.add(Activation('relu'))
    model.add(Dropout(0.4))
    model.add(Convolution2D(36, 3, 3, border_mode='same'))
    model.add(MaxPooling2D())
    model.add(Dropout(0.4))
    model.add(Activation('relu'))
    model.add(Flatten())
    model.add(Dense(100, name="hidden1"))
    model.add(Dropout(0.4))
    model.add(Activation('relu'))
    model.add(Dense(10, name="hidden3"))
    model.add(Activation('relu'))
    model.add(Dense(1, name='output'))

    model.summary()

    model.compile(loss='mse',
                  optimizer=Adam(lr=0.00005),
                  metrics=['mean_absolute_error'])

    history = model.fit(X_train, y_train,
                        batch_size=128, nb_epoch=200,
                        verbose=1, validation_split=0.2,
                        validation_data=(X_test, y_test),
                        shuffle=True)
    print(history)
    return model


# Utility function to write out the cropping layer's output to make sure we're doing it right...
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号