Tensorflow - 在训练的softmax分类模型上检测多个对象

时间:2017-05-30 02:21:27

标签: machine-learning tensorflow deep-learning softmax

我使用标准SVHN裁剪数字数据集生成一个模型,该模型分为10个可能的数字,测试集的准确率为89.89%。继续,我想检测图像上的多个数字。 (例如汽车登记牌上的数字)我该怎么做呢?我是否需要重新训练模型以检测多个图像?

#conv1
W_conv1 = weight_variable([5, 5, 1, 32])
b_conv1 = bias_variable([32])
x_image = tf.reshape(x, [-1,32,32,1])
h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)
h_pool1 = max_pool_2x2(h_conv1)

#conv2
W_conv2 = weight_variable([5, 5, 32, 64])
b_conv2 = bias_variable([64])
h_conv2 = tf.nn.relu(conv2d(h_pool1, W_conv2) + b_conv2)
h_pool2 = max_pool_2x2(h_conv2)

#Densely
W_fc1 = weight_variable([8 * 8 * 64, 1024])
b_fc1 = bias_variable([1024])

h_pool2_flat = tf.reshape(h_pool2, [-1, 8*8*64])
h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1)

#Dropout
keep_prob = tf.placeholder(tf.float32)
h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob)

#Readout
W_fc2 = weight_variable([1024, 10])
b_fc2 = bias_variable([10])
y_conv = tf.matmul(h_fc1_drop, W_fc2) + b_fc2

#Train
cross_entropy = tf.reduce_mean(
tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y_conv))
train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)
correct_prediction = tf.equal(tf.argmax(y_conv,1), tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
sess.run(tf.global_variables_initializer())
for i in range(40000):
  batch = shvn_data.nextbatch(100)
  if i%100 == 0:
    train_accuracy = accuracy.eval(feed_dict={
        x:batch[0], y_: batch[1], keep_prob: 1.0})
    print("step %d, training accuracy %f"%(i, train_accuracy))
  train_step.run(feed_dict={x: batch[0], y_: batch[1], keep_prob: 0.5})

我的代码是从这里修改的:https://www.tensorflow.org/get_started/mnist/pros。我的代码可以在这里找到:https://github.com/limwenyao/ComputerVision/blob/testing/CNN_MNIST.py#L216

1 个答案:

答案 0 :(得分:0)

你可以在网上包裹一个跨栏系统。所以你用车板拍摄你的图像并将其切割成许多较小的图像,然后在每个较小的图像上运行数字检测并记录找到的数字,最后将它们放在一起,然后记录你的板号。

将车牌图像切割成较小图像的过程通常也是训练有素的网络。所以你会有两个网:

  • 一个人学得很好
  • 另一个学会从每个剪切子图像中读取一位数字