簡體   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