首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >tensorflow中的histogram2d

tensorflow中的histogram2d
EN

Stack Overflow用户
提问于 2017-11-01 23:12:37
回答 1查看 490关注 0票数 0

我想在Tensorflow中创建一个histogram2d。如下所示:

最好是在Tensorboard中,但如果有一个没有tensorboard的简单解决方案就可以了。

Tensorboard似乎只绘制了一维直方图/分布。我有一个使用np.histogram2d和图像的解决方案,我将添加它们作为答案,但它远非理想,因为我不能显示轴或观察量化值。

EN

回答 1

Stack Overflow用户

发布于 2017-11-01 23:12:37

我的解决方案包括使用numpy的np.histogram2d,使用tf.py_func将其嵌入到tensorflow中,然后使用tf.summary_image将“height”绘制为图像中的grey_scale。

代码语言:javascript
复制
def _histogram_2d(a,b):
  """
  takes two tensors of the same shape and computes the 2d histogram of their pairs
  """
  ar = a.reshape(-1)
  br = b.reshape(-1)
  aux = np.histogram2d(ar, br)
  return aux[0].astype(np.float32), aux[1].astype(np.float32), aux[2].astype(np.float32)

[H, xedges, yedges] = tf.py_func(_histogram_2d, [a, b], [tf.float32, tf.float32, tf.float32])
      tf.summary.image('/2d_hist', tf.expand_dims(tf.expand_dims(H,0),-1))

你会得到类似这样的结果:

它可以完成这项工作,但也可能有更好的方法。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47058011

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档