亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

AttributeError: 模塊“tensorflow”沒有屬性

AttributeError: 模塊“tensorflow”沒有屬性

斯蒂芬大帝 2021-12-09 15:14:33
我正在做一些與圖像字幕相關的任務,我已經加載了這樣的初始模型的權重model = InceptionV3(weights='imagenet')但我收到這樣的錯誤:AttributeError: module 'tensorflow' has no attribute 'get_default_graph'我該怎么辦?請幫忙。這是上述代碼的完整輸出。1 . -------------------------------------------------- ------------------------- AttributeError Traceback (most recent call last) in () 1 # 加載 inception v3 模型 ----> 2 模型= InceptionV3(include_top=True,weights='imagenet') 3 # InceptionV3(weights='imagenet')~/anaconda3/lib/python3.6/site-packages/keras/applications/__init__.pyin wrapper(*args, **kwargs)     26             kwargs['models'] = models     27             kwargs['utils'] = utils---> 28         return base_fun(*args, **kwargs)     29      30     return wrapper~/anaconda3/lib/python3.6/site-packages/keras/applications/inception_v3.pyin InceptionV3(*args, **kwargs)      9 @keras_modules_injection     10 def InceptionV3(*args, **kwargs):---> 11     return inception_v3.InceptionV3(*args, **kwargs)     12      13 ~/anaconda3/lib/python3.6/site-packages/keras_applications/inception_v3.pyin InceptionV3(include_top, weights, input_tensor, input_shape,pooling, classes, **kwargs)    155     156     if input_tensor is None:--> 157         img_input = layers.Input(shape=input_shape)    158     else:    159         if not backend.is_keras_tensor(input_tensor):~/anaconda3/lib/python3.6/site-packages/keras/engine/input_layer.pyin Input(shape, batch_shape, name, dtype, sparse, tensor)    176                              name=name, dtype=dtype,    177                              sparse=sparse,--> 178                              input_tensor=tensor)    179     # Return tensor including _keras_shape and _keras_history.    180     # Note that in this case train_output and test_output are the same pointer.
查看完整描述

3 回答

?
莫回無

TA貢獻1865條經驗 獲得超7個贊

改變

Import keras.<something>.<something>

Import tensorflow.keras.<something>.<something>

其中“something”指的是您要導入的模塊。它對我有用。


查看完整回答
反對 回復 2021-12-09
?
神不在的星期二

TA貢獻1963條經驗 獲得超6個贊

發生這種情況的另一個原因是在tensorflow_backend.py

位于:lib/python3.6/site-packages/keras/backend/

使用tf.compat.v1.get_default_graph獲取圖

而不是tf.get_default_graph。

通過在目錄中替換它,可以成功解決此問題。


查看完整回答
反對 回復 2021-12-09
?
江戶川亂折騰

TA貢獻1851條經驗 獲得超5個贊

我通過更換固定這個問題tensorflow.keras。*到tensorflow.python.keras。*

工作示例:

from tensorflow.python.keras.models import Sequential


查看完整回答
反對 回復 2021-12-09
  • 3 回答
  • 0 關注
  • 304 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號