def train_model(dataset): X = T.tensor4() S = T.tensor3() layers = [] layers.append(ConvPoolLayer( input=X, input_shape=(3, 160, 80), filter_shape=(32, 3, 5, 5), pool_shape=(2, 2), active_func=actfuncs.tanh, flatten=False )) layers.append(ConvPoolLayer( input=layers[-1].output, input_shape=layers[-1].output_shape, filter_shape=(64, 32, 5, 5), pool_shape=(2, 2), active_func=actfuncs.tanh, flatten=False )) layers.append(FullConnLayer( input=layers[-1].output.flatten(2), input_shape=np.prod(layers[-1].output_shape), output_shape=1024, dropout_ratio=0.1, active_func=actfuncs.tanh )) layers.append(FullConnLayer( input=layers[-1].output, input_shape=layers[-1].output_shape, output_shape=37 * 17, dropout_input=layers[-1].dropout_output, active_func=actfuncs.sigmoid )) model = NeuralNet(layers, X, layers[-1].output) model.target = S ''' model.cost = costfuncs.binxent(layers[-1].dropout_output, S.flatten(2)) + \ 1e-3 * model.get_norm(2) model.error = costfuncs.binerr(layers[-1].output, S.flatten(2)) ''' model.cost = costfuncs.weighted_norm2( layers[-1].dropout_output, S.flatten(2), 1.0) + \ 1e-3 * model.get_norm(2) model.error = costfuncs.weighted_norm2( layers[-1].output, S.flatten(2), 1.0) sgd.train(model, dataset, lr=1e-2, momentum=0.9, batch_size=100, n_epochs=300, epoch_waiting=10) return model
def train_model(dataset): X = T.matrix() S = T.tensor3() layers = [] layers.append(FullConnLayer( input=X, input_shape=2784, output_shape=1024, dropout_ratio=0.1, active_func=actfuncs.tanh )) """ layers.append(FullConnLayer( input=layers[-1].output, input_shape=layers[-1].output_shape, output_shape=1024, dropout_ratio=0.1, dropout_input=layers[-1].dropout_output, active_func=actfuncs.tanh )) """ layers.append(FullConnLayer( input=layers[-1].output, input_shape=layers[-1].output_shape, output_shape=37 * 17, dropout_input=layers[-1].dropout_output, active_func=actfuncs.sigmoid )) model = NeuralNet(layers, X, layers[-1].output) model.target = S ''' model.cost = costfuncs.binxent(layers[-1].dropout_output, S.flatten(2)) + \ 1e-3 * model.get_norm(2) model.error = costfuncs.binerr(layers[-1].output, S.flatten(2)) ''' model.cost = costfuncs.weighted_norm2( layers[-1].dropout_output, S.flatten(2), 1.0) + \ 1e-3 * model.get_norm(2) model.error = costfuncs.weighted_norm2( layers[-1].output, S.flatten(2), 1.0) sgd.train(model, dataset, lr=1e-2, momentum=0.9, batch_size=100, n_epochs=300, epoch_waiting=10, never_stop=True) return model