TensorFlow入门

模型保存与加载

ckpt加载与加载

GPU训练

tensorflow创建的Tensor默认放在GPU上

tf.ConfigProto

tf.ConfigProto()主要的作用是配置tf.Session的运算方式,比如gpu运算或者cpu运算

config = tf.ConfigProto()
config.gpu_options.allow_growth = True       	# 当前进程尽情使用需要的显存	 	
config.allow_soft_placement = True				# 有时候,不同的设备,它的cpu和gpu是不同的,如果将这个选项设置成True,那么当运行设备不满足要求时,会自动分配GPU或者CPU。
config.log_device_placement = False          	# 获取你的 operations 和 Tensor 被指派到哪个设备上运行,会打印出op和Tensor的设备日志
sess = tf.Session(config = config)

TensorBoard使用

Scalar的添加

网络训练过程中的auccracy和loss通常使用scalar的形式来展示
步骤:

  1. 定义要收集的指标,如:metric_loss = tf.summary.scalar(“loss”, loss)。
  2. 调用merge_all或merge把summary信息保存到磁盘,以便tensorboard展示。如:summary_op = tf.summary.merge_all()。
  3. 定义FileWriter,如:writer = tf.summary.FileWriter(’./graph’,sess.graph)。
  4. 运行summary_op。sess.run(summary_op)
  5. 使用FileWriter将summary写入日志文件。如:writer.add_summary(summary, step)。
# 1. 定义scalar
tf.summary.scalar('accuracy',acc)     
# 2. 定义summary_op          
summary_op = tf.summary.merge_all()  
# 3. 定义FileWriter
writer = tf.summary.FileWriter(DIR,sess.graph)

for step in range(training_step):       #训练循环  
	#  4. 运行summary_op得到summary
    summary = sess.run(summary_op,feed_dict =  {...})
    # 5. 使用writer将summary和step写入日志文件
    writer.add_summary(summary,step)
tensorboard展示

执行tensorboard --logdir=DIR --port=PORT,然后在http://localhost:6006中便可查看
在服务器上运行tensorboard,然后再本地浏览器查看需要在本地进行端口转发

ssh -N -f -L 6006:172.17.0.6:6006 liufengqi@202.120.38.4  -p 20201
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值