国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

解決 AttributeError: module ‘tensorflow‘ has no attribute ‘contrib‘ 等類似的問題

這篇具有很好參考價(jià)值的文章主要介紹了解決 AttributeError: module ‘tensorflow‘ has no attribute ‘contrib‘ 等類似的問題。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

1、項(xiàng)目場(chǎng)景:

使用tensorflow2.x版本的時(shí)候,使用調(diào)用tensorflow1.x函數(shù)的代碼時(shí),常常會(huì)出現(xiàn)module ‘tensorflow’ has no attribute ‘contrib’這樣的問題,這是由于tensorflow2.x廢棄了很多tensorflow1.x API接口,本文針對(duì)常見的幾種錯(cuò)誤來使tf2.0不降版本也能運(yùn)行代碼。


2、問題描述和解決辦法

1、報(bào)錯(cuò)AttributeError: module ‘tensorflow’ has no attribute ‘random_normal’

在報(bào)錯(cuò)的行數(shù)將tf.random_normal修改成tf.random.normal即可

代碼修改前:

w = tf.Variable(tf.random_normal([num_neurons[-1], 1]))

代碼修改后:

w = tf.Variable(tf.random.normal([num_neurons[-1], 1])

2、報(bào)錯(cuò) AttributeError: module ‘tensorflow’ has no attribute ‘placeholder’

將前邊的import tensorflow改成兼容處理的tensorflow.compat.v1,再禁用eager_execution

代碼修改前:

import tensorflow as tf

代碼修改后:

import tensorflow.compat.v1 as tf
tf.compat.v1.disable_eager_execution()

3、報(bào)錯(cuò)AttributeError: module ‘tensorflow’ has no attribute ‘contrib’

這個(gè)是比較麻煩的,因?yàn)閠ensorflow2.x版本已經(jīng)沒有contrib庫,但是讀者可以試試下面的方法
首先用placeholder的方法,先修改import tensorflow as tf 改成

import tensorflow.compat.v1 as tf
tf.compat.v1.disable_eager_execution()

BasicLSTMCell處理方法,DropoutWrapper和MultiRNNCell同理
代碼修改前:

cell = tf.contrib.rnn.BasicLSTMCell(num_units=units, forget_bias=0.9)

代碼修改后:

cell = tf.nn.rnn_cell.BasicLSTMCell(num_units=units,forget_bias=0.9)

將contrib.rnn 改成 nn.rnn_cell,如果使用了static_rnn類似的,就把contrib.rnn改成nn即可

代碼修改前:

outputs, _ = tf.contrib.rnn.static_rnn(stacked_lstm_cells, inputs, dtype=tf.float32)

代碼修改后:

outputs, _ = tf.nn.static_rnn(stacked_lstm_cells, inputs, dtype=tf.float32)

參考博客
①tf2.0不降版本也能完美解決module ‘tensorflow’ has no attribute ‘contrib’ 等類似的問題
②tf2.0不降版本也能完美解決module ‘tensorflow’ has no attribute ‘contrib’的問題文章來源地址http://www.zghlxwxcb.cn/news/detail-780905.html


到了這里,關(guān)于解決 AttributeError: module ‘tensorflow‘ has no attribute ‘contrib‘ 等類似的問題的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 解決AttributeError: module tensorflow has no attribute reset_default_graph

    目錄 解決AttributeError: module tensorflow has no attribute reset_default_graph 錯(cuò)誤原因 解決方法 步驟1: 查看TensorFlow版本 步驟2: 替換過時(shí)的方法或?qū)傩?步驟3: 更新代碼 步驟4: 手動(dòng)重置默認(rèn)圖(如果適用) 結(jié)論 在使用TensorFlow進(jìn)行深度學(xué)習(xí)任務(wù)時(shí),有時(shí)會(huì)遇到類似于\\\"AttributeError: module \\\'te

    2024年02月04日
    瀏覽(20)
  • 解決AttributeError: module ‘keras‘ has no attribute ……

    在成功解決AttributeError: module ‘keras‘ has no attribute ‘utils‘_new1998的博客-CSDN博客這篇博客中博主有提到如何解決這一問題,其中就是要把 更改成為 而博主不知道其中原因,原因其實(shí)是在TensorFlow 2.4及以上版本中, import keras 的方式已經(jīng)被棄用,取而代之的是 import tensorflow.k

    2024年02月11日
    瀏覽(31)
  • 解決AttributeError: module ‘serial‘ has no attribute ‘Serial‘

    最近在搞上位機(jī)時(shí)遇到了報(bào)錯(cuò)AttributeError: module ‘serial’ has no attribute ‘Serial’,翻譯過來就是serial類沒有Serial對(duì)象。然后卡了一個(gè)小時(shí)才解決,試了網(wǎng)上很多方法,最后才發(fā)現(xiàn)報(bào)錯(cuò)原因,這問題python也有責(zé)任。 下面說下一般的解決方法。 python3之后串口都改為pyserial,seria

    2024年02月02日
    瀏覽(19)
  • AttributeError: module ‘numpy‘ has no attribute ‘bool‘解決

    AttributeError: module ‘numpy‘ has no attribute ‘bool‘解決

    問題原因:在numpy的1.24版本已經(jīng)棄用了np.bool這個(gè)名稱,取而代之的是np.bool_ 解決方法: 1.點(diǎn)擊出錯(cuò)文件 2.將np.bool更改為np.bool_

    2024年02月12日
    瀏覽(27)
  • 【已解決】AttributeError: module ‘numpy‘ has no attribute ‘int‘.

    【已解決】AttributeError: module ‘numpy‘ has no attribute ‘int‘.

    AttributeError: module ‘numpy’ has no attribute ‘int’. np.int was a deprecated alias for the builtin int . To avoid this error in existing code, use int by itself. Doing this will not modify any behavior and is safe. 新版本的numpy里面沒有np.int了。 第一種,降低numpy版本,安裝1.20以下的版本。 第二種,修改源碼。 將 修

    2024年02月14日
    瀏覽(26)
  • 【已解決】AttributeError: module ‘pandas‘ has no attribute ‘Series‘

    【已解決】AttributeError: module ‘pandas‘ has no attribute ‘Series‘

    問題描述:pandas是用于數(shù)據(jù)處理和分析的包,本文是基于筆者在進(jìn)行模型訓(xùn)練時(shí)遇到的一個(gè)問題,于是隨筆記錄下了從發(fā)現(xiàn)問題到解決問題的整個(gè)過程。 當(dāng)遇到AttributeError: module \\\'pandas\\\' has no attribute \\\'Series\\\'這樣的錯(cuò)誤,首先我是在python命令行中進(jìn)行測(cè)試Series屬性是否可用。 ?

    2024年02月11日
    瀏覽(27)
  • 成功解決AttributeError: module ‘numpy‘ has no attribute ‘float‘.

    AttributeError: module ‘numpy’ has no attribute ‘float’. np.float was a deprecated alias for the builtin float . To avoid this error in existing code, use float by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.float64 here. The aliases was originally deprecated in NumPy 1.20; for

    2024年02月16日
    瀏覽(25)
  • AttributeError: module ‘numpy‘ has no attribute ‘a(chǎn)rray‘解決辦法

    AttributeError: module ‘numpy‘ has no attribute ‘a(chǎn)rray‘解決辦法

    NumPy是Python中重要的數(shù)值計(jì)算庫,提供了強(qiáng)大的數(shù)組操作和數(shù)學(xué)函數(shù)。然而,有時(shí)候我們可能會(huì)在使用NumPy時(shí)遇到\\\"AttributeError: module ‘numpy’ has no attribute ‘a(chǎn)rray’\\\"的錯(cuò)誤提示,這可能會(huì)讓一些用戶感到困惑。在本文中,我們將分享如何解決這個(gè)問題的方法,并幫助讀者更好地

    2024年02月13日
    瀏覽(24)
  • AttributeError: module ‘openai‘ has no attribute ‘error‘解決方案

    AttributeError: module ‘openai‘ has no attribute ‘error‘解決方案

    ??大家好,我是愛編程的喵喵。雙985碩士畢業(yè),現(xiàn)擔(dān)任全棧工程師一職,熱衷于將數(shù)據(jù)思維應(yīng)用到工作與生活中。從事機(jī)器學(xué)習(xí)以及相關(guān)的前后端開發(fā)工作。曾在阿里云、科大訊飛、CCF等比賽獲得多次Top名次?,F(xiàn)為CSDN博客專家、人工智能領(lǐng)域優(yōu)質(zhì)創(chuàng)作者。喜歡通過博客創(chuàng)作

    2024年01月17日
    瀏覽(19)
  • 完美解決 AttributeError: module ‘torch.utils‘ has no attribute ‘data‘

    完美解決 AttributeError: module ‘torch.utils’ has no attribute ‘data’ 下滑查看解決方法 AttributeError: module ‘torch.utils‘ has no attribute ‘data‘ 這個(gè)錯(cuò)誤通常是由于使用了過時(shí)的torch版本導(dǎo)致的。在舊的torch版本中,torch.utils.data模塊是存在的,但在新版的torch中已經(jīng)被移除,因此會(huì)出現(xiàn)

    2024年02月07日
    瀏覽(24)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包