텐텐텐텐텐 텐텐 텐텐텐텐 (R0.12) Moon Yong Joon
PowerPoint
(r0.12)Moon Yong Joon
1. 2. Data type3. Tensorflow 4. Tensor graph5. tensorboard
1.
anaconda windows7 anaconda pip tensorflow
Hello tensorflow python 3 (str) unicode str encoding bytes uncode type
Tensorflow /
Tensorflow
edges nodes graph
Tensorflow : (session)
tensorflow tf x 35 .y x + 5 global_variables_initializer 4 y
Tensorflow graph (session)
Tensorboard tensorboard
tensorboard graph graph
Tensorflow
Tensorflow Session fetch feed 2 FetcheFeeds fetch () Placeholder OPOPVAR
xfetchGraphfeed
With : Session with close()
fetch : Tensor Session tensoroperationTensor operation
fetch : Session.run Tensor
Tensorflow feed Session feed feed_dict
feed : Session.run Tensor
Assert
python assert assert
assert assert operation
assert assert operation
Numpy
numpy
(reduction_indices=1)
session
Tensorboard
tensorflow session summary tensorboard
tensorboard (localhost:6006)
Regression
Numpy :
n (y_data)(y)(^2),n.
Numpy : Operation
Tensorflow :
Tensorflow :
cost function
n (y_data)(y)(^2),n(Least-squares) .
Optimizer
class tf.train.Optimizertf.train.Optimizer class the API to add Ops to train a model, subclasses GradientDescentOptimizer, AdagradOptimizer, or MomentumOptimizer. tf.train.Optimizer GradientDescentOptimizer AdagradOptimizer MomentumOptimizer
class tf.train.GradientOptimizer (Gradient descent) train = optimizer.minimize(loss) (Gradient descent) (loss)
Gradient descent f(x ) , x0 . x i , x i+1 .
gamma i . f gamma i . , . x0 . .
tf.train.Optimizer.minimize compute_gradients () apply_gradients () , compute_gradients () apply_gradients ()
minimize
2. Data Type
Tensorclass
Tensorflow Session Tensor Class TensorSparseTensorTensorArray
Tensor class
Tensor 0 n 0 : 1 : 2 : 3 : 2 N : n-1
(rank)
dtype tensor data typePython typeDescriptionDT_FLOATtf.float3232 bits floating point.DT_DOUBLEtf.float6464 bits floating point.DT_INT8tf.int88 bits signed integer.DT_INT16tf.int1616 bits signed integer.DT_INT32tf.int3232 bits signed integer.DT_INT64tf.int6464 bits signed integer.DT_UINT8tf.uint88 bits unsigned integer.DT_STRINGtf.stringVariable length byte arrays. Each element of a Tensor is a byte array.DT_BOOLtf.boolBoolean.DT_COMPLEX64tf.complex64Complex number made of two 32 bits floating points: real and imaginary parts.DT_COMPLEX128tf.complex128Complex number made of two 64 bits floating points: real and imaginary parts.DT_QINT8tf.qint88 bits signed integer used in quantized Ops.DT_QINT32tf.qint3232 bits signed integer used in quantized Ops.DT_QUINT8tf.quint88 bits unsigned integer used in quantized Ops.
Variable:Tensor
tf.Variable() , , # Create a variable. y = tf.Variable(, name=)
tf.Variable() Tensor
: Tensor tf.Variable() y Variable
Numpy vs. Tensor numpy tensorflow array , ,
rank tensor rank
shape tensor shape
size tensor shape
: eval with Session
Variable : initialized_valueinitialized_value
Variable : assign assing, assign_add, assign_sub
global_variables global
variable_scopeVariable_scope
reuse_variables Variable_scope
get_variable Variable_scope
get_variable Variable_scope
reset_default_graph scope reset
:tensorboard
tensorboard
tensorboard
Placeholder:Tensor
placeholder placeholder tf.placeholder(dtype, shape=None, name=None)
Args: dtype: shape: tensor name: A name for the operation
Returns: ATensorthat may be used as a handle for feeding a value, but not evaluated directly.
placeholder Tensor placeholder Tensor
placeholder Tensor placeholder (feed)
Values : Tensor
constant tf.constant() a Tensor
zeros/zeros_like numpy tensorflow array
ones/ones_like 1 tensor
fill tensor value
Sequences : Tensor
linspace tensor .
range tensor .
Random : Tensor
random_normal 2 3 normal
random_normal : seed 2 3 normal
random_uniform 2 3 uniform
shuffle 3 2 shuffle
sparseTensorclass
SparseTensor
SparseTensor class. Tensor tensor session
TensorArrayclass
TensorArray
TensorArray , , Tensor . while_loop map_fn
TensorArray : write TensorArray write
TensorArray : read TensorArray read Tensor session
TensorArray : gather TensorArray gather Tensor session
pack/unpack
TensorArray TensorArray gather Tensor session
TensorArray : unpack/pack Tensor TensorArray
3. Tensorflow
Operation
Operation Operation
Operation Operation
Operation : graph Operation
Input & reader
placeholder feed_dict
placeholder_with_default feed_dict
File read
python open file
read_file Read_file
CSV: queue
csv file build csv_file
csv file csv decode
resize
transpose
: slice slice
Tensor
Tensor
: scalar scalar
, abs, neg, sign
neg negative
: / /
: cross a b . 3- 3 , , 3-
gradiants 2*x**2
complex:
Reduction/Scan
reduce_sum (reduction_indices=1)
reduce_mean/min/max
reduce_any/all True False
reduce_prod/logsumexp
accumulate_n shape
cumsum/cumprod
Segment
segment_sum/prod segment . Segment rank
segment_min/max segment min, max . Segment rank
transpose
diag
Matmul :
Inverse :
matrix_determinant :
trace
eye :
Tensorcontrol flow
tuple
identity
tuple tuple(list)
cond operation
case operation
while_loop 1 loop
while_loop 2 x loop
operation
Logical Operators operations
Comparison Operators operations
select tensor
where : x y None condition
where : x y
argmin/argmax /
unique/setdiff1d 2
Tensor
Scan
scan , .
scan :
scan : initializer : 1 initializer fn initializer . fn .
scan : initializer: 2 initializer fn initializer . fn .
Map/Fold
map_fn map . dtype
foldl / foldr , , fn
Tensor Transformations
Shaping
reshape numpy tensorflow array reshape
squeeze tensor size 1
expand_dims tensor axis
meshgrid ( 'xy') ( 'ij') , 'xy'()
Slicing and Joining
slice tensor slice tensor tf.slice(input_, begin, size, name=None)
reverse , dim bool
split tensor split axis
tile tensor tile
pad : constant tensor pad
pad : tensor pad
concat tensor tensor concat
pack/unpack numpy tensor
String
String/reduce join string_join/reduce_join
substr Tensor
encode/decode: base64 Tensor base64 /
string_split string_split SparseTensor values Tensor
histogram
histogram
histogram 3 2 shuffle
histogram_fixed_width histogram
4. Tensor graph
Building the graph( )
Tensorflow Graph session graph Building the graphLaunching the graph in a session
Graph
Tensorflow: graph graph nodes edges
Building the graphGraph tensor
tensor
Launching in a sessionSession run Tensor Operation
Product tensor tf.matmul(matrix1, matrix2)
Launching \the graph in a session()
Session
Session Session 2 Session.close() InteractiveSessionSessionInteractive . Tensor.eval(), Operation.run() Non-Interactive . Session.run()
Session
: Session , session
global_variables_initializer 1 operation Session.run .
global_variables_initializer 2 operation Session
Interactive Session
, InteraciveSession .initializer.run()
InteractiveSessionOperation.run(), Tensor.eval()
Interactive Usage Interactive tendor add
Interactive Usagesess = tf.InteractiveSession() ide
Interactive Usage 1Interactive tensor add
Session.run
Session Operation , Tensor operationtensorOperation.run() Tensor.eval()Session.run( _ )Session.run() operation tensor
Session.run : tensor
Session.run : operation runOperation: (attribute) .
Session.run fetches: graph grape , grape .feed_dict: graph options: A [RunOptions] protocol bufferrun_metadata: A [RunMetadata] protocol buffertf.Session.run(fetches, feed_dict=None, options=None, run_metadata=None)
Session : Session Session run with
sess = tf.InteractiveSession() tensor eval()
Session.run()Tensor.eval()
Session Session numpy.int32 Tensor
tensor
fetch
Session run () .
.
Feed
Placeholder sess feed_dict
rand_array feed_dict placeholder
Session feed Placeholder sess feed_dict
Session.run Session numpy.int32 Tensor
tensor
train.Savor
train.Savor
:
train.Savor
: train.Savor
Tensorflowgraph class
Moon Yong Joon
tf.Graph
graphGraph operation Tensor
OperationTensorrepresent units of computationrepresent the units of data that flow between operations.
graph as_default graph context Graph
tensorflow graph graph node
graph node ()Tf.get_default_graph() get_operations() op node
graph node ()
graph node () graph
graph node ()Op inputs
Tf.constant() tensor session
5. tensorboard
tensorboard
Tensorboard
Tensorboard localhost:6006
Summary
tf.summary.FileWriter summary
Graph localhost:6006
Graph : localhost:6006 GRAPHS
Graph session summary tensorboard
Graph : tensorboard (localhost:6006)
1 SummaryWriter summary.FileWriter , sess.graph_def sess.graph
2 ()
tensorboard
tensorboard : input input node tensorflow
Tensorflow : graph op namegraph = tf.get_default_graph() operation node
tensorboard : weight weight node
tensorboard : output output node tensorflow
Tensorboard
Tensorboard !tensorboard --logdir = C:\Users\06411\Documents\logs