Details about TensorFlow installation and simple examples on windows, and details about tensorflow
This article describes how to install TensorFlow on windows and provides simple examples. The details are as follows:
Installation instructions
Platform: It can be installed on Ubuntu, Mac OS, and Windows.
Version: Provides the gpu version and cpu version.
Installation Method: pip and Anaconda
Tips:
- Currently, Python 3.5.x is supported on Windows.
- For the gpu version, cuda8 and cudnn5.1 are required.
Installation progress
Progress:
Anaconda 4.3 (corresponding to python3.6) is being installed and deleted.
Progress:
Anaconda 4.3 (corresponding to python3.6) get
Python3.5.2get in Anaconda
Tensorflow1.0.0get
Train of Thought
It is daunting to have some terms I have never seen before when I look at other people's tutorials.
Therefore, it starts with glossary.
Then we will introduce the installation and simple examples of TensorFlow.
As your own notes,
I also hope that I can see this tutorial as easy as possible!
CUDA
CUDA (Compute uniied Device Architecture) is a computing platform launched by NVIDIA, a graphics card manufacturer. CUDA™It is a general parallel computing architecture launched by NVIDIA, which enables GPU to solve complex computing problems. It includes the CUDA instruction set architecture (ISA) and the parallel computing engine inside the GPU. Developers can now use the C language for CUDA™C language is the most widely used high-level programming language. The compiled program can support CUDA™It runs on Ultra-High Performance processors. CUDA3.0 has started to support C ++ and FORTRAN.
The computing industry is evolving from "central processing" with only the CPU to "collaborative processing" with the CPU and GPU. NVIDIA™(NVIDIA™The CUDA (Unified Computing Device Architecture) programming model was invented to make full use of the advantages of CPU and GPU in applications. Now, this architecture has been applied to GeForce™(View™), ION™(Yiyang™), Quadro, and Tesla GPU (graphics processor.
From Baidu encyclopedia.
(So I cannot use the card)
Anaconda
Anaconda is a leading open data science platform supported by Python. The open-source version of Anaconda is a high-performance distribution version of Python and R, including more than 100 of the most popular Python, R, and Scala software packages for data science.
From Anaconda official Download Page
For more information, see the official Anaconda tutorial, which is easy to understand!
Anaconda preliminary study
0. Download the Anaconda installation package: Anaconda official
I downloaded Anaconda4.3.0For Windows 64bit (built-in python3.6)
After the download is complete, install it and continue to the next step.
1. Check whether Anaconda is successfully installed:conda --version
(Hey, the first step is successful. Be happy)
2. Check which environments are currently installed:conda info --envs
(Only one! Not afraid. Continue !)
3. Check which versions of python can be installed:conda search --full-name python
(Yes. Which one do you want? Of course, it's python3.5)
4. Install python of different versions:conda create --name tensorflow python=3.5
(Assume that a version 3.5.x is automatically selected after python = 3.5 is input)
(Python3.5.3? The lab server is 3.5.2. Make sure you have the same server !)
(Okay, GO !)
(Hey! Well! A step closer to success !)
5. Follow the prompts to activate it:activate tensorflow
(Hey, it has a small hat ~ Represents my current environment)
6. Make sure that the tensorflow environment has been successfully added:conda info --envs
(Bravo !)
7. Check the python version in the new environment:python --version
(^ Happy ~)
8. Exit the current environment:deactivate
(The little hat fell)
9. Switch the environment:activate tensorflow
Activate and switch to any environment ~
Since tensorflow is installed in this article, avtivate tensorflow is required!
Goblin! I'm coming!
PS: For more information, see the official Anaconda tutorial. It is easy to understand and get started! Do not search for online tutorials without official tutorials!
TensorFlow Installation
This document describes how to install tensorflow on a Native windows system,
Anocanda installation method,
The installed version is the cpu (well, as AMD's video card, it hides the surface and cries)
Anaconda 4.3.0.1 (with python3.6)
Configured with python3.5.2 in Anaconda
The following is the main character of today! (Coming soon)
1. Follow the instructions on the official website:
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.0.0-cp35-cp35m-win_x86_64.whl
(Okay. First, make an error, and then try again! I don't know what to do )/~~)
2. Another attempt:pip install tensorflow
(This is the case! I am an AMD card. The corresponding information is different !)
3. Confirm that tensorflow is successfully installed:
Error attempt: directly type python in cmd, and then typeimport tensorflow as tf
(The default value is python3.6, ah, ah, from anaconda to the installed python3.5 !~)
Correct attempt: Enter Anaconda Prompt-python and enter the tensorflow installation environment (Do you remember when we installed python3.5.2 ?~), Type python, and then typeimport tensorflow as tf
Here you can find Anaconda Prompt-python:
Open Anaconda Navigator (Start Menu-> Anaconda 3-> Anaconda Navigator), create a spyder, and click "install" under spyder. After installation, it becomes "Launch, click it to go in.
Say Hello to tensorflow in spyder!
Output:
(Hey, hey, haha, I feel like I have succeeded !!! What about you ?~~)
Please refer to the official tensorflow documentation. The Chinese community does not seem to update windows installation.
TensorFlow routine
We have installed a new thing. Let's use it first!
Concept or something. Run the first Applet and check again!
Find a sense of accomplishment to continue!
Sample Source: MINIST For ML Beginners
MINST Dataset:
- 55000 training set, 10000 Test Set, 5000 verification set
- Each image is 28 pixels * 28 pixels
Code:
# Obtain the dataset from tensorflow. examples. tutorials. mnist import input_datamnist = input_data.read_data_sets ("MNIST_data/", one_hot = True) import tensorflow as tf # input image data placeholder x = tf. placeholder (tf. float32, [None, 784]) # weight and deviation W = tf. variable (tf. zeros ([784, 10]) B = tf. variable (tf. zeros ([10]) # Use the softmax model y = tf. nn. softmax (tf. matmul (x, W) + B) # The placeholder y _ = tf for the cost function. placeholder (tf. float32, [None, 10]) # Cross Entropy Evaluation cost cross_entropy = tf. performance_mean (-tf. reduce_sum (y _ * tf. log (y), reduction_indices = [1]) # Use the gradient descent algorithm to optimize the learning speed: 0.5train _ step = tf. train. gradientDescentOptimizer (0.5 ). minimize (cross_entropy) # Sessionsess = tf. interactiveSession () # initialize the variable tf. global_variables_initializer (). run () # Train the model for 1000 times in range (1000): batch_xs, batch_ys = mnist. train. next_batch (100) sess. run (train_step, feed_dict = {x: batch_xs, y _: batch_ys}) # Calculate the correct rate of correct_prediction = tf. equal (tf. argmax (y, 1), tf. argmax (y _, 1) accuracy = tf. performance_mean (tf. cast (correct_prediction, tf. float32) print (sess. run (accuracy, feed_dict = {x: mnist. test. images, y _: mnist. test. labels }))
Running result: the output shows the accuracy of the model.
Conclusion
I spent most of my time deploying the environment yesterday, but not only did I get nothing but I was overwhelmed. Today, I am fighting again and simply write and write, as if chatting with people next to me. Well, it's easy to make things when you're in a good mood. Time is precious, but I still hope that your learning curve will not be too steep. I hope you can happily enter the new field.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.