test_X2_label = np.transpose(np.mat(test_X2_data['label_X2']))

# view1 layers
X1 = tf.placeholder(tf.float32, [None, 1024])
X2 = tf.placeholder(tf.float32, [None, 1024])

W11 = tf.Variable(tf.random_uniform([1024, 1], -1, 1))
#L11 = tf.nn.relu(tf.matmul(X1,W11))
model1 = tf.matmul(X1, W11)

# view2 layers
W12 = tf.Variable(tf.random_uniform([1024, 1], -1, 1))
#L12 = tf.nn.relu(tf.matmul(X2,W12))
model2 = tf.matmul(X2, W12)

cost = neg_correlation(model1, model2, 1) + 0.1 * tf.norm(
    W11, ord=1) + 0.1 * tf.norm(W12, ord=1) + 0.1 * tf.matmul(
        tf.matmul(tf.transpose(W11), H1), W11) + 0.1 * tf.matmul(
            tf.matmul(tf.transpose(W12), H2), W12)
optimizer = tf.train.AdamOptimizer(learning_rate).minimize(cost)

init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)

iterations = 0
for epoch in range(n_epochs):
    index = np.arange(train_X1.shape[0])
    np.random.shuffle(index)
    trX1 = train_X1[index]
    trX2 = train_X2[index]
Пример #2
0
# view2 layers
W12 = tf.Variable(tf.random_uniform([1024, 2048], -1, 1))
L12 = tf.nn.relu(tf.matmul(X2, W12))

W22 = tf.Variable(tf.random_uniform([2048, 2048], -1, 1))
L22 = tf.nn.relu(tf.matmul(L12, W22))

W32 = tf.Variable(tf.random_uniform([2048, 1024], -1, 1))
L32 = tf.nn.relu(tf.matmul(L22, W32))

W42 = tf.Variable(tf.random_uniform([1024, 1], -1, 1))
model2 = tf.matmul(X2, W42)

cost = neg_correlation(
    model1, model2,
    1) + 0.01 * tf.norm(W41, ord=1) + 0.01 * tf.norm(W42, ord=1)
#+  0.01*tf.norm(W11,ord=2) + 0.1*tf.norm(W12,ord=2)+ 0.01*tf.norm(W21,ord=1) + 0.01*tf.norm(W22,ord=1) + 0.01 * tf.norm(W31,ord=1) + 0.01*tf.norm(W32,ord=1)
#cost = tf.contrib.metrics.streaming_pearson_correlation(model1,model2)
optimizer = tf.train.AdamOptimizer(0.01).minimize(cost)

init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)

iterations = 0
for epoch in range(n_epochs):
    index = np.arange(train_X1.shape[0])
    np.random.shuffle(index)
    trX1 = train_X1[index]
    trX2 = train_X2[index]
Пример #3
0
# view2 layers
W12 = tf.Variable(tf.random_uniform([1024, 2048], -1, 1))
L12 = tf.nn.relu(tf.matmul(X2, W12))

W22 = tf.Variable(tf.random_uniform([2048, 2048], -1, 1))
L22 = tf.nn.relu(tf.matmul(L12, W22))

W32 = tf.Variable(tf.random_uniform([2048, 1024], -1, 1))
L32 = tf.nn.relu(tf.matmul(L22, W32))

W42 = tf.Variable(tf.random_uniform([1024, 1], -1, 1))
model2 = tf.matmul(L32, W42)

cost = tf.reduce_mean(tf.square(W41 - train_X1_label)) + tf.reduce_mean(
    tf.square(W42 - train_X2_label)) + neg_correlation(model1, model2, 1)
# neg_correlation(model1,model2,1) ++ 0.01*tf.norm(W41,ord=1) + 0.01*tf.norm(W42,ord=1)
#+  0.01*tf.norm(W11,ord=2) + 0.1*tf.norm(W12,ord=2)+ 0.01*tf.norm(W21,ord=1) + 0.01*tf.norm(W22,ord=1) + 0.01 * tf.norm(W31,ord=1) + 0.01*tf.norm(W32,ord=1)
#cost = tf.contrib.metrics.streaming_pearson_correlation(model1,model2)
optimizer = tf.train.AdamOptimizer(0.01).minimize(cost)

init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)

iterations = 0
for epoch in range(n_epochs):
    index = np.arange(train_X1.shape[0])
    np.random.shuffle(index)
    trX1 = train_X1[index]
    trX2 = train_X2[index]
Пример #4
0
    activation=tf.nn.relu,
    kernel_regularizer=tf.contrib.layers.l2_regularizer(scale=0.01))
h22 = tf.layers.max_pooling2d(h22, [2, 2], [2, 2])
h22 = tf.layers.dropout(h22, 0.7, is_training)

h32 = tf.contrib.layers.flatten(h22)
h32 = tf.layers.dense(
    h32,
    256,
    activation=tf.nn.relu,
    kernel_regularizer=tf.contrib.layers.l2_regularizer(scale=0.01))
h42 = tf.layers.dense(
    h32, 10, kernel_regularizer=tf.contrib.layers.l2_regularizer(scale=0.01))

# Optimization
cost = neg_correlation(h41, h42, 10)
optimizer = tf.train.AdamOptimizer(0.001).minimize(cost)

init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)

iterations = 0
for epoch in range(n_epochs):
    index = np.arange(train_X1.shape[0])
    np.random.shuffle(index)
    trX1 = train_X1[index]
    trX2 = train_X2[index]

    for start, end in zip(range(0, train_X1.shape[0], batch_size),
                          range(batch_size, train_X1.shape[0], batch_size)):