Win10安装Tensorflow流水账
2021-01-14 02:11
标签:pytho ide data cal 训练 atp rdp models batch 给电脑安装Tensorflow,由于安装过程太过繁琐,记个流水账便于日后再装时查询 安装python 然后安装tensorflow: 如果安装失败可以在这个页面找到对应版本的安装文件用其他工具下载来安装: https://www.tensorflow.org/install/pip 然后就是安装cuda和cudnn了,在这之前相信你已经安装好了显卡驱动.根据https://www.tensorflow.org/install/source_windows的表格找到和你安装的tf对应版本的cuda和cudnn下载来安装. 测试代码: Win10安装Tensorflow流水账 标签:pytho ide data cal 训练 atp rdp models batch 原文地址:https://www.cnblogs.com/DragonStart/p/12258258.html资源下载表
Name
URL
version
Python
https://www.python.org/downloads/
看这个 https://www.tensorflow.org/install/pip
Tensorflow
https://www.tensorflow.org/install/pip
看这个 https://www.tensorflow.org/install/pip
CUDA
https://developer.nvidia.com/cuda-toolkit-archive
看这个 here:https://www.tensorflow.org/install/source_windows
CUDNN
https://developer.nvidia.com/rdp/cudnn-download
看这个 here:https://www.tensorflow.org/install/source_windows
安装过程
用命令安装:pip install --upgrade numpy
pip install --upgrade matplotlib
pip install --upgrade tensorflow-gpu
import tensorflow as tf
import matplotlib.pyplot as plt
# 下载并读取训练数据 验证数据
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
# model = tf.keras.models.Sequential([
# tf.keras.layers.Flatten(input_shape=(28, 28)),
# tf.keras.layers.Dense(512, activation=tf.nn.relu),
# tf.keras.layers.Dropout(0.2),
# tf.keras.layers.Dense(10, activation=tf.nn.softmax)
# ])
# 重组训练数据格式
x_train = x_train.reshape(60000, 28, 28, 1)
x_test = x_test.reshape(10000, 28, 28, 1)
# 定义网络模型
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Conv2D(32, kernel_size=5, input_shape=(28, 28, 1)))
model.add(tf.keras.layers.MaxPool2D(strides=2))
model.add(tf.keras.layers.ReLU())
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(128, activation=tf.nn.sigmoid))
model.add(tf.keras.layers.Dense(128, activation=tf.nn.sigmoid))
model.add(tf.keras.layers.Dense(10, activation=tf.nn.softmax))
# 加载已经训练好的模型权重和偏置参数(如果有)
# model.load_weights('epic_num_reader.model')
# 编译网络模型
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy', metrics=['accuracy'])
# 填充所有训练数据 , epochs: 训练总轮数
model.fit(x_train, y_train, epochs=5)
# 测试模型的准确性和精度(将输出到console)
model.evaluate(x_test, y_test)
# 使用模型识别
x = x_test[0:1]
# plt.figure()
# plt.subplot(4,8,1)
# plt.imshow(x[0],cmap = plt.cm.gray)
# plt.show()
ret = model.predict(x, batch_size=1)
ret = ret
# 保存模型到文件
model.save('epic_num_reader.model')
文章标题:Win10安装Tensorflow流水账
文章链接:http://soscw.com/index.php/essay/41566.html