Show Menu
Cheatography

Tensorflow Cheat Sheet (DRAFT) by

Tensorflow Cheat sheet

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Import

import tensorflow as tf

placeh­olders

tf.pla­ceh­old­er(­dtype, shape=­None, name=None)

Variables

tf.Var­iab­le(­ini­tia­l_v­alu­e=None, traina­ble­=True, collec­tio­ns=­None, name=None, dtype=­None, ...)

Show Variable

 
with tf.Ses­sion() as sess:
print sess.r­un(x)
 

Phase 1: Assemble graph

Step 1: Read in data
Step 2: Create placeh­olders for inputs and labels
tf.pla­ceh­old­er(­dtype, shape=­None, name=None)
Step 3: Create weight and bias
tf.Var­iab­le(­ini­tia­l_v­alu­e=None, traina­ble­=True, collec­tio­ns=­None, name=None, dtype=­None, ...)
Step 4: Build model to predict Y
Y_pred­icted = X * w + b
Step 5: Specify loss function
tf.squ­are(Y - Y_pred­icted, name="l­oss­")
Step 6: Create optimizer
tf.tra­in.G­ra­die­ntD­esc­ent­Opt­imi­zer­(le­arn­ing­_ra­te=­0.0­01).mi­nim­ize­(loss)

Phase 2: Train model

Initialize variables
Run optimizer op (with data fed into placeh­olders for inputs and labels)