All Projects → waybarrios → TensorFlow_CNN

waybarrios / TensorFlow_CNN

Licence: other
Example CNN on CIFAR-10 classification

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to TensorFlow CNN

Github-Stars-Predictor
It's a github repo star predictor that tries to predict the stars of any github repository having greater than 100 stars.
Stars: ✭ 34 (+142.86%)
Mutual labels:  prediction
infer
🔮 Use TensorFlow models in Go to evaluate Images (and more soon!)
Stars: ✭ 65 (+364.29%)
Mutual labels:  prediction
vlainic.github.io
My GitHub blog: things you might be interested, and probably not...
Stars: ✭ 26 (+85.71%)
Mutual labels:  prediction
GDLibrary
Matlab library for gradient descent algorithms: Version 1.0.1
Stars: ✭ 50 (+257.14%)
Mutual labels:  softmax-regression
reinforcement learning course materials
Lecture notes, tutorial tasks including solutions as well as online videos for the reinforcement learning course hosted by Paderborn University
Stars: ✭ 765 (+5364.29%)
Mutual labels:  prediction
stock-forecast
Simple stock & cryptocurrency price forecasting console application, using PHP Machine Learning library (https://github.com/php-ai/php-ml)
Stars: ✭ 76 (+442.86%)
Mutual labels:  prediction
Sales-Prediction
In depth analysis and forecasting of product sales based on the items, stores, transaction and other dependent variables like holidays and oil prices.
Stars: ✭ 56 (+300%)
Mutual labels:  prediction
prediction-builder
A library for machine learning that builds predictions using a linear regression.
Stars: ✭ 107 (+664.29%)
Mutual labels:  prediction
MSDS696-Masters-Final-Project
Earthquake Prediction Challenge with LightGBM and XGBoost
Stars: ✭ 58 (+314.29%)
Mutual labels:  prediction
Topics-In-Modern-Statistical-Learning
Materials for STAT 991: Topics In Modern Statistical Learning (UPenn, 2022 Spring) - uncertainty quantification, conformal prediction, calibration, etc
Stars: ✭ 74 (+428.57%)
Mutual labels:  prediction
behaiv-java
User Behavior Prediction for everyone
Stars: ✭ 12 (-14.29%)
Mutual labels:  prediction
Loan-Prediction-Dataset
No description or website provided.
Stars: ✭ 21 (+50%)
Mutual labels:  prediction
btcpredict
📈 Bitcoin bull run peak prediction project (price and date)
Stars: ✭ 36 (+157.14%)
Mutual labels:  prediction
verif
Software for verifying weather forecasts
Stars: ✭ 70 (+400%)
Mutual labels:  prediction
PlasFlow
Software for prediction of plasmid sequences in metagenomic assemblies
Stars: ✭ 74 (+428.57%)
Mutual labels:  prediction
PyDREAM
Python Implementation of Decay Replay Mining (DREAM)
Stars: ✭ 22 (+57.14%)
Mutual labels:  prediction
R Unet
Video prediction using lstm and unet
Stars: ✭ 25 (+78.57%)
Mutual labels:  prediction
engine
Benefit from new browsers' technologies to speed up your site
Stars: ✭ 39 (+178.57%)
Mutual labels:  prediction
Deep-learning-model-deploy-with-django
Serving a keras model (neural networks) in a website with the python Django-REST framework.
Stars: ✭ 76 (+442.86%)
Mutual labels:  prediction
Diebold-Mariano-Test
This Python function dm_test implements the Diebold-Mariano Test (1995) to statistically test forecast accuracy equivalence for 2 sets of predictions with modification suggested by Harvey et. al (1997).
Stars: ✭ 70 (+400%)
Mutual labels:  prediction

#CNN TensorFLow CIFAR-10 is a common benchmark in machine learning for image recognition. Link: http://www.cs.toronto.edu/~kriz/cifar.html


Overview

Code in this directory demonstrates how to use TensorFlow to train and evaluate a convolutional neural network (CNN) on both CPU and GPU. We also demonstrate how to train a CNN over multiple GPUs.


Installation Ubuntu/Linux

$ pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl

Model Architecture

The model in this CIFAR-10 tutorial is a multi-layer architecture consisting of alternating convolutions and nonlinearities. These layers are followed by fully connected layers leading into a softmax classifier. The model follows the architecture described by Alex Krizhevsky, with a few differences in the top few layers.

This model achieves a peak performance of about 86% accuracy within a few hours of training time on a GPU. Please see below and the code for details. It consists of 1,068,298 learnable parameters and requires about 19.5M multiply-add operations to compute inference on a single image.


Code Organization

File Purpose
cifar10_input.py Reads the native CIFAR-10 binary file format.
cifar10.py Builds the CIFAR-10 model.
cifar10_train.py Trains a CIFAR-10 model on a CPU or GPU.
cifar10_multi_gpu_train.py Trains a CIFAR-10 model on multiple GPUs.
cifar10_eval.py Evaluates the predictive performance of CIFAR10

CIFAR-10 Model

The CIFAR-10 network is largely contained in cifar10.py. The complete training graph contains roughly 765 operations. We find that we can make the code most reusable by constructing the graph with the following modules:

1. Model inputs: inputs() and distorted_inputs() add operations that read and preprocess CIFAR images for evaluation and training, respectively.

2. Model prediction: inference() adds operations that perform inference, i.e. classification, on supplied images.

3. Model training: loss() and train() add operations that compute the loss, gradients, variable updates and visualization summaries.

Model Inputs

The input part of the model is built by the functions inputs() and distorted_inputs() which read images from the CIFAR-10 binary data files. These files contain fixed byte length records, so we use tf.FixedLengthRecordReader.

The images are processed as follows:

* They are cropped to 24 x 24 pixels, centrally for evaluation or randomly for training.
* They are approximately whitened to make the model insensitive to dynamic range.

For training, we additionally apply a series of random distortions to artificially increase the data set size:

* Randomly flip the image from left to right.
* Randomly distort the image brightness.
* Randomly distort the image contrast.

Model Predicition

The prediction part of the model is constructed by the inference() function which adds operations to compute the logits of the predictions. That part of the model is organized as follows:

Layer Name Description
conv1 convolution and rectified linear activation.
pool1 max pooling.
conv2 convolution and rectified linear activation.
norm2 local response normalization.
pool2 max pooling.
local3 fully connected layer with rectified linear activation.
local4 fully connected layer with rectified linear activation.
softmax_linear linear transformation to produce logits.

Model Training

The usual method for training a network to perform N-way classification is multinomial logistic regression, aka. softmax regression. Softmax regression applies a softmax nonlinearity to the output of the network and calculates the cross-entropy between the normalized predictions and a 1-hot encoding of the label. For regularization, we also apply the usual weight decay losses to all learned variables. The objective function for the model is the sum of the cross entropy loss and all these weight decay terms, as returned by the loss() function.


Launching and Training the Model

We have built the model, let's now launch it and run the training operation with the script cifar10_train.py.

python cifar10_train.py

You should see the output:

Filling queue with 20000 CIFAR images before starting to train. This will take a few minutes.
2015-11-10 10:45:45.927302: step 0, loss = 4.68 (2.0 examples/sec; 64.221 sec/batch)
2015-11-10 10:45:49.133065: step 10, loss = 4.66 (533.8 examples/sec; 0.240 sec/batch)
2015-11-10 10:45:51.397710: step 20, loss = 4.64 (597.4 examples/sec; 0.214 sec/batch)
2015-11-10 10:45:54.446850: step 30, loss = 4.62 (391.0 examples/sec; 0.327 sec/batch)
2015-11-10 10:45:57.152676: step 40, loss = 4.61 (430.2 examples/sec; 0.298 sec/batch)
2015-11-10 10:46:00.437717: step 50, loss = 4.59 (406.4 examples/sec; 0.315 sec/batch)

The script reports the total loss every 10 steps as well the speed at which the last batch of data was processed. A few comments:

* The first batch of data can be inordinately slow (e.g. several minutes) as the preprocessing threads fill up the shuffling queue with 20,000 processed CIFAR images.

* The reported loss is the average loss of the most recent batch. Remember that this loss is the sum of the cross entropy and all weight decay terms.

* Keep an eye on the processing speed of a batch. The numbers shown above were obtained on a Tesla K40c. If you are running on a CPU, expect slower performance.
cifar10_train.py periodically saves all model parameters in checkpoint files but it does not evaluate the model. The checkpoint file will be used by cifar10_eval.py to measure the predictive performance (see Evaluating a Model below).

If you followed the previous steps, then you have now started training a CIFAR-10 model. Congratulations!

The terminal text returned from cifar10_train.py provides minimal insight into how the model is training.


Evaluating a Model

Let us now evaluate how well the trained model performs on a hold-out data set. the model is evaluated by the script cifar10_eval.py . It constructs the model with the inference() function and uses all 10,000 images in the evaluation set of CIFAR-10. It calculates the precision at 1: how often the top prediction matches the true label of the image.

To monitor how the model improves during training, the evaluation script runs periodically on the latest checkpoint files created by the cifar10_train.py.

python cifar10_eval.py

You should see the output:

2015-11-11 11:15:44.391206: precision @ 1 = 0.860

Launching and Training the Model on Multiple GPU cards

If you have several GPU cards installed on your machine you can use them to train the model faster with the cifar10_multi_gpu_train.py script. It is a variation of the training script that parallelizes the model across multiple GPU cards.

python cifar10_multi_gpu_train.py --num_gpus=2

Contributions

http://tensorflow.org/tutorials

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].