Пример #1
0
def create_convnet(theta, is_tr=True):
    # input
    a0 = T.matrix("x")
    a00 = a0.reshape((a0.shape[0], 1, 28, 28))

    # I: conv pool
    theta1 = [theta[0], theta[1]]
    sz1_pool = (2, 2)
    a1 = models.create_conv_pool_tanh(a00, theta1, sz1_pool)

    # II: conv pool
    theta2 = [theta[2], theta[3]]
    sz2_pool = (2, 2)
    a2 = models.create_conv_pool_tanh(a1, theta2, sz2_pool)

    # III: fc + dropout
    theta3 = [theta[4], theta[5]]
    if is_tr:
        a3 = models.create_dropout(models.create_linear_sigmoid(a2.flatten(2), theta3), trng=trng)
    else:
        a3 = models.create_dropout(models.create_linear_sigmoid(a2.flatten(2), theta3), trng=None)

    # IV: fc, output
    theta4 = [theta[6], theta[7]]
    a4 = models.create_linear(a3, theta4)

    return a0, a4
Пример #2
0
def create_mlp(theta, is_tr=True):
    # input layer
    x = T.matrix('x')

    # hidden layer I
    theta1 = (theta[0], theta[1])
    if is_tr:
        a1 = models.create_dropout(models.create_linear_sigmoid(x, theta1), trng=trng)
    else:
        a1 = models.create_dropout(models.create_linear_sigmoid(x, theta1), trng=None)

    # hidden layer II
    theta2 = (theta[2], theta[3])
    if is_tr:
        a2 = models.create_dropout(models.create_linear_sigmoid(a1, theta2), trng=trng)
    else:
        a2 = models.create_dropout(models.create_linear_sigmoid(a1, theta2), trng=None)

    # output layer
    theta3 = (theta[4], theta[5])
    a3 = models.create_linear_sigmoid(a2, theta3)

    return x, a3