简体   繁体   English

使用Tensorflow过滤Tensor

[英]Filtering a Tensor using Tensorflow

I'm attempting to filter a matrix that represents a point cloud in tensorflow. 我正在尝试过滤代表张量流中点云的矩阵。 It is an nx 3 matrix. 它是一个nx 3矩阵。

I only want to keep rows with z > eps . 我只想保留z > eps行。 This corresponds to column index 2 of the matrix. 这对应于矩阵的列索引2。

I have the following code: 我有以下代码:


import numpy as np
import tensorflow as tf

point_cloud = tf.placeholder(tf.float32, shape=[None,3])
eps = tf.placeholder(tf.float32)

mask = tf.greater(point_cloud[:,2], eps)
reduced_cloud = tf.boolean_mask(point_cloud, mask)


init = tf.global_variables_initializer()

with tf.Session() as sess:
    sess.run(init)
    _cloud = np.random.rand(5000,3)
    feed = {point_cloud:_cloud, eps:0.0025}
    _filtered = sess.run(reduced_cloud, feed_dict=feed)

When I run the above code I get this: 当我运行上面的代码时,我得到了:


ValueError: Number of mask dimensions must be specified, even if some dimensions are None.  E.g. shape=[None] is ok, but shape=None is not.

I don't understand the error message, having tried to specify shape in a number of places with no success, and the documentation seems to suggest the boolean_mask only works with np.array s. 我不理解错误消息,试图在许多地方指定形状都没有成功,并且文档似乎建议boolean_mask仅适用于np.array Is there any way to do this entirely on the tensorflow graph? 有没有办法完全在张量流图上做到这一点?

You haven't specified the shape of eps which needs to be a 1D-tensor: 您尚未指定需要为一维张量的eps的形状:

import numpy as np
import tensorflow as tf

point_cloud = tf.placeholder(tf.float32, shape=[None,3])
eps = tf.placeholder(tf.float32, shape=[None])

mask = tf.greater(point_cloud[:,2], eps)
reduced_cloud = tf.boolean_mask(point_cloud, mask)

init = tf.global_variables_initializer()
with tf.Session() as sess:
     sess.run(init)
     _cloud = np.random.rand(5000,3)
     feed = {point_cloud:_cloud, eps:[0.0025]}
     _filtered = sess.run(reduced_cloud, feed_dict=feed)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM