0

现在我的问题是关于阅读 tfrecords。例如,假设我有两个图像,每个框都有它的边界框来包含对象。

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

数据已成功写入 tfrecord 文件,现在我的工作是读取它。

当我加载它时,我发现数据不匹配。例如它可能是

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

我尝试使用 opencv2 绘制它并发现这个问题。

我读取 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)


4

1 回答 1

1

你的数据很好,你会得到不匹配,因为你这样做:

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

每次调用sess.run()该图时,都会在新输入上进行评估,并且计算您传入参数的任何张量并返回其值。如果您想要来自同一示例的图像和 bbox,请运行

image, gbboxe = sess.run([image[0, :, :, :], gbboxes[0, :]])
于 2017-11-08T09:08:43.660 回答