win10安装Tensorflow-cpu(AMD显卡) && keras

安装环境:WIN10 AMD集显😭😭

Anaconda版本:Anaconda3-4.4.0 (64位)(建议不要装最新的,历史版本可在 清华大学开源软件镜像站 下载

Python版本:Python 3.5(在安装Anaconda3时勾选了3.6)
勾选两个框
图一

Tensorflow版本:tensorflow 1.8
Tensorflow版本
图二

一. 安装Anaconda

1. 根据上面清华大学开源软件镜像站下载对应的安装包,并安装,(看挺多博文建议安装在C盘,所以我的也是安装在了C盘)

2. 检查是否安装成功:conda --version (在Anaconda Prompt 或者 命令提示符 输入命令行均可)

在Anaconda Prompt输入命令行
图三

3. 检测当前安装环境:conda info --envs

 *注意*   本图是安装之后的图片,安装前,并没有
 tensorflow               C:\Users\xxx\Anaconda3\envs\tensorflow  一行

检测安装环境
图四

4. 检查目前有哪些版本的python可以安装:

conda search --full-name python

5. 选择一个python版本安装(这里选择python3.5.4版本):

conda create --name tensorflow python=3.5.4

6. 激活tensorflow :

activate tensorflow

7. tensorflow环境被成功添加:(如图四所示) ;

conda info --envs

查看tensorflow环境下的python版本:python --version(如图五所示)
查看tensorflow环境下的python版本
图五

二. Tensorflow 1.8 安装

1. 打开anaconda prompt

2. 安装 cpu 版本的 tensorflow

注意:需要激活tensorflow下

python -m pip install tensorflow==1.8.0 -i https://pypi.douban.com/simple

安装cpu 版本的 tensorflow

3.安装成功后测试

import tensorflow as tf  
hello = tf.constant('Hello, TensorFlow!')  
sess = tf.Session()  
print(sess.run(hello))  

期间有个提示:
提示
解决方法:可参考此文

三.安装keras

1. 打开anacoda prompt

2. 激活tensorflow

activate tensorflow

3. 输入python

4. 安装 keras

pip install keras

5. 测试

安装完成后,输入

import keras

若返回 Using TensorFlow backend, 则说明安装成功
安装成功

6. 测试

import numpy as np
from keras.models import Sequential
from keras.layers import Dense, Dropout

# Generate dummy data
x_train = np.random.random((1000, 20))
y_train = np.random.randint(2, size=(1000, 1))
x_test = np.random.random((100, 20))
y_test = np.random.randint(2, size=(100, 1))

model = Sequential()
model.add(Dense(64, input_dim=20, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(1, activation='sigmoid'))

model.compile(loss='binary_crossentropy',
              optimizer='rmsprop',
              metrics=['accuracy'])
model.fit(x_train, y_train,
          epochs=20,
          batch_size=128)
score = model.evaluate(x_test, y_test, batch_size=128)

测试结果

1000/1000 [==============================] - 0s 282us/step - loss: 0.7214 - acc: 0.5000
Epoch 2/20
1000/1000 [==============================] - 0s 18us/step - loss: 0.7102 - acc: 0.4870
Epoch 3/20
1000/1000 [==============================] - 0s 17us/step - loss: 0.7049 - acc: 0.5080
Epoch 4/20
1000/1000 [==============================] - 0s 15us/step - loss: 0.6985 - acc: 0.5110
Epoch 5/20
1000/1000 [==============================] - 0s 15us/step - loss: 0.6963 - acc: 0.5120
Epoch 6/20
1000/1000 [==============================] - 0s 15us/step - loss: 0.6952 - acc: 0.5100
Epoch 7/20
1000/1000 [==============================] - 0s 14us/step - loss: 0.6970 - acc: 0.5170
Epoch 8/20
1000/1000 [==============================] - 0s 13us/step - loss: 0.6894 - acc: 0.5240
Epoch 9/20
1000/1000 [==============================] - 0s 13us/step - loss: 0.6976 - acc: 0.5150
Epoch 10/20
1000/1000 [==============================] - 0s 14us/step - loss: 0.6922 - acc: 0.5320
Epoch 11/20
1000/1000 [==============================] - 0s 14us/step - loss: 0.6889 - acc: 0.5340
Epoch 12/20
1000/1000 [==============================] - 0s 14us/step - loss: 0.6916 - acc: 0.5150
Epoch 13/20
1000/1000 [==============================] - 0s 14us/step - loss: 0.6920 - acc: 0.5180
Epoch 14/20
1000/1000 [==============================] - 0s 15us/step - loss: 0.6917 - acc: 0.5410
Epoch 15/20
1000/1000 [==============================] - 0s 13us/step - loss: 0.6897 - acc: 0.5410
Epoch 16/20
1000/1000 [==============================] - 0s 12us/step - loss: 0.6983 - acc: 0.4920
Epoch 17/20
1000/1000 [==============================] - 0s 13us/step - loss: 0.6910 - acc: 0.5230
Epoch 18/20
1000/1000 [==============================] - 0s 13us/step - loss: 0.6873 - acc: 0.5390
Epoch 19/20
1000/1000 [==============================] - 0s 14us/step - loss: 0.6920 - acc: 0.5250
Epoch 20/20
1000/1000 [==============================] - 0s 14us/step - loss: 0.6910 - acc: 0.5490
100/100 [==============================] - 0s 460us/step

7.遇到的一个问题:keras版本过高

ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via

目前版本太高,需要降版本到2.2

pip install keras==2.2 -i https://pypi.douban.com/simple

欧克,安装完成,大功告成!

参考文章:

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值