TensorFlow API 笔记

Basic

tf.while_loop

def while_loop(cond, body, loop_vars):
	...
	while cond(loop_vars):
    	loop_vars = body(loop_vars)
    ...

loop_vars 参数先传入 cond 判断条件是否成立,如果 cond(loop_vars)True,则把 loop_vars 参数传入 body 执行操作并用 body 操作后的返回值更新 loop_vars 参数,然后再次进入循环,直到不满足条件。

Graph

API

get tf.Operation from Graph

# session is tf.Session
# returns tf.Operation(in tensorflow/python/framework/ops.py)
session.graph.get_operations()

get_tensor_by_name

import tensorflow as tf
with tf.variable_scope("generate"):
    with tf.variable_scope("resnet_stack"):
        bias = tf.Variable(0.0,name="bias")

for tv in tf.trainable_variables():
    print (tv.name)
b = tf.get_default_graph().get_tensor_by_name("generate/resnet_stack/bias:0")

with tf.Session() as sess:
    tf.global_variables_initializer().run()
    print(sess.run(b))

Model

analysis

tf.contrib.tfprof.model_analyzer.print_model_analysis()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值