How to setup: Tensorflow in Windows 10

Some steps may be optional, but recommended. This article is summarized as short as possible. If you want to find more detailed explains, refer to the References.

Install anaconda (optional, but recommended)

How to install anaconda is not scope of this text.

However, In some cases, if already installed version of anaconda fails to upgrade, try this. In most case, it will update without any trouble.

conda update conda
conda update anaconda
conda deactivate
conda update anaconda-navigator

Create a virtual environment using anaconda prompt with following commands. (It’s also possible to create it by using anaconda-navigator)

conda create -n tf2 python=3.8

Install tensorflow

In terminal(or anaconda prompt), type this. This command will install tensorflow 2.x that supports both GPU and CPU.

pip install tensorflow

Install cuda, cudnn

Both cuda and cudnn library must be installed to use GPU in tensorflow. At this time, tensorflow 2.4 supports cuda 11. The cuda 11 supports RTX 20xx, RTX 30xx series video cards.

When you unzip the downloaded file, you can see followings.

Move whole folders to

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2

The path may be differ depends on your system.

Test

In python prompt, try this. You can see appropriate working log message. If not, make sure that you have install Cuda11.

from tensorflow.python.client import device_lib
device_lib.list_local_devices()

If you see the details about your video card in the terminal, it’s done well.

One more thing

Simple machine learning code. [2]

import numpy as np 
import tensorflow as tf
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(128, activation='relu'), tf.keras.layers.Dropout(0.2), tf.keras.layers.Dense(10)])loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)model.compile(optimizer='adam',loss=loss_fn,metrics=['accuracy'])
model.fit(x_train, y_train, epochs=5)

If you see following logs, it’s ready to roll.

Trouble shooting

In some cases, you may encounter following error.

W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cusolver64_10.dll'; dlerror: cusolver64_10.dll not found

go to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin

cp cusolver64_11.dll cusolver64_10.dll

References

[1] Installation Guide :: NVIDIA Deep Learning cuDNN Documentation

[2] https://koos808.tistory.com/41

[3] python — Tensorflow GPU Could not load dynamic library ‘cusolver64_10.dll’; dlerror: cusolver64_10.dll not found — Stack Overflow

--

--

Memento

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store