Win10 installation Tensorflow running account

To install computer Tensorflow, because the installation process is too cumbersome, easy to remember running account query a later date equipment

Download table

Name URL version
Python https://www.python.org/downloads/ Look at this https://www.tensorflow.org/install/pip
Tensorflow https://www.tensorflow.org/install/pip Look at this https://www.tensorflow.org/install/pip
CUDA https://developer.nvidia.com/cuda-toolkit-archive Look at this here Wallpaper: https://www.tensorflow.org/install/source_windows
CUDNN https://developer.nvidia.com/rdp/cudnn-download Look at this here Wallpaper: https://www.tensorflow.org/install/source_windows

Installation process

Install python

Then install tensorflow:
with the command to install:

pip install --upgrade numpy
pip install --upgrade matplotlib
pip install --upgrade tensorflow-gpu

If the installation fails can find the corresponding version of the installation file on this page to download other tools to install: https://www.tensorflow.org/install/pip

Then it is to install cuda and cudnn, and before that I believe you have installed the graphics driver. Https://www.tensorflow.org/install/source_windows according to the table and find you install the corresponding version of tf cuda to download and cudnn installation.

Test code:

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')

Guess you like

Origin www.cnblogs.com/DragonStart/p/12258258.html