Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tf2.0 #326

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Tf2.0 #326

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 50 additions & 0 deletions tf2.0/notebooks/0_Prerequisite/ml_introduction.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Machine Learning\n",
"\n",
"Prior to start browsing the examples, it may be useful that you get familiar with machine learning, as TensorFlow is mostly used for machine learning tasks (especially Neural Networks). You can find below a list of useful links, that can give you the basic knowledge required for this TensorFlow Tutorial.\n",
"\n",
"## Machine Learning\n",
"\n",
"- [An Introduction to Machine Learning Theory and Its Applications: A Visual Tutorial with Examples](https://www.toptal.com/machine-learning/machine-learning-theory-an-introductory-primer)\n",
"- [A Gentle Guide to Machine Learning](https://blog.monkeylearn.com/a-gentle-guide-to-machine-learning/)\n",
"- [A Visual Introduction to Machine Learning](http://www.r2d3.us/visual-intro-to-machine-learning-part-1/)\n",
"- [Introduction to Machine Learning](http://alex.smola.org/drafts/thebook.pdf)\n",
"\n",
"## Deep Learning & Neural Networks\n",
"\n",
"- [An Introduction to Neural Networks](http://www.cs.stir.ac.uk/~lss/NNIntro/InvSlides.html)\n",
"- [An Introduction to Image Recognition with Deep Learning](https://medium.com/@ageitgey/machine-learning-is-fun-part-3-deep-learning-and-convolutional-neural-networks-f40359318721)\n",
"- [Neural Networks and Deep Learning](http://neuralnetworksanddeeplearning.com/index.html)\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "IPython (Python 2.7)",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
96 changes: 96 additions & 0 deletions tf2.0/notebooks/0_Prerequisite/mnist_dataset_intro.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"# MNIST Dataset Introduction\n",
"\n",
"Most examples are using MNIST dataset of handwritten digits. The dataset contains 60,000 examples for training and 10,000 examples for testing. The digits have been size-normalized and centered in a fixed-size image (28x28 pixels) with values from 0 to 1. For simplicity, each image has been flatten and converted to a 1-D numpy array of 784 features (28*28).\n",
"\n",
"## Overview\n",
"\n",
"![MNIST Digits](http://neuralnetworksanddeeplearning.com/images/mnist_100_digits.png)\n",
"\n",
"## Usage\n",
"In our examples, we are using TensorFlow [input_data.py](https://github.com/tensorflow/tensorflow/blob/r0.7/tensorflow/examples/tutorials/mnist/input_data.py) script to load that dataset.\n",
"It is quite useful for managing our data, and handle:\n",
"\n",
"- Dataset downloading\n",
"\n",
"- Loading the entire dataset into numpy array: \n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Import MNIST\n",
"from tensorflow.examples.tutorials.mnist import input_data\n",
"mnist = input_data.read_data_sets(\"/tmp/data/\", one_hot=True)\n",
"\n",
"# Load data\n",
"X_train = mnist.train.images\n",
"Y_train = mnist.train.labels\n",
"X_test = mnist.test.images\n",
"Y_test = mnist.test.labels"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- A `next_batch` function that can iterate over the whole dataset and return only the desired fraction of the dataset samples (in order to save memory and avoid to load the entire dataset)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Get the next 64 images array and labels\n",
"batch_X, batch_Y = mnist.train.next_batch(64)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Link: http://yann.lecun.com/exdb/mnist/"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
172 changes: 172 additions & 0 deletions tf2.0/notebooks/1_Introduction/basic_operations.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Basic Tensor Operations\n",
"\n",
"Basic tensor operations using TensorFlow v2.\n",
"\n",
"- Author: Aymeric Damien\n",
"- Project: https://github.com/aymericdamien/TensorFlow-Examples/"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from __future__ import print_function\n",
"import tensorflow as tf"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Define tensor constants.\n",
"a = tf.constant(2)\n",
"b = tf.constant(3)\n",
"c = tf.constant(5)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"add = 5\n",
"sub = -1\n",
"mul = 6\n",
"div = 0.6666666666666666\n"
]
}
],
"source": [
"# Various tensor operations.\n",
"# Note: Tensors also support python operators (+, *, ...)\n",
"add = tf.add(a, b)\n",
"sub = tf.subtract(a, b)\n",
"mul = tf.multiply(a, b)\n",
"div = tf.divide(a, b)\n",
"\n",
"# Access tensors value.\n",
"print(\"add =\", add.numpy())\n",
"print(\"sub =\", sub.numpy())\n",
"print(\"mul =\", mul.numpy())\n",
"print(\"div =\", div.numpy())"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"mean = 3\n",
"sum = 10\n"
]
}
],
"source": [
"# Some more operations.\n",
"mean = tf.reduce_mean([a, b, c])\n",
"sum = tf.reduce_sum([a, b, c])\n",
"\n",
"# Access tensors value.\n",
"print(\"mean =\", mean.numpy())\n",
"print(\"sum =\", sum.numpy())"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# Matrix multiplications.\n",
"matrix1 = tf.constant([[1., 2.], [3., 4.]])\n",
"matrix2 = tf.constant([[5., 6.], [7., 8.]])\n",
"\n",
"product = tf.matmul(matrix1, matrix2)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<tf.Tensor: id=31, shape=(2, 2), dtype=float32, numpy=\n",
"array([[19., 22.],\n",
" [43., 50.]], dtype=float32)>"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Display Tensor.\n",
"product"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[19., 22.],\n",
" [43., 50.]], dtype=float32)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Convert Tensor to Numpy.\n",
"product.numpy()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.15"
}
},
"nbformat": 4,
"nbformat_minor": 2
}