我的任务:承认koshe和sobkak。我建立了一个卷积神经网络,但它没有经过训练。输入数据一切正常,我将它们标准化。以下是训练时的损失。有一次,损失不再发生变化。 如果你看一下准确性,那么它会发出40到60的随机数 我尝试了不同的架构和超参数,但这没有帮助
step 0, training loss 2.3357
step 1, training loss 1.25691
step 2, training loss 0.807765
step 3, training loss 0.794417
step 4, training loss 0.849323
step 5, training loss 0.798526
step 6, training loss 0.734194
step 7, training loss 0.706299
step 8, training loss 0.694308
step 9, training loss 0.693147
step 10, training loss 0.693147
step 11, training loss 0.693147
step 12, training loss 0.693147
step 13, training loss 0.693147
step 14, training loss 0.693147
step 15, training loss 0.693147
step 16, training loss 0.693147
step 17, training loss 0.693147
step 18, training loss 0.693147
step 19, training loss 0.693147
step 20, training loss 0.693147
step 21, training loss 0.693147
step 22, training loss 0.693147
step 23, training loss 0.693147
step 24, training loss 0.693147
step 25, training loss 0.693147
step 26, training loss 0.693147
step 27, training loss 0.693147
step 28, training loss 0.693147
step 29, training loss 0.693147
step 30, training loss 0.693147
step 31, training loss 0.693147
step 32, training loss 0.693147
step 33, training loss 0.693147
step 34, training loss 0.693147
step 35, training loss 0.693147
step 36, training loss 0.693147
step 37, training loss 0.693147
step 38, training loss 0.693147
step 39, training loss 0.693147
step 40, training loss 0.693147
step 41, training loss 0.693147
step 42, training loss 0.693147
step 43, training loss 0.693147
step 44, training loss 0.693147
step 45, training loss 0.693147
step 46, training loss 0.693147
step 47, training loss 0.693147
step 48, training loss 0.693147
step 49, training loss 0.693147
step 50, training loss 0.693147
step 51, training loss 0.693147
step 52, training loss 0.693147
step 53, training loss 0.693147
step 54, training loss 0.693147
step 55, training loss 0.693147
step 56, training loss 0.693147
step 57, training loss 0.693147
step 58, training loss 0.693147
step 59, training loss 0.693147
step 60, training loss 0.693147
step 61, training loss 0.693147
step 62, training loss 0.693147
step 63, training loss 0.693147
step 64, training loss 0.693147
step 65, training loss 0.693147
step 66, training loss 0.693147
step 67, training loss 0.693147
step 68, training loss 0.693147
step 69, training loss 0.693147
step 70, training loss 0.693147
step 71, training loss 0.693147
step 72, training loss 0.693147
step 73, training loss 0.693147
step 74, training loss 0.693147
step 75, training loss 0.693147
step 76, training loss 0.693147
step 77, training loss 0.693147
step 78, training loss 0.693147
step 79, training loss 0.693147
step 80, training loss 0.693147
step 81, training loss 0.693147
step 82, training loss 0.693147
step 83, training loss 0.693147
step 84, training loss 0.693147
step 85, training loss 0.693147
step 86, training loss 0.693147
step 87, training loss 0.693147
step 88, training loss 0.693147
step 89, training loss 0.693147
step 90, training loss 0.693147
step 91, training loss 0.693147
step 92, training loss 0.693147
step 93, training loss 0.693147
step 94, training loss 0.693147
step 95, training loss 0.693147
step 96, training loss 0.693147
step 97, training loss 0.693147
step 98, training loss 0.693147
step 99, training loss 0.693147
step 100, training loss 0.693147
step 101, training loss 0.693147
step 102, training loss 0.693147
step 103, training loss 0.693147
step 104, training loss 0.693147
step 105, training loss 0.693147
我的架构
sess = tf.InteractiveSession()
def widht_init(shape):
weight = tf.Variable(tf.truncated_normal(shape,stddev = 0.1))
return weight
def bias_init(shape):
bias = tf.Variable(tf.constant(0.1,shape=shape))
return bias
def conv2d(x,W):
return tf.nn.conv2d(x,W, strides=[1,1,1,1], padding='SAME')
def max_pool_2x2(x):
return tf.nn.max_pool(x, ksize=[1, 2, 2, 1],strides=[1, 2, 2, 1], padding='SAME')
y_ = tf.placeholder(tf.float32, shape=[None, 2])
x = tf.placeholder(tf.float32, shape=[None,WIDTH,WIDTH,CHANNELS])
#first conv layer
W1 = widht_init([3,3,3,32])
b1 = bias_init([32])
h1_conv = conv2d(x,W1)
h1_conv = tf.nn.relu(h1_conv+b1)
h1_conv = max_pool_2x2(h1_conv)
print(h1_conv.shape)
#second conv layer
W2 = widht_init([3,3,32,32])
b2 = bias_init([32])
h2_conv = conv2d(h1_conv,W2)
h2_conv = tf.nn.relu(h2_conv+b2)
h2_conv = max_pool_2x2(h2_conv)
print(h2_conv.shape)
#third conv layer
W3 = widht_init([3,3,32,64])
b3 = bias_init([64])
h3_conv = conv2d(h2_conv,W3)
h3_conv = tf.nn.relu(h3_conv+b3)
h3_conv = max_pool_2x2(h3_conv)
print(h3_conv.shape)
#third conv layer
W4 = widht_init([3,3,64,128])
b4 = bias_init([128])
h4_conv = conv2d(h3_conv,W4)
h4_conv = tf.nn.relu(h4_conv+b4)
h4_conv = max_pool_2x2(h4_conv)
print(h4_conv.shape)
W5 = widht_init([3,3,128,256])
b5 = bias_init([256])
h5_conv = conv2d(h4_conv,W5)
h5_conv = tf.nn.relu(h5_conv+b5)
h5_conv = max_pool_2x2(h5_conv)
print(h5_conv.shape)
#full conect layer
values = h5_conv.get_shape().as_list()
print(values[1],values[2],values[3])
h5_conv = tf.reshape(h5_conv, (-1, values[1]*values[2]*values[3]))
print(h5_conv.shape)
W_fc = widht_init([values[1]*values[2]*values[3],256])
b_fc = bias_init([256])
h_fc = tf.nn.relu(tf.matmul(h5_conv,W_fc)+b_fc)
print(h_fc.shape)
#dropout layer
keep_prob = tf.placeholder(tf.float32)
h_fc_drop = tf.nn.dropout(h_fc, keep_prob)
W_fc1 = widht_init([256,64])
b_fc1 = bias_init([64])
h_fc1 = tf.nn.relu(tf.matmul(h_fc_drop,W_fc1)+b_fc1)
print(h_fc1.shape)
h_fc_drop1 = tf.nn.dropout(h_fc1, keep_prob)
#output layer
W_out = widht_init([64,2])
b_out = bias_init([2])
y_conv = tf.nn.relu(tf.matmul(h_fc_drop1,W_out)+b_out)
print(y_conv.shape)
培训
batch_size = 16
epochs = 1000
sess.run(tf.global_variables_initializer())
for step in range(1000):
offset = (step * batch_size) % (y_train.shape[0] - batch_size)
batch_data = X_train[offset:(offset + batch_size), :, :, :]
batch_labels = y_train[offset:(offset + batch_size), :]
train_step.run(feed_dict={x: batch_data, y_: batch_labels, keep_prob: 0.5})
#train_accuracy = accuracy.eval(feed_dict={x:batch_data, y_: batch_labels, keep_prob: 1.0})
train_loss = cross_entropy.eval(feed_dict={x:X_valid, y_:y_valid, keep_prob: 1.0})
print("step %d, training loss %g"%(step, train_loss))
#print("test accuracy %g"%accuracy.eval(feed_dict={x: X_valid, y_: y_valid, keep_prob: 1.0}))