我在我的 Pycharm 中编写了以下代码,它在 Tensorflow 中执行完全连接层 (FCL)。占位符发生无效参数错误。所以我在占位符中输入了所有dtype
, shape
, 和name
,但我仍然收到无效参数错误。
我想通过 FCL 模型制作新的 Signal(1, 222)。
输入信号(1, 222) => 输出信号(1, 222)
maxPredict
: 找出输出信号中具有最高值的索引。
calculate Y
: 获取maxPredict对应的频率数组值。
loss
:使用真实 Y 之间的差异并将 Y 计算为损失。
loss
= tf.abs(trueY - calculateY)`
代码(发生错误)x = tf.placeholder(dtype=tf.float32, shape=[1, 222], name='inputX')
错误
InvalidArgumentError(回溯见上文):您必须使用 dtype float 和 shape [1,222] tensorflow.python.framework.errors_impl.InvalidArgumentError 为占位符张量“inputX”提供一个值:您必须为占位符张量“inputX”提供一个值与 dtype float 和 shape [1,222] [[{{node inputX}} = Placeholderdtype=DT_FLOAT, shape=[1,222], _device="/job:localhost/replica:0/task:0/device:CPU:0"]] 在处理上述异常,又发生了一个异常:
我改变了我的代码。x = tf.placeholder(tf.float32, [None, 222], name='inputX')
错误案例 1tensorFreq = tf.convert_to_tensor(basicFreq, tf.float32)
newY = tf.gather(tensorFreq, maxPredict) * 60
loss = tf.abs(y - tf.Variable(newY))
ValueError:initial_value 必须指定一个形状:Tensor("mul:0", shape=(?,), dtype=float32)
错误案例 2tensorFreq = tf.convert_to_tensor(basicFreq, tf.float32)
newY = tf.gather(tensorFreq, maxPredict) * 60
loss = tf.abs(y - newY)
回溯(最近一次调用):文件“D:/PycharmProject/DetectionSignal/TEST_FCL_StackOverflow.py”,第 127 行,trainStep = opt.minimize(loss) 文件“C:\Users\Heewony\Anaconda3\envs\TSFW_pycharm\lib \site-packages\tensorflow\python\training\optimizer.py”,第 407 行,最小化([str(v) for _,v in grads_and_vars],loss))ValueError:没有为任何变量提供梯度,检查你的图表对于不支持梯度的操作,变量之间 [tf.Variable 'Variable:0' shape=(222, 1024) dtype=float32_ref, tf.Variable 'Variable_1:0' shape=(1024,) dtype=float32_re, .. ....... tf.Variable 'Variable_5:0' shape=(222,) dtype=float32_ref] 和损失 Tensor("Abs:0", dtype=float32)。
操作系统平台和发行版:Windows 10 x64
TensorFlow 安装自:Anaconda
Tensorflow 1.12.0 版:
蟒蛇 3.6.7:
移动设备:不适用
重现的确切命令:N/A
GPU 型号和内存:NVIDIA GeForce CTX 1080 Ti
CUDA/cuDNN:9.0/7.4
森林海
小怪兽爱吃肉
相关分类