** TensorFlow 2.1.0 is now available on Python 3.7 on Windows 10! ** **
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 ..
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.
This file itself is included in Visual Studio 2019, so if you have VS 2019 installed, it's okay.
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.
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
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.
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.
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.
"Installing TensorFlow with pip" https://www.tensorflow.org/install/pip?hl=ja#windows
Recommended Posts