2017-11-08 17 views
0

私の問題は、tfrecordsを読むことです。 たとえば、2つのイメージがあり、各ボックスにオブジェクトを含むバウンディングボックスがあるとします。テンソルでのtfrecordの読み込みに関する問題

 

    image1 bbox1:xmin1,ymin1,xmax1,ymax1 
    image2 bbox2:xmin2,ymin2,xmax2,ymax2 

データがtfrecordファイルに正常に書き込まれましたが、今は自分の仕事がそれを読むことです。私はそれをロードする際

はそして、私はそれが私がopencv2を使用して、それを描画し、この問題を見つけよう

`image1 bbox2:xmin2,ymin2,xmax2,ymax2`

かもしれデータはmatched.For例ではありません見つけます。

tfrecordを読むために私のコードは次の通りである:あなたのデータは結構です

 


    image, gbboxes= tf.train.batch(
      [image, gbboxes], 
      batch_size=config.batch_size, 
      num_threads=1, 
      capacity=50) 

     batch_queue = slim.prefetch_queue.prefetch_queue(
      [image, gbboxes], 
      capacity=50) 

     image, gbboxes = batch_queue.dequeue() 

     with tf.Session() as sess: 
      coord = tf.train.Coordinator() 
      threads = tf.train.start_queue_runners(sess=sess, coord=coord) 
      init_op = tf.global_variables_initializer() 
      sess.run(init_op) 
      # 0 index to extreact first image of batch 
      image = sess.run(image[0, :, :, :]) 
      gbboxe = sess.run(gbboxes[0, :]) 

      [ymin, xmin, ymax, xmax] = gbboxe*config.image_width 
      image = np.asarray(image, np.uint8) 
      cv2.rectangle(image, (int(xmin), int(ymin)), (int(xmax), int(ymax)), (0, 255, 0), 1) 
      cv2.imshow("test", image) 
      cv2.waitKey()  
      coord.request_stop() 
      coord.join(threads) 

 

答えて

1

あなたがこれを行うためには、不一致を得る:

image = sess.run(image[0, :, :, :]) 
gbboxe = sess.run(gbboxes[0, :]) 

あなたはグラフsess.run()を呼び出すたびに新しい入力でと評価され、引数に渡すテンソルが計算され、その値が返されます。 イメージと同じサンプルのbboxを使用する場合は、

image, gbboxe = sess.run([image[0, :, :, :], gbboxes[0, :]]) 
+0

素晴らしい!どうもありがとうございました!!! –

関連する問題