Use Tensorflow 2.1.0 with Anaconda on Windows 10!

Conclusion first

** TensorFlow 2.1.0 is now available on Python 3.7 on Windows 10! ** **

Preface

The other day I tried using TensorFlow 2.1.0 using the environment of Google Colab. I was impressed that it was convenient to use it without any preparation, but I tried to build an environment and test it because I wanted to run it on a local machine and I wanted to run it on the Jupyter Notebook I had been using before ..

Rough flow

  1. Create a new virtual environment with ** Anaconda Navigtor **
  2. Install ** Microsoft Visual C ++ Redistributable Package ** for Visual Studio 2015, 2017 and 2019
  3. Install libraries such as ** TensorFlow, matplotlib ** with Anaconda Navigtor
  4. Installation confirmation
  5. Let's actually move ** TensorFlow 2.0 ** to recognize handwritten characters I got stuck in two items. It seems that you need to install additional packages to use ** TensorFlow 2.1.0 ** Maybe this is the point where you have to worry about installing ** TensorFlow 2.1.0 ** on ** Windows 10 **?

1. Create a new environment with Anaconda Navigator

2. Install the Microsoft Visual C ++ Redistributable Package for Visual Studio 2015, 2017 and 2019

https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads/ Download and install the Microsoft Visual C ++ Redistributable Package for Visual Studio 2015, 2017 and 2019 from the url above. TensorFlow 2.1.0 and later versions seem to require the msvcp140_1.dll file included in this package. visual.png

This file itself is included in Visual Studio 2019, so if you have VS 2019 installed, it's okay.

3. Install libraries such as Tensorflow and matplotlib with Anaconda Navigtor

It's almost time to finish this far. Go back to ** Anaconda Navigator **, select the environment generated by environment, set the item on the left of the right menu to ALL or Not Installed, search for ** tensorflow, matplotlib **, add a check box, and apply. Install it. ** TensorFlow 2.1.0 ** is a fairly large library, so it will take some time to install, but let's wait. anaconda_inst.png

4. Installation confirmation

Select open with Python in the play button to the right of the ** Anaconda Navigator ** environment name to open a command prompt. Now run the following to import and check the version of TensorFlow, and if there are no errors, the installation was successful!

import tensorflow
print(tf.__version__)

Warning! HDF5 library version mismatched error If you get an error like this, there is a possibility that the HDF5 library has a version inconsistency. After checking the operation once, this phenomenon occurred and TensorFlow could not be imported. I reinstalled the HDF5 library and it was cured.

pip uninstall h5py
pip install --user h5py

5. Let's actually run TensorFlow 2.0 to recognize handwritten characters

This completes the environment construction for TensorFlow 2.1.0! Finally, we will build and train a neural network by referring to "Introduction to TensorFlow 2.0 for beginners" on the official TensorFlow website. Launch Jupyter Notebook and execute the following code.

First, we take in a training data set called mnist for image recognition etc. and build a model of neural network.

Dataset loading, model building


from __future__ import absolute_import, division, print_function, unicode_literals
#Install TensorFlow
import tensorflow as tf
#Read dataset from mnist
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
#Neural network model setting and construction
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, activation='softmax')
])
model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])

Model training and evaluation


model.fit(x_train, y_train, batch_size=32, epochs=5)
model.evaluate(x_test,  y_test, verbose=2)

Here are the progress and results of the training. train.png

View the contents of the dataset


#Import helper library
import numpy as np
import matplotlib.pyplot as plt
#10 data*Output to 6
for i in range(0,60):
  plt.subplot(6,10,i+1)
  plt.imshow(x_train[i],cmap='gray')
plt.show()
print(y_train[0:60])

The contents of the dataset look like this. You can see that the image data of 28 * 28 handwritten numbers and the number label are included. dataset.png

in conclusion

I used ** TensorFlow 2.1.0 on Windows 10 Python 3.7 ** and trained a neural network model based on mnist's handwritten digit dataset. Next, I would like to predict the handwritten numbers that I prepared.

Source

"Installing TensorFlow with pip" https://www.tensorflow.org/install/pip?hl=ja#windows

Recommended Posts

Use Tensorflow 2.1.0 with Anaconda on Windows 10!
Use pyvenv on Windows
Use Python 3.8 with Anaconda
Anaconda on Windows Terminal
Install Anaconda on Windows 10
Build TensorFlow on Windows
Use Ansible on Windows
Use QuTiP on Windows
Use pip on Windows
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
Use TensorFlow with Intellij IDEA
Install cvxpy on windows, Anaconda
Use Windows 10 fonts with WSL
[Tensorflow] Tensorflow environment construction on Windows 10
Notes on installing Anaconda 3 on Windows
Use Python on Windows (PyCharm)
Use Linux on Windows 10 (WSL2)
Blogging with Pelican on Windows
Preparing to use Tensorflow (Anaconda) with Visual Studio Code
Try running tensorflow on Docker + anaconda
tensor flow with anaconda on mac
Anaconda python environment construction on Windows 10
How to use Dataiku on Windows
Precautions when installing tensorflow with anaconda
Run Tensorflow natively supported on windows
Run SwitchBot on Windows 10 with Bleak
Use Windows 10 speech synthesis with Python
Getting started with USD on Windows
Install PyStan on Windows without Anaconda
Getting started with Python 3.8 on Windows
Environment construction of TensorFlow + JupyterNotebook + Matplotlib on Windows version Anaconda (August 2017 version)
Run servo with Python on ESP32 (Windows)
Try using Bash on Windows 10 2 (TensorFlow installation)
Use Tabpy with Cloud Run (on GKE)
How to use Cmder with PyCharm (Windows)
How to use Google Assistant on Windows 10
Use without installing python 2.x on Windows
Build Python environment with Anaconda on Mac
tensorflow does not enter in windows + anaconda.
Run py.test on Windows Anaconda and MinGW
I built a TensorFlow environment on windows10
I tried object detection with YOLO v3 (TensorFlow 2.0) on a windows CPU!
Use Jupyter Notebook with Visual Studio Code on Windows 10 + Python + Poetry + pyenv-win
Unable to import packages installed in virtual environment with Anaconda on Windows 10
Theano on Anaconda
Zundokokiyoshi with TensorFlow
Breakout with Tensorflow
Try Tensorflow with a GPU instance on AWS
Use dein.vim and ckw-mod with Windows7 32bit PowerShell
[0] TensorFlow-GPU environment construction built with Anaconda on Ubuntu
Organize files on Windows with Linux commands-using WSL-
Boot CentOS 8 from Windows 10 with Wake On LAN
Use Python in Anaconda environment with VS Code
Notes for using TensorFlow on Bash on Ubuntu on Windows
Until you use PhantomJS with Python on Heroku
[Python] How to install OpenCV on Anaconda [Windows]
Installing TensorFlow on Windows Easy for Python beginners
Use Python / Django with Windows Azure Cloud Service!
[Windows] Memo to use Keras on GPU [Tensorflow-GPU]
How to install / verify graphviz on anaconda / windows10
Use anaconda virtual environment with Zsh (problem fix)