tensorflow编程实战

TensorFlow编程实战


一,tf.constant() and so on

  • tf.constant(value,share,dtpye,name,verify_shape)
  • value:初始化值
  • shape:n1n2n…nk(0<k<)
  • verify_shape ?
  • tf.zeros()
  • tf.ones()
  • tf.ones_like()
  • tf.fill()
  • tf.lin_space(start,end,num,name)
  • tf.range(start,limit,delta,dtype,name)

二,tensorflow random generate constant

  • tf.random_normal()
  • tf.truncated_normal()
  • tf.random_uniform()
  • tf.random_shuffle()
  • tf.multinomil()
  • tf.random_gamma()

三,Operations

  • elements-wise mathematical operations,like Add,Equal
  • array operations,like concat,shuffle
  • matrix operations,like MatrixMul,
  • stateful operations,like Variables
  • netural network building block,like Softmax,Sigmoid,MaxPool
  • checking Point operations,like save Restore
  • Queue and synchronization operations,like Enqueue,MutexAcquire
  • control flow operations,like Merge,Switch,Enter,NextIteration,Leave

四,Tensor DataType

  • tf.(b)float_(16/32/64)
  • tf.complex(64/128)
  • tf.uint(8/16)
  • tf.int(8/16/32/64)
  • bool
  • string
  • tf.qint(8/16/32)
  • tf.quint(8/16)
  • tf.resource

五,Tensor Varible

  • tf.variable()
  • tf.get_variable(name,shape,initicalizer)
  • initial all the variable at once
with tf.Session() as sess:
		sess.run(tf.global_variables_initializer())

or
with tf.Session() as sess:
		sess.run(tf.variables_initializer(name1,name2,...))

六,Traning phrase1

  1. reading data
  2. create placeholders for input and labels
  3. create weight and bias
  4. Y_predicted=wX+b
  5. specify loss function:loss=tf.Square(Y-Y_predicted,name)
  6. create optimizer:
opt=tf.train.GrandientDecentOptimizer(learning_rate=0.01)
optimizer=opt.minimize(loss)

or

optimizer=tf.train.GradientDecentOptimizer(learnint_rate=0.001).minimize(loss)
sess.run([optimizer,loss],feedDict={X:x,Y:y})
  1. optimizer list,like AdagradOptimizer,MomemtuOptimizer…

七,Traning Phrase2

  1. initialize variables
  2. run optimizer:usually use feed_Dict()
  3. write log files as FileWriter
  4. see it on TensorBoard

tips

  1. tensor objects are not iterable

猜你喜欢

转载自blog.csdn.net/qq_34299554/article/details/84193756