简体   繁体   English

在 virtualenv 中运行 tensorflow 时出错:模块 'tensorflow' 没有属性 'truncated_normal'

[英]Error when running tensorflow in virtualenv: module 'tensorflow' has no attribute 'truncated_normal'

I have the following error when running a CNN made in keras运行在 keras 中制作的 CNN 时出现以下错误

File "venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 4185, in truncated_normal return tf.truncated_normal(shape, mean, stddev, dtype=dtype, seed=seed) AttributeError: module 'tensorflow' has no attribute 'truncated_normal'文件“venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py”,第 4185 行,在 truncated_normal return tf.truncated_normal(shape, mean, stddev, dtype=dtype, seed=seed) AttributeError: module “张量流”没有属性“截断正常”

I have already installed and reinstalled Tensorflow 2.0 several times.我已经多次安装并重新安装了 Tensorflow 2.0。 What could be happening?会发生什么?

Keras 2.2.4 does not support TensorFlow 2.0 (it was released much before TF 2.0), so you can either downgrade TensorFlow to version 1.x, or upgrade Keras to version 2.3, which does support TensorFlow 2.0. Keras 2.2.4 does not support TensorFlow 2.0 (it was released much before TF 2.0), so you can either downgrade TensorFlow to version 1.x, or upgrade Keras to version 2.3, which does support TensorFlow 2.0.

For TewnsorFlow 2.x and keras 2.3 or the above, the following usage is more adaptable.对于 TewnsorFlow 2.x 和 keras 2.3 或以上版本,以下用法适应性更强。 Users do not need to downgrade both TensorFlow and Keras.用户无需同时降级 TensorFlow 和 Keras。

# Add the import statements 
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

# Change it to the sample expression as follows. 
init = tf.compat.v1.random.truncated_normal()

Cheers!干杯!

In Tensorflow v2.0 and above, " tf.truncated_normal " replaced with " tf.random.truncated_normal " Tensorflow v2.0及以上版本,“ tf.truncated_normal ”替换为“ tf.random.truncated_normal

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Tensorflow Object 检测 API - 错误运行 model_builder_test.py 模块 'tensorflow' 没有属性 'contrib' - Tensorflow Object Detection API - Error running model_builder_test.py module 'tensorflow' has no attribute 'contrib' AttributeError:模块“tensorflow”没有属性“app”:错误 - AttributeError: module 'tensorflow' has no attribute 'app': error tensorflow 错误:模块没有属性 GraphDef - tensorflow error: module has no attribute GraphDef 属性错误:模块“tensorflow”没有属性“变量”“错误” - AttributeError: module 'tensorflow' has no attribute 'Variable' “ERROR” Tensorflow 2.1.0 错误,模块“tensorflow”没有属性“GraphKeys” - Tensorflow 2.1.0 Error, module 'tensorflow' has no attribute 'GraphKeys' Tensorflow 错误:AttributeError:模块“tensorflow”没有属性“placeholder” - Tensorflow error: AttributeError: module 'tensorflow' has no attribute 'placeholder' 运行pythonw时,VirtualEnv TensorFlow安装验证带有“ ImportError:没有名为tensorflow的模块” - VirtualEnv TensorFlow installation validation with “ImportError: No module named tensorflow” when running pythonw Tensorflow:模块'tensorflow'没有属性'constant' - Tensorflow: module 'tensorflow' has no attribute 'constant' 模块“tensorflow”没有属性“log” - module 'tensorflow' has no attribute 'log' 模块Tensorflow没有属性KMeans - Module Tensorflow has no attribute KMeans
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM