tensorflow - 如何手动计算 tensorflow 中 conv3d 的反向传播?
问题描述
在 tensorflow 中,对于 2D 卷积,有一个有用的评论是关于如何将输入和权重的反向传播再次映射到 2D 卷积。你可以在这里找到它。
我知道卷积反向传播的基本原理。但是,我不能像 2D 卷积那样将反向传播映射到前向卷积。我也不想对反向道具使用矩阵乘法。
现在,我正在为 3D 卷积寻找类似的东西。我们如何通过使用另一个 3D 卷积计算输入和权重的 3D 卷积的反向传播?
我只想让代码如下所示:
with tf.GraientTape() as tape:
y = tf.nn.conv3d(x, w) # forward pass
L = tf.math.reduce_mean(y, axis = [1, 2, 3, 4]) # calculate loss for each sample in the batch which can be anything.
dl_dy, dl_dx, dl_dw = tape.gradient(L, [y, x, w])
dl_dx_est = tf.nn.conv3d(dl_dy, w)
dl_dw_est = tf.nn.conv3d(x, dl_dy)
在上面的代码中,我们有:
x.shape = [batch, in_depth, in_height, in_width, in_channels]
w.shape = [filter_depth, filter_height, filter_width, in_channels, out_channels]
y.shape = [batch, out_depth, out_height, out_width, out_channels]
现在的目标是拥有tf.reduce_mean(tf.abs(dl_dx_est - dl_dx)) == 0.0
和相同的东西dl_dw_est
。我可能需要填充/旋转/转置 w 和 dl_dy 和 x 但我不知道怎么做?
总之,在 tensorflow 代码中包含类似于注释(提到的链接)的内容将是理想的。
解决方案
推荐阅读
- xamarin - 未找到命名空间上的类型的 Xamarin Forms 默认构造函数。ShowOverlay
- batch-file - 过滤批处理文件 cmd 输出到文件
- python - 在分配该特定实例时“不能分配必须是一个实例”
- php - PHP/MySQL 多个查询好吗?
- python - 将值从 HTML 页面传递到烧瓶应用程序以实现数据库连接
- sql - 权限错误 - 创建数据库链接 Oracle
- regex - 如何在postgresql中提取电子邮件最后一个'@'字符之前的部分?
- spreadsheet - Excel 2013 中的条件格式
- php - 准确比较来自不同时区的日期与归零时间
- laravel - Laravel Auth::guard('api')->user() 返回 null