Windows10 installing Anaconda+tensorflow (CPU) +keras+pycharm

Source: Internet
Author: User
Tags keras

"Install Anaconda3"

Download: https://www.continuum.io/downloads, prompts during installation failed to create Anacoda menue refer to Http://www.cnblogs.com/chuckle/p/7429624.html when the error occurs.

"Install TensorFlow"(Requires network link, offline installation reference: HTTP://WWW.JIANSHU.COM/P/C245D46D43F0)

Open Anaconda Prompt, enter:

Pip Install TensorFlow

"Install Keras"(need network link, reference: http://www.jianshu.com/p/c245d46d43f0)

Open Anaconda Prompt, enter:

Pip Install Keras

  This will install Theano, regardless of it.

"Test Keras for installation Success"(reference: http://www.jianshu.com/p/c245d46d43f0)

Open Anaconda Prompt, and on the command line, enter:

Python

Re-enter:

Import TensorFlow as Tfsess = tf. Session () A = Tf.constant (ten) B = tf.constant (+) print (Sess.run (A + b))

The output was successfully installed for 32,tensorflow.

Re-enter:

Import Keras

Error-Free, Keras installation is successful.

"Install Pycharm and activate"

Slightly.

To modify the Python interpreter path, select Python.exe in the Anaconda installation directory:

  

"Demo"(Requires network link, download data set)

Create a new project in Pycharm, create a new Python file, copy the following code (formerly @ involves wind,http://www.cnblogs.com/surfzjy/p/6419201.html)and run.

From __future__ import print_function# imported NumPy library, NumPy is a common scientific computing library, optimizing the operation of the matrix import NumPy as Npnp.random.seed (1337) # Import Mnist database, Mnist is a commonly used handwritten digital library from keras.datasets import mnist# Import order model from keras.models import sequential# imported full-connection layer dense, Activation layer Activation and dropout layer from keras.layers.core import dense, dropout, activation# importing optimizer rmspropfrom keras.optimizers Import rmsprop# Importing NumPy tool, mainly using to_categorical to convert class vectors from keras.utils import np_utils# setting Batch size batch_size = 128# Set the number of categories nb_classes = 10# Set the number of iterations Nb_epoch = Keras DataSet in 20# Mnist has been divided into 60,000 training sets, 10,000 test sets in the form of a call in the following format (X_train, Y_ Train), (x_test, y_test) = Mnist.load_data () # X_train was originally a three-dimensional vector of 60000*28*28, converting it to 60000*784 's two-dimensional vector x_train = x_ Train.reshape (60000, 784) # X_test was originally a three-dimensional vector of 10000*28*28, converting it to 10000*784 's two-dimensional vector x_test = X_test.reshape (10000, 784) # will X_ Train, x_test data format to float32 storage X_train = X_train.astype (' float32 ') x_test = X_test.astype (' float32 ') # normalized x_train/= 255x_ Test/= 255# Print out the training set and test set information print (X_train.shape[0], ' train samples ') print (x_test.shape[0],' Test samples ') ' Maps a class vector (an integer vector from 0 to nb_classes) to a two value class matrix, which is equivalent to re-encoding the vector with One-hot ' ' Y_train = np_utils.to_categorical (y_ Train, nb_classes) Y_test = np_utils.to_categorical (Y_test, nb_classes) # establishing a sequential model = sequential () " The model needs to know the shape of the input data, so the first layer of sequential needs to accept a parameter about the shape of the input data, and the subsequent layers can automatically derive the shape of the intermediate data, so there is no need to specify this parameter for each layer ' # The input layer has 784 neurons # The first hidden layer has 512 neurons, the activation function is relu,dropout ratio of 0.2model.add (Dense (input_shape= (784))) Model.add (Activation ( ' Relu ') Model.add (Dropout (0.2)) # The second hidden layer has 512 neurons, and the activation function is relu,dropout proportional to 0.2model.add (dense) model.add (Activation (' Relu ')) Model.add (Dropout (0.2)) # The output layer has 10 neurons, the activation function is Softmax, and the classification result Model.add (dense ()) Model.add (Activation (' Softmax ')) # Overall information for the output model # Total number of parameters is 784*512+512 + 512*512+512 + 512*10+10 = 669706model.summary () " The learning process of the configuration model compile receives three parameters: 1. Optimizer Optimizer: Parameters can be specified as predefined optimizer names, such as Rmsprop, Adagrad, or a optimizer class object, so Rmsprop () 2. Loss function Loss: The parameter is the objective function that the model tries to minimize, can be a predefined loss function, such as categorical_crossentropy, MSE, or a loss function 3. List of indicators: For classification issues, the list is generally set to metrics=[' Accuracy ' model.compile (loss= ' Categorical_crossenTropy ', Optimizer=rmsprop (), metrics=[' accuracy ') ' Training model Batch_size: Specifies the number of samples per batch included in the gradient drop Nb_epoch : The number of rounds of training, NB is ofverbose: The log shows that 0 is not output log information for the standard output stream, 1 is the output progress bar record, and 2 is the Epoch output row record Validation_data: Specifies the validation set the Fit function returns a History object                    , its history.history attribute records the value of the loss function and other indicators as the epoch changes, and if there is a validation set, it also contains the validation set of these indicator changes "' History = Model.fit (X_train, Y_train,                    Batch_size = batch_size, Nb_epoch = nb_epoch, verbose = 1, Validation_data = (X_test, y_test) # Calculates the error of the model on some input data by batch score = Model.evaluate (X_test, Y_test, verbose=0) # Outputs the trained model is measured Test Set performance print (' Test score: ', score[0]) print (' Test accuracy: ', score[1])

  

Windows10 installing Anaconda+tensorflow (CPU) +keras+pycharm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.