繁体   English   中英

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

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

运行在 keras 中制作的 CNN 时出现以下错误

文件“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 “张量流”没有属性“截断正常”

我已经多次安装并重新安装了 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.

对于 TewnsorFlow 2.x 和 keras 2.3 或以上版本,以下用法适应性更强。 用户无需同时降级 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()

干杯!

Tensorflow v2.0及以上版本,“ tf.truncated_normal ”替换为“ tf.random.truncated_normal

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM