tensorflow slim库的使用

slim库的导入:

import tensorflow as tf
import tensorflow.contrib.slim as slim

常用函数:

与tensorflow自带的函数相比,slim能够让我们不用重复写函数的参数。那么函数的参数写在哪里呢?核心方法就是slim.arg_scope。

slim.arg_scope

def arg_scope(list_ops_or_scope, **kwargs)
 list_ops_or_scope:要用的函数的作用域,可以在需要使用的地方用@add_arg_scope 声明
 **kwargs: keyword=value 定义了list_ops中要使用的变量

也就是说可以通过这个函数将不想重复写的参数通过这个函数自动赋值。

示例:

import tensorflow.contrib.slim as slim
@slim.add_arg_scope
def hh(name, add_arg):
    print("name:", name)
    print("add_arg:", add_arg)

with slim.arg_scope([hh], add_arg='this is add'):
    hh('test')
#结果:
#name: test
#add_arg: this is add

之后是使用slim构建神经网络常用的函数。

slim.conv2d

slim.conv2d是对tf.conv2d的进一步封装。常见调用方式:

net = slim.conv2d(inputs, 256, [3, 3], stride=1, scope='conv1_1')
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值