python - Expected_shape 变量在 tensorflow 中没有任何影响

标签 python tensorflow

在以下代码段中,即使初始值和 expected_shape 不匹配,代码也会运行并给出输出 1.0。这是代码。

import tensorflow as tf
import numpy as np

X = tf.placeholder(dtype=tf.float32)
y = tf.placeholder(dtype=tf.float32)
W = tf.Variable(0.0, expected_shape=(3,1))
b = tf.Variable(1.0)

sess = tf.Session()
init = tf.global_variables_initializer()
sess.run(init)

print(sess.run(tf.add(W,b)))

不是应该抛出错误吗?

最佳答案

目前,建议使用tf.get_variable并尽可能避免使用 tf.Variable。

现在,如果您查看 source code,那么为什么 expected_shape 没有任何效果? ,它被提及是因为它已被弃用并被忽略。如果您进一步查看 _init_from_args 函数,就会发现 expected_shape 参数完全被忽略,并且该值不会用于进一步处理。

关于python - Expected_shape 变量在 tensorflow 中没有任何影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47531328/

相关文章:

python - Tensorflow 对象检测后续步骤

python - 线程不使用python中的所有核心

python - PyOpenGL 是开始学习 opengl 编程的好地方吗?

Python 值错误 : Unknown label type: 'continuous'

python - OpenCV 是否支持 .HEIC 图像格式?

python - 使用python将列表存储到csv文件中

machine-learning - IDE(Pycharm)中无法监控tensorflow权重张量吗?

python - Tensorflow:ImportError:DLL load failed while importing _pywrap_tensorflow_internal:找不到指定的模块

python - TensorFlow:如果我在图形中处理二次计算,是否会消耗更多内存?

python - Tensorflow .pb 文件到 coreml 模型 : 'Unsupported Ops of type: AddV2'