1. 程式人生 > >解決學習tensorflow的LSTM模型中遇到一個版本不相容問題

解決學習tensorflow的LSTM模型中遇到一個版本不相容問題

tensorflow版本降級1.1.0到1.0.0

降級原因:
    在學習LSTM模型預測相關的知識的時候,分別學習了來自github預測餘弦函式和黃文堅 唐源寫的Tensorflow實戰一書第7章的Tensorflow實現基於LSTM的語言模型和TensorFlow入門(五)多層 LSTM 通俗易懂版 的部落格。在執行其程式碼時均報錯如下:
ValueError: Attempt to have a second RNNCell use the weights of a variable scope that already has weights: ‘rnn/multi_rnn_cell/cell_0/basic_lstm_cell’; and the cell was not constructed as BasicLSTMCell(…, reuse=True). To share the weights of an RNNCell, simply reuse it in your second calculation, or create a new one with the argument reuse=True.


其中在一個一篇部落格tensorflow實現基於LSTM的文字分類方法的討論區中討論了這個問題但是沒有給出合理詳細的思路。

博主環境:centos 7, tensorflow1.1.0;python3.6;anaconda3;

萬般無奈下,選擇降低tensorflow的版本,網上絕大部分下載tensorflow的方法是在https://storage.googleapis.com/tensorflow/linux/cpu此連結下得到whl檔案,但是博主開啟時已經顯示失效(想哭),後來發現即使下載下來用pip install 安裝也並沒有卵用,需要和anaconda環境匹配;在
ls /home/guo/anaconda3/pkgs/

路徑下能發現tensorflow的版本是最新的1.1.0,可是怎麼修改為1.0.0呢?

博文中找到了方法,但是不夠完整,博主的步驟如下:

  1. conda list 核實了一遍tensorflow版本;
  2. conda remove tensorflow;同時刪除rm -r /home/guo/anaconda3/pkgs/tensorflow*;把之前的版本刪除乾淨;
  3. source activate tensorflow;
  4. conda install -c conda-forge tensorflow;這時候下載下來的是1.0.0的壓縮包,可以去/home/guo/anaconda3/pkgs/檢視;(理論上下一步應該:conda install tensorflow,但是這個命令會要求你再次升級為1.1.0,所以要謹慎)
  5. source deactivate;
  6. 最關鍵的一步本地安裝:conda install –use-local /home/guo/anaconda3/pkgs/tensorflow-1.0.0-py36_0.tar.bz2
  7. conda list,去核實你的版本吧(最前邊提出的問題也就解決了)