【问题标题】:Tensorflow finding pixels with matching valueTensorFlow查找具有匹配值的像素
【发布时间】:2019-03-13 07:31:50
【问题描述】:

我正在尝试创建用于训练 2 类语义分割网络的数据批次。目标分割图像有 2 层,第一层为 1 类的所有像素,否则为 0。第二层的像素是倒置的。

在数据集中,我的输出图像是带有[255,255,255][0,0,0] 的3 通道rgb 图像。输入和输出图像存储在 tf-record 文件中。

当我在 numpy 中进行实验时,我使用以下代码创建了一个 2 通道二进制图像:

c1_pix = np.all(op_img == np.array([255,255,255]), axis=2)
c1_pix = c1_pix.reshape(*(h,w), 1)
op_arr = np.concatenate((c1_pix, np.invert(c1_pix)), axis=2)

这给了我想要的 2 层 1 和 0 图像。

我正在尝试在 tensorflow 中重复它,但我是新手。我试过c1_pix = tf.where(tf.equal(op_img, [[[255,255,255]]]))。它似乎有效,但它返回 1 和 0 的 3 通道 int64 张量,我无法反转它。

有人可以帮我解决这个问题吗?

谢谢,

【问题讨论】:

    标签: python numpy tensorflow machine-learning binary-image


    【解决方案1】:

    在浏览 tf 文档一段时间后,我想出了以下解决方案

    c1_pix, _, _ = tf.split(tf.equal(op_img,[[[255,255,255]]]), 3, axis=-1)
    c2_pix = tf.logical_not(c1_pix)
    new_op_img = tf.concat([c1_pix, c2_pix], -1)
    

    这对我有用。

    【讨论】:

      猜你喜欢
      • 2015-12-20
      • 1970-01-01
      • 2016-10-28
      • 1970-01-01
      • 2016-07-02
      • 1970-01-01
      • 2020-10-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多