예제 #1
0
# layer_0
model_0 = ConvAutoEncoder(
    layers=[layer_0_en,
            MaxPoolingSameSize(pool_size=(4, 4)), layer_0_de])
out_0 = model_0.fprop(images, corruption_level=corruption_level)
cost_0 = mean_square_cost(out_0[-1], images) + L2_regularization(
    model_0.params, 0.005)
updates_0 = gd_updates(cost=cost_0,
                       params=model_0.params,
                       method="sgd",
                       learning_rate=0.1)

# layer_0 --> layer_1
model_0_to_1 = FeedForward(
    layers=[layer_0_en, MaxPooling(pool_size=(4, 4))])
out_0_to_1 = model_0_to_1.fprop(images)

# layer_1
model_1 = ConvAutoEncoder(
    layers=[layer_1_en,
            MaxPoolingSameSize(pool_size=(2, 2)), layer_1_de])
out_1 = model_1.fprop(out_0_to_1[-1], corruption_level=corruption_level)
cost_1 = mean_square_cost(out_1[-1], out_0_to_1[-1]) + L2_regularization(
    model_1.params, 0.005)
updates_1 = gd_updates(cost=cost_1,
                       params=model_1.params,
                       method="sgd",
                       learning_rate=0.1)

# layer_1 --> layer_2
예제 #2
0
                            batch_size=batch_size,
                            border_mode="same")

# learning rate formula:
# r = 1 - 0.5*(ni/ntot)*(ni/ntot)
# ni = ith layer; ntot = number of layers


# layer_0
model_0=ConvAutoEncoder(layers=[layer_0_en, MaxPoolingSameSize(pool_size=(4,4)), layer_0_de])
out_0=model_0.fprop(images, corruption_level=corruption_level)
cost_0=mean_square_cost(out_0[-1], images)+L2_regularization(model_0.params, 0.005)
updates_0=gd_updates(cost=cost_0, params=model_0.params, method="sgd", learning_rate=0.1)

# layer_0 --> layer_1
model_0_to_1=FeedForward(layers=[layer_0_en, MaxPooling(pool_size=(2,2))]);
out_0_to_1=model_0_to_1.fprop(images);

# layer_1
model_1=ConvAutoEncoder(layers=[layer_1_en, MaxPoolingSameSize(pool_size=(2,2)), layer_1_de])
out_1=model_1.fprop(out_0_to_1[-1], corruption_level=corruption_level)
cost_1=mean_square_cost(out_1[-1], out_0_to_1[-1])+L2_regularization(model_1.params, 0.005)
updates_1=gd_updates(cost=cost_1, params=model_1.params, method="sgd", learning_rate=0.1)

# layer_1 --> layer_2
model_1_to_2=FeedForward(layers=[layer_1_en, MaxPooling(pool_size=(4,4))]);
out_1_to_2=model_1_to_2.fprop(images);

# layer_2
model_2=ConvAutoEncoder(layers=[layer_2_en, MaxPoolingSameSize(pool_size=(2,2)), layer_2_de])
out_2=model_2.fprop(out_1_to_2[-1], corruption_level=corruption_level)
예제 #3
0
print "[MESSAGE] The data is loaded"

X = T.matrix("data")
y = T.ivector("label")
idx = T.lscalar()

images = X.reshape((batch_size, 1, 32, 32))

layer_0 = LCNLayer(filter_size=(7, 7),
                   num_filters=64,
                   num_channels=1,
                   fm_size=(32, 32),
                   batch_size=batch_size,
                   border_mode="full")

pool_0 = MaxPooling(pool_size=(2, 2))

layer_1 = LCNLayer(filter_size=(5, 5),
                   num_filters=32,
                   num_channels=64,
                   fm_size=(16, 16),
                   batch_size=batch_size,
                   border_mode="full")

pool_1 = MaxPooling(pool_size=(2, 2))

flattener = Flattener()

layer_2 = ReLULayer(in_dim=32 * 64, out_dim=800)

layer_3 = SoftmaxLayer(in_dim=800, out_dim=10)
예제 #4
0
#                             batch_size=batch_size,
#                             border_mode="full")

model_0 = ConvAutoEncoder(layers=[layer_0_en, layer_0_de])
out_0 = model_0.fprop(images, corruption_level=corruption_level)
cost_0 = mean_square_cost(out_0[-1], images) + L2_regularization(
    model_0.params, 0.005)
updates_0 = gd_updates(cost=cost_0,
                       params=model_0.params,
                       method="sgd",
                       learning_rate=0.1)

## append a max-pooling layer

model_trans = FeedForward(
    layers=[layer_0_en, MaxPooling(pool_size=(2, 2))])
out_trans = model_trans.fprop(images)

model_1 = ConvAutoEncoder(layers=[layer_1_en, layer_1_de])
out_1 = model_1.fprop(out_trans[-1], corruption_level=corruption_level)
cost_1 = mean_square_cost(out_1[-1], out_trans[-1]) + L2_regularization(
    model_1.params, 0.005)
updates_1 = gd_updates(cost=cost_1,
                       params=model_1.params,
                       method="sgd",
                       learning_rate=0.1)

# model_2=ConvAutoEncoder(layers=[layer_2_en, layer_2_de])
# out_2=model_2.fprop(out_1[0], corruption_level=corruption_level)
# cost_2=mean_square_cost(out_2[-1], out_1[0])+L2_regularization(model_2.params, 0.005)
# updates_2=gd_updates(cost=cost_2, params=model_2.params, method="sgd", learning_rate=0.1)
예제 #5
0
layer_1_de=SigmoidConvLayer(filter_size=(2,2),
                            num_filters=50,
                            num_channels=50,
                            fm_size=(8,8),
                            batch_size=batch_size,
                            border_mode="same")


model_0=ConvAutoEncoder(layers=[layer_0_en, MaxPoolingSameSize(pool_size=(4,4)), layer_0_de])
out_0=model_0.fprop(images, corruption_level=corruption_level)
cost_0=mean_square_cost(out_0[-1], images)+L2_regularization(model_0.params, 0.005)
updates_0=gd_updates(cost=cost_0, params=model_0.params, method="sgd", learning_rate=0.1)

## append a max-pooling layer

model_trans=FeedForward(layers=[layer_0_en, MaxPooling(pool_size=(4,4))]);
out_trans=model_trans.fprop(images);


model_1=ConvAutoEncoder(layers=[layer_1_en, MaxPoolingSameSize(pool_size=(2,2)), layer_1_de])
out_1=model_1.fprop(out_trans[-1], corruption_level=corruption_level)
cost_1=mean_square_cost(out_1[-1], out_trans[-1])+L2_regularization(model_1.params, 0.005)
updates_1=gd_updates(cost=cost_1, params=model_1.params, method="sgd", learning_rate=0.1)


train_0=theano.function(inputs=[idx, corruption_level],
                        outputs=[cost_0],
                        updates=updates_0,
                        givens={X: train_set_x[idx * batch_size: (idx + 1) * batch_size]})

train_1=theano.function(inputs=[idx, corruption_level],