Keras+tensorflow-gpu环境安装

import tensorflow as tf
import pandas as pd
import numpy as np
import keras
from keras.models import Model
from keras.layers import Input,Flatten,Dense,Conv1D,Conv2D,MaxPool2D,Dropout
from keras.layers import  Embedding, Concatenate
from keras.layers import LSTM
from sklearn.preprocessing import StandardScaler,MinMaxScaler
from matplotlib import pyplot
from math import sqrt
from sklearn.metrics import mean_squared_error

方法1
1.安装python3.6+tensorflow+Keras(gpu)

```python
conda create -n keras-gpu python=3.6
activate keras-gpu
conda install -c anaconda keras-gpu

2.报错
2.1

如果keras的版本和tensorflow的版本不一致,就会报错。

我的tensorflow的版本是1.10.0,而keras的版本是2.6.0

解决方案:
pip uninstall keras
pip install keras==2.2.0

2.2
ModuleNotFoundError: No module named ‘sklearn’

解决方案:
 pip install -U scikit-learn

2.3
ModuleNotFoundError: No module named ‘matplotlib’

解决方案:
pip install matplotlib

2.4
Missing optional dependency ‘xlrd’. Install xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd.
0

解决方案:
pip install xlrd

2.5
D:\Install\Anaconda3\envs\keras-gpu\lib\site-packages\tensorflow\python\framework\dtypes.py:462: FutureWarning: Passing (type, 1) or ‘1type’ as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / ‘(1,)type’.
np_resource = np.dtype([(“resource”, np.ubyte, 1)])
numpy版本需要升级
Requirement already up-to-date: numpy in d:\install\anaconda3\envs\keras-gpu\lib\site-packages (1.19.5)

pip  install --target=d:\install\anaconda3\envs\keras-gpu\lib\site-packages numpy

方法2
直接利用conda,安装整个GPU环境,相对而言,更快,更简单一些

1、默认源通常下载速度慢,将清华大学的conda软件源添加进去,保证安装的速度。

conda config –-show 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mro/ 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2/ 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro/ 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/ 
conda config --set show_channel_urls yes 
conda config --show
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

2、安装代码,其中需要查询tensorflow对应的cudatoolkit,cudnn版本,同时cudatoolkit,cudnn版本受限于显卡,需要先查询自己电脑支持的显卡支持的最高版本。


conda create -n keras-gpu python=3.6
activate keras-gpu
conda install cudatoolkit=9.0(xx为自己需要的版本号)
conda install cudnn=7.1
pip install tensorflow-gpu=x.x.x

3、示例(本文安装环境版本)
python3.6+tensorflow-gpu(1.10.0)+keras(2.2.4)+cudatoolkit(9.0)+cudnn(7.1.4)
Keras+tensorflow-gpu环境安装_第1张图片
Keras+tensorflow-gpu环境安装_第2张图片

Keras+tensorflow-gpu环境安装_第3张图片

推荐参考博客:

GPU版本Tensorflow+Keras环境安装与配置_keras 2.9.0与tensorflow-gpu版本_繁星之歌的博客-CSDN博客** https://blog.csdn.net/mangfan1993/article/details/121486811?spm=1001.2101.3001.6650.4&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-4-121486811-blog-106436292.235%5Ev38%5Epc_relevant_sort_base2&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-4-121486811-blog-106436292.235%5Ev38%5Epc_relevant_sort_base2&utm_relevant_index=5

快速简单安装tensorflow与keras的GPU版本_SJTUzhou的博客-CSDN博客 https://blog.csdn.net/SJTUzhou/article/details/106436292

你可能感兴趣的:(keras,tensorflow,python)