- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的图像为478 x 717 x 3 = 1028178像素,等级为1。我通过调用tf.shape和tf.rank进行了验证。
当我调用image.set_shape([478,717,3])时,它将引发以下错误。
"Shapes %s and %s must have the same rank" % (self, other))
ValueError: Shapes (?,) and (478, 717, 3) must have the same rank
ValueError: Shapes (1028178,) and (478, 717, 3) must have the same rank
What is the difference between x.set_shape() and x = tf.reshape(x)?
The tf.Tensor.set_shape() method updates the static shape of a Tensor object, and it is typically used to provide additional shape information when this cannot be inferred directly. It does not change the dynamic shape of the tensor.
The tf.reshape() operation creates a new tensor with a different dynamic shape.
最佳答案
据我所知(并编写了该代码), Tensor.set_shape()
中没有错误。我认为误解源于该方法的名称困惑。
为了详细说明FAQ entry you quoted,Tensor.set_shape()
是一个纯Python函数,可改善给定tf.Tensor
对象的形状信息。 “改善”是指“使内容更加具体”。
因此,当您拥有形状为Tensor
的t
对象(?,)
时,即未知长度的一维张量。您可以调用t.set_shape((1028178,))
,然后在调用t
时(1028178,)
将具有t.get_shape()
形状。这不会影响基础存储,也不会影响后端的任何内容:它仅意味着使用t
进行后续形状推断可以依赖于它是长度为1028178的 vector 的断言。
如果t
具有(?,)
形状,则对t.set_shape((478, 717, 3))
的调用将失败,因为TensorFlow已经知道t
是 vector ,因此它不能具有(478, 717, 3)
形状。如果要根据t
的内容制作具有该形状的新Tensor,可以使用 reshaped_t = tf.reshape(t, (478, 717, 3))
。这将在Python中创建一个新的tf.Tensor
对象;实际的implementation of tf.reshape()
使用张量缓冲区的浅拷贝来执行此操作,因此在实践中不昂贵。
一个类比是Tensor.set_shape()
就像是一种运行时强制转换,如Java之类的面向对象语言。例如,如果您有一个指向Object
的指针,但是知道它实际上是String
,则可以执行强制转换(String) obj
以便将obj
传递给需要String
参数的方法。但是,如果您有一个String
s
并尝试将其转换为java.util.Vector
,则编译器会给您一个错误,因为这两种类型无关。
关于tensorflow - 对tf.Tensor.set_shape()的澄清,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35451948/
在此链接中:http://www.sencha.com/blog/spotlight-ext-js-customers/ 请滚动到部分:为什么我们选择 Ext JS 有这一行: By using Ex
只是想确保我正确理解这一点(我会在 SO Chat 上问,但它已经死在那里了!): 我们有一个顶点数组,我们通过绑定(bind)它使其成为“当前” 然后我们有一个缓冲区,我们将其绑定(bind)到目标
我正在学习与 Java Swing 一起使用的类(class),但我遇到了障碍。在这个项目中,我们正在为不同的组件设置大小,但是,导师特意敲了一行我不太理解的代码,我只是在寻找这行代码概念的解释。 基
所以我尝试创建一个 HttpsRequest,效果非常好。问题是,我做错了什么,我认为这可能是因为我使用 HttpResponse,但我没有找到任何与 Https 类似的东西。有没有一种方法可以像 h
我正在阅读 Martin Fowler 的“UML distilled”,在阅读关联类的过程中,我得到了这句话: What benefit do you gain with the associati
我只是询问此说明: String[][] s = new String[2][2]; 如果我创建这个变量“s”,我会创建一个包含 2 行和 2 列的字符串表吗?或者 2 个表有 2 个元素?感谢您的澄
我目前正在做的事情需要为世界各地的用户提供本地化时间。所有日期时间都存储为 UTC,因此转换它们非常容易,并且我们有一个已知的、安全的引用点等等。 但是,关于如何表达偏移量的一些事情让我摸不着头脑。
我开始学习 spring,我遇到了一个定义,它说“Spring 使开发人员能够在没有应用程序服务器的情况下进行企业开发”。 这到底是什么意思,使用应用服务器进行企业开发有什么危害。 但是开发者在进行企
我是 AngularJS 的新手,对如何设置 angularJS 进行开发感到困惑。 Link1 link1 说我们需要 node.js 和一系列其他工具,这些工具必须在使用 AngularJS 之前
我是 iPhone 和 iPad 应用程序的开发者。 我的一个应用程序是在线个人财务管理工具的配套应用程序,该工具通过网站提供其服务和功能。这些功能的一部分将通过我正在创建的原生 iOS 应用程序提供
我正在研究飞行模拟器。我读过一篇关于四元数的教程(这个:http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quater
抱歉,如果这是一个微不足道的问题: 实现 1: class Foo { protected: int bar; public: Foo(int bar) {
作为 C 中实现定义行为的示例。C 标准规定数据类型的大小是实现定义的。因此,假设 sizeof(int) 是实现定义的。 此实现定义的行为是否意味着 size(int) 依赖于平台或由编译器供应商定
从理论上讲,inline 函数在 C 语言中具有内部/静态链接,也就是说,它们仅在单个翻译单元内可见。因此,在两个单独的文件中定义的内联函数应该无法相互看到,并且两者都有自己的地址空间。 我正在尝试使
对于神童来说,这可能是一个非常基本的问题。但我对处理它有疑问。 在转换期间我们使用: int.Parse(someThing) Convert.ToInt32 或 Convert.ToString()
这个问题在这里已经有了答案: Regarding Android Permissions and Signature Protection level (2 个答案) 关闭 8 年前。 由于我是An
我有这个功能: 函数 Foo(){} 根据这张图片: >> Foo.prototype -> Foo {} 所以如果我写: Foo.prototype.constructor 现在 - 它引
我读了this article关于 Task.ConfigureAwait,它有助于防止异步代码中的死锁。 看看这段代码:(我知道我不应该做 .Result ,但这是问题的一部分) private v
我正在学习 C#。我可以将闭包理解为一种可以适应其定义环境中的变化的结构吗。 示例: List gurus = new List() {
这个问题在这里已经有了答案: Difference between volatile and synchronized in Java (4 个回答) 关闭6年前。 我对我读到的关于 volatile
我是一名优秀的程序员,十分优秀!