我正试图解决Kaggle上的Dogs vs. Cats Redux: Kernels Edition问题。这是一个简单的图像分类问题。但是,我的表现比17分以上的随机预测更糟糕。有谁知道这可能是为什么?真的很差准确性与神经网络
神经网络模型
def convolutional_neural_network():
weights = {
# 3x3x3 conv => 1x1x8
'conv1': tf.Variable(tf.random_normal([3, 3, 3, 8])),
# 5x5x8 conv => 1x1x16
'conv2': tf.Variable(tf.random_normal([5, 5, 8, 16])),
# 3x3x16 conv => 1x1x32
'conv3': tf.Variable(tf.random_normal([3, 3, 16, 32])),
# 32 FC => output_features
'out': tf.Variable(tf.random_normal([(SIZE//16)*(SIZE//16)*32, output_features]))
}
biases = {
'conv1': tf.Variable(tf.random_normal([8])),
'conv2': tf.Variable(tf.random_normal([16])),
'conv3': tf.Variable(tf.random_normal([32])),
'out': tf.Variable(tf.random_normal([output_features]))
}
conv1 = tf.add(conv2d(input_placeholder, weights['conv1'], 1), biases['conv1'])
relu1 = relu(conv1)
pool1 = maxpool2d(relu1, 4)
conv2 = tf.add(conv2d(pool1, weights['conv2'], 1), biases['conv2'])
relu2 = relu(conv2)
pool2 = maxpool2d(relu2, 2)
conv3 = tf.add(conv2d(pool2, weights['conv3'], 1), biases['conv3'])
relu3 = relu(conv3)
pool3 = maxpool2d(relu3, 2)
pool3 = tf.reshape(pool3 , shape=[-1, (SIZE//16)*(SIZE//16)*32])
output = tf.add(tf.matmul(pool3, weights['out']), biases['out'])
return output
的输出具有无激活作用。
预测,最佳化和损失函数
output_prediction = convolutional_neural_network()
loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(output_prediction, output_placeholder))
trainer = tf.train.AdamOptimizer()
optimizer = trainer.minimize(loss)
test_prediction = tf.nn.softmax(output_prediction)
的图像与批量大小转换成大小 X X 的numpy的阵列和供给到所述神经网络的64.
编辑:相同的代码为200个纪元。没提升。我做得稍微差一些。
20个时代似乎没有足够的地方...你也需要一个相当大的训练集...这可能需要几个小时来训练......你可能想看看在谷歌已经开始训练的模型(参见https://www.tensorflow.org/how_tos/image_retraining/) –
你使用这个循环的是什么? https://github.com/DollarAkshay/Python-Programs/blob/master/Artificial%20Intelligence/Kaggle_Dogs_vs_Cats.py#L124为什么不''np.argmax'什么的? – martianwars
@Joran Beasley是的,20个时代看起来不是那么简单,但是它不应该做一个体面的预测吗?我的训练集有25k图像。你建议多少个时代?我其实是想学习神经网络,这就是为什么我不使用预先训练的模型:) –