2017-05-30 123 views
0

我已經使用標準SVHN裁剪數字數據集來生成一個模型,該模型可分爲10個可能的數字,測試集的準確率爲89.89%。繼續前進,我想檢測圖像上的多個數字。 (例如汽車登記牌上的號碼)我會如何去做這件事?我是否需要重新訓練我的模型以檢測多個圖像?Tensorflow - 在訓練好的softmax分類模型上檢測多個對象

#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

+0

讀一個數字在此處添加代碼,不要讓我們跟隨外部鏈接 –

回答

0

你會圍繞你的網包裝一個跨步系統。因此,您可以將圖像與車牌一起拍攝下來,然後將其剪切成許多較小的圖像,然後在每個較小的圖像上運行數字檢測並記錄找到的數字,最後將它們放在一起並確認您的車牌號碼。

將車牌圖像切割成較小圖像的過程通常也是訓練有素的網絡。所以,你將有兩個網:

  • 一個學會了切好
  • 另獲悉,從每個切割子圖像
+0

理解,謝謝! –