- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道为什么在以下代码中我的毕业生没有得到任何结果:
import tensorflow.keras.losses as losses
loss = losses.squared_hinge(y_true, y_pred)
from tensorflow.keras import backend as K
grads = K.gradients(loss, CNN_model.input)[0]
iterate = K.function([CNN_model.input], [loss, grads])
<tf.Tensor 'conv2d_3_input:0' shape=(?, 28, 28, 1) dtype=float32>
<tf.Tensor 'Mean_3:0' shape=(1,) dtype=float64>
最佳答案
据我之前的经验了解,Tensorflow需要使用GradientTape
为了记录某个变量的事件,从而计算其梯度。在你的情况下应该是这样的:
x = np.random.rand(10) #your input variable
x = tf.Variable(x) #to be evaluated by GradientTape the input should be a tensor
with tf.GradientTape() as tape:
tape.watch(x) #with this method you can observe your variable
proba = model(x) #get the prediction of the input
loss = your_loss_function(y_true, proba) #compute the loss
gradient = tape.gradient(loss, x) #compute the gradients, this must be done outside the recording
关于tensorflow - 为什么 K.gradients 对于损失 wrt 输入的梯度没有返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61261285/
到目前为止,我已经能够使用ssh创建一个小的脚本,并希望将单个命令传递给我正在使用的dd-wrt路由器。现在已经完成了这一步,我希望通过ssh登录多次传递同一命令,而不是仅从文本文件传递一次。 完成此
谁能帮我理解为什么下面的代码会有这样的输出: [ +/- 5.00m (speed 32.65 mps / course 294.26) @ 7/27/16, 4:34:19 AM Eastern D
在一个复杂的库或框架中,显然有时只在内部需要类来实现更高级别的功能。 通常这些内部结构与内部结构的工作方式紧密相关,因此将它们提供给用户没有意义 - 他们所能做的就是尝试篡改您的私有(private)
在 C++ 中,给定替代方案: void fun(int arg1, int arg2opt = 0); // vs. void fun(int arg1, int arg2); void fun(i
好的,这是一个抽象的算法挑战,它将保持抽象,因为它是我将要使用它的地方的最高 secret 。 假设我们有一组对象 O = {o_1, ..., o_N} 和一个对称相似度矩阵 S,其中 s_ij 是
我正在开发一些自定义应用程序,以便在DD-WRT上运行。我正在使用Linksys WRT54GL作为我的开发平台,但闪存空间有限。我想我快没地方了,但我不知道如何显示已用/可用的闪存空间。 linux
我有一个非常大的数据框,其中一些值与一个因素相关联,如下所示: value user 12 USER1 4 USER5 6 USER3 5
这个问题已经有答案了: How can I pivot a dataframe? (5 个回答) 已关闭 5 年前。 DF 说明: Pandas DF 有两列“ID”、“名称”,其中同一“ID”有多个
我正在尝试了解函数类型的变化规则。似乎他们不将输入和输出视为相同(直到对偶)。考虑这个程序。 let mk1 s = s |> Seq.iter (fun _ -> ()) // val mk1 :
我正在使用结构制作一个复数计算器,这是我的 printf 函数 printf("%d%c%di", sum.real, sign, sum.imag); 我可以一切正确,除了一件事,当 sum.ima
我正在尝试在 Swift 中实现一种发布-订阅。在我当前的情况下,有些消息仅发送给接收者,而其他消息还需要触发回调。现在,我定义了一个 enum 来保存不同的消息,例如 enum Message {
我有一个场景,我有 2 个标签需要配置。标签的名称是“Out Date”和“In Date”。我在数据库中只有一个名为“日期”的字段。它是“Out”还是“In”在运行时由枚举“Scenario”的值决
在使用正则表达式帮助解决 Python Challenge 中的问题时, 我遇到了一些让我困惑的行为。 来自 here : (...) 匹配括号内的任何正则表达式。 和 '+' 导致生成的 RE 匹配
我是 dd-wrt 固件开发的初学者。我有一个 Linksys 路由器(型号 E900)并从 dd-wrt 网站下载适用于该型号的固件以自定义此 firmware一些个人要求的网页。我知道 d
大家好,我在 Linksys EA6500 路由器上运行 DD-WRT v.3.0,并且运行以下脚本以便能够访问当前连接到路由器的 WiFi MAC 地址: echo "#!/bin/ash" > /
我有类似下面的内容。 SideTitle r1c1r1c2r2c1r2c2 我使用以下 CSS 将副标题 float 到左侧。 .sideTitle { float: left; } 这是因为边标题根
据我了解,当今大多数浏览器在建立安全连接时首先尝试 TLS,如果未建立连接,它们会回退到 SSL v3。 现在考虑以下场景:我通过 HTTPS 访问网站,该网站已停止支持 SSL v3。我的 mozi
我有一个用 Java 编写的现有解决方案,我很乐意在 OpenWrt 上运行它路由器。 OpenWrt 甚至可以在不安装大量依赖项的情况下运行 Java 吗?有人试过这个吗? 最佳答案 我从未做过,但
我正在尝试使用循环链表来解决约瑟夫斯问题。但是在创建函数中,我遇到了关于指向链表节点的 NULL 指针的段错误。谁能解释为什么会出现段错误?谢谢你! #include using namespace
我已经搜索过转置和枢轴,但找不到类似的东西。输入表: +-----+-------+-------+-------+ | TID | TP1 | TP2 | TP3 | +-----+--
我是一名优秀的程序员,十分优秀!