2017-11-08 2 views
0

이제 내 문제는 tfrecords를 읽는 것입니다. 예를 들어 두 개의 이미지가 있고 각 상자에 객체를 포함 할 경계 상자가 있다고 가정합니다.tensorflow로 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

놀랍지 만 놀랍습니다! 대단히 감사합니다 !!! –

관련 문제