【问题标题】:Gradient of FFT over variables failsFFT 对变量的梯度失败
【发布时间】:2016-07-08 21:00:31
【问题描述】:

在 TensorFlow 中,以下代码失败并出现错误 ValueError: Shapes (3, 32, 28, 28) and () are not compatible

import tensorflow as tf

filters = 32
width = 28
height = 28
channels = 3

x = tf.placeholder(tf.float32, shape=[None, height, width, channels])
w = tf.Variable(tf.truncated_normal([channels, filters, height, width], stddev=0.1))
b = tf.Variable(tf.constant(0.1, shape=[32]))

w_ifft = tf.real(tf.batch_ifft2d(tf.complex(w, 0.0)))
w_ifft_transpose = tf.transpose(w_ifft, [2, 3, 0, 1])

conv = tf.nn.conv2d(x, w_ifft_transpose, strides=[1, 1, 1, 1], padding='SAME')
output = tf.nn.bias_add(conv, b)

print tf.gradients(output, w)

虽然这是一个说明错误的简化示例,但我在变量上使用 iffts 来参数化频域中的卷积滤波器,如 Spectral Representations for Convolutional Neural Networks 中所述

【问题讨论】:

  • 您使用的是什么版本的 TensorFlow?我用 0.9.0 运行它,这段代码打印出[<tf.Tensor 'gradients/Complex_grad/Reshape:0' shape=(3, 32, 28, 28) dtype=float32>]
  • 0.9.0 -- 您是否尝试了最近编辑的代码版本?
  • 是的,似乎工作正常。
  • 我使用的是 python 2.7、tensorflow 0.9.0(通过 pip 安装)、cuda 7.5、cudnn 4.0.7

标签: python neural-network tensorflow conv-neural-network


【解决方案1】:

在你的代码中,w_ifft_transpose 的形状是[height, width, channels, filters],然后你使用我的电脑中的tf.nn.conv2d。 [python 3.5.5 tensorflow 版本 1.1.0、cuda 8.0、cudnn 6.0]

其实你w的参数个数远远大于传统的3*3卷积,你用ifft2d因为不存在复数而没有意义

【讨论】:

    猜你喜欢
    • 2012-08-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-03
    • 2020-06-27
    • 2012-05-15
    • 1970-01-01
    • 2020-02-29
    • 2017-06-05
    相关资源
    最近更新 更多