keras环境搭建 [过程记录]
生活随笔
收集整理的這篇文章主要介紹了
keras环境搭建 [过程记录]
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 虛擬環境安裝
1.安裝anaconda
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/2.進入anaconda prompt
conda config --show channels conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/ #如果想刪掉 conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/ #但是上面那種方法會把channels變成空的[],所以我們還是選擇換回默認源更好 conda config --remove-key channels #查看當前使用源 conda config --show-sources #ssl_verify: True #show_channel_urls: True conda create -n keras #創建虛擬環境 conda activate keras #進入虛擬環境 pip install tensorflow==2.0 -i https://pypi.doubanio.com/simple pip install keras-i https://pypi.doubanio.com/simple #報錯Cannot unpack file后改為下面一行可正常運行 pip install keras -i https://pypi.doubanio.com/simple --trusted-host pypi.doubanio.com python #進入python #測試是否安裝成功 #導入keras時使用如下代碼,在 tensorflow2.X 中導入keras模塊代碼使用下述方法會報錯 from keras.layers import Input, Dense, Conv2D, MaxPooling2D, PReLU, Flatten, Softmax from keras.models import Model#解決辦法:將上述py文件中代碼修改為: from tensorflow.keras.layers import Input, Dense, Conv2D, MaxPooling2D, PReLU, Flatten, Softmax from tensorflow.keras.models import Model#ImportError: cannot import name ‘get_config’ from ‘tensorflow.python.eager.context’ 這個類型報錯的問題我遇到的都可以通過導入包時使用tensorflow.keras解決#該報錯解決方案的原文鏈接:https://blog.csdn.net/qq_29304033/article/details/117258910 conda install nb_conda #這一句一直報錯,感覺是和之前conda鏡像怎么都設置不好有關 #暫未解決,但不知道為什么jupyter notebook不進入虛擬環境也莫名可以使用tensorflow.keras #xs 不知道為什么根本就沒裝到虛擬環境里去,直接裝在base環境里了,把虛擬環境文件夾刪了…就先這樣吧所以整理一個不在虛擬環境里搭建keras的方法:
2 直接安裝
1.下載anaconda
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/2.進入anaconda prompt
#安裝后端tensorflow pip install tensorflow==2.0 -i https://pypi.doubanio.com/simple#安裝前端keras pip install keras -i https://pypi.doubanio.com/simple --trusted-host pypi.doubanio.com python #進入python #測試是否安裝成功 #導入keras時使用如下代碼,在 tensorflow2.X 中導入keras模塊代碼使用下述方法會報錯 from keras.layers import Input, Dense, Conv2D, MaxPooling2D, PReLU, Flatten, Softmax from keras.models import Model#解決辦法:將上述py文件中代碼修改為: from tensorflow.keras.layers import Input, Dense, Conv2D, MaxPooling2D, PReLU, Flatten, Softmax from tensorflow.keras.models import Model#ImportError: cannot import name ‘get_config’ from ‘tensorflow.python.eager.context’ 這個類型報錯的問題我遇到的都可以通過導入包時使用tensorflow.keras解決#該報錯解決方案的原文鏈接:https://blog.csdn.net/qq_29304033/article/details/117258910 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的keras环境搭建 [过程记录]的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 程一笑:快手电商GMV已达到万亿规模
- 下一篇: 讯飞发布星火认知大模型及四大行业应用成果