如何为TensorBoard图像添加标签?

时间:2016-03-15 15:13:45

标签: python tensorflow tensorboard

TensorBoard是一个很棒的工具,但它可以更强大吗?下图显示了TensorBoard中的可视化。

通过以下代码调用:

tf.image_summary('images', images, max_images=100)

正如API建议的那样,最后一个数字是"图像编号",在这种情况下从0到99,因为我指定了max_images = 100.我想问一下,如果我可以附加标签这张图片放入文字?这将是一个很棒的功能,因为它允许用户在训练期间实时查看图像及其各自的标签。在某些图像被完全贴错标签的情况下,可以实现修复。换句话说,我希望下图中的相应文字为:

images/image/9/5
images/image/39/6
images/image/31/0
images/image/30/2
where last digit is the label.

谢谢!

enter image description here

2 个答案:

答案 0 :(得分:7)

我还没有找到一种方法只使用tensorflow来做到这一点,所以我做了以下几点:

  1. 为摘要图像创建占位符(例如,对于十个摘要图像,如(10,224,224,3))。
  2. 根据占位符创建图像摘要。
  3. 在验证期间(或培训,如果您愿意),使用session.run([sample_images, sample_labels])之类的内容将摘要的图像和标签拉入python。
  4. 遍历批处理并使用OpenCV使用cv2.putText将标签写入图像。
  5. 运行摘要操作,为占位符提供标记图像。

答案 1 :(得分:1)

这是Vince Gatto提出的方法的一个小改进。我们可以使用var geometry = new THREE.BoxBufferGeometry(10, 10, 0); var material = new THREE.MeshBasicMaterial({map: new THREE.TextureLoader().load('models/packagin/place.png')}); var mesh = new THREE.Mesh(geometry, material); mesh.position.set(10, 5, 0); material.map.needsUpdate = true; //ADDED OBJ.traverse(function (child) { if (child.name !== '') { OBJ.add(mesh) } }); 来避免创建额外的占位符和执行额外的tf.py_func

首先,我们定义以下功能(您将需要安装session.run

opencv-python

现在,我们可以使用import cv2 import tensorflow as tf def put_text(imgs, texts): result = np.empty_like(imgs) for i in range(imgs.shape[0]): text = texts[i] if isinstance(text, bytes): text = text.decode() # You may need to adjust text size and position and size. # If your images are in [0, 255] range replace (0, 0, 1) with (0, 0, 255) result[i, :, :, :] = cv2.putText(imgs[i, :, :, :], str(text), (0, 30), cv2.FONT_HERSHEY_COMPLEX, 1, (0, 0, 1), 2) return result def tf_put_text(imgs, texts): return tf.py_func(put_text, [imgs, texts], Tout=imgs.dtype) 在顶部图像上打印标签,然后再将它们提供给图像摘要:

tf_put_text