简体   繁体   English

如何在TensorFlow中清除tf.Tensor的形状信息?

[英]How do I clear the shape information of tf.Tensor in TensorFlow?

Suppose during training a network, we resize all images to 512*512, so there might be a tf.Tensor named input:0 , which is of shape (batch_size, 512, 512, 3) . 假设在训练网络期间,我们将所有图像的大小调整为512 * 512,因此可能有一个名为input:0tf.Tensor input:0 ,形状为(batch_size, 512, 512, 3) tf.Tensor (batch_size, 512, 512, 3)

However, when making predictions, it is possible to feed images of multiple sizes into the network. 但是,在进行预测时,可以将多种尺寸的图像输入网络。 So the shape of tensor input:0 should be something like (batch_size, None, None, 3) , since the size of images are unknown. 因此张量input:0的形状input:0应该类似于(batch_size, None, None, 3) ,因为图像的大小是未知的。

So if I have a Tensor of shape (batch_size, 512, 512, 3) , how do I "reshape" it to (batch_size, None, None, 3) ? 因此,如果我有一个Tensor of shape (batch_size, 512, 512, 3) ,我该如何“重塑”它(batch_size, None, None, 3) I tried 我试过了

inputs=tf.reshape(inputs, (batch_size, tf.shape(inputs)[1], tf.shape(inputs)[2], 3)

but the output is still of shape (batch_size, 512, 512, 3) . 但输出仍然是形状(batch_size, 512, 512, 3)

I don't believe you can resize/rescale the weight/bias terms in a neural network. 我不相信你可以调整/重新调整神经网络中的权重/偏差项。 But it would be pretty easy to resize your image input to 512*512. 但是将图像输入的大小调整为512 * 512非常容易。 Have you considered that? 你考虑过吗?

暂无
暂无

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

相关问题 TensorFlow:如何将tf.Tensor字符串转换为python datetime数据类型? - TensorFlow: How convert tf.Tensor string to python datetime datatype? Tensorflow:TypeError:预期的二进制或Unicode字符串,得到了 <tf.Tensor 'Placeholder:0' shape=<unknown> dtype = string&gt; - Tensorflow: TypeError: Expected binary or unicode string, got <tf.Tensor 'Placeholder:0' shape=<unknown> dtype=string> 如何创建一个继承自 tf.Tensor 的新 class? - How I create a new class that inherits from tf.Tensor? TensorFlow:将 tf.Dataset 转换为 tf.Tensor - TensorFlow: convert tf.Dataset to tf.Tensor 如何在 tf.Tensor 中重塑和填充零 - How to reshape and padding zeros in tf.Tensor 如何将 map function 应用于 tf.Tensor - how to apply map function to the tf.Tensor KeyError:tf.Tensor&#39;Placeholder_6:0&#39;shape = <unknown> dtype =字符串 - KeyError: tf.Tensor 'Placeholder_6:0' shape=<unknown> dtype=string InvalidArgumentError:预期 'tf.Tensor(False, shape=(), dtype=bool)' 为真 - InvalidArgumentError: Expected 'tf.Tensor(False, shape=(), dtype=bool)' to be true 类型错误:<tf.tensor: shape ...> 有类型<class 'tensorflow.python.framework.ops.eagertensor'> ,但预期其中之一:(<class 'int'> ,)</class></class></tf.tensor:> - TypeError: <tf.Tensor: shape ... > has type <class 'tensorflow.python.framework.ops.EagerTensor'>, but expected one of: (<class 'int'>,) Tensorflow 概率错误:OperatorNotAllowedInGraphError:不允许迭代`tf.Tensor` - Tensorflow Probability Error: OperatorNotAllowedInGraphError: iterating over `tf.Tensor` is not allowed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM