slim.arg_scope中python技巧

slim.arg_scope函数说明如下:

Stores the default arguments for the given set of list_ops.
For usage, please see examples at top of the file.
Args:
list_ops_or_scope: List or tuple of operations to set argument scope for or
a dictionary containing the current scope. When list_ops_or_scope is a
dict, kwargs must be empty. When list_ops_or_scope is a list or tuple,
then every op in it need to be decorated with @add_arg_scope to work.
**kwargs: keyword=value that will define the defaults for each op in
list_ops. All the ops need to accept the given set of arguments.
Yields:
the current_scope, which is a dictionary of {op: {arg: value}}
Raises:
TypeError: if list_ops is not a list or a tuple.
ValueError: if any op in list_ops has not be decorated with @add_arg_scope.

因此使用@slim.add_arg_scope修饰目标函数,从而达到用slim.arg_scope为目标函数设置默认参数。而库中的conv2d等函数,已经被默认声明。因此,可以在构建网络时,快捷设置,达到节省时间的目的。同时,也可以通过下面的方式进行单独声明。

with slim.arg_scope(
    [slim.conv2d,slim.max_pool2d],stride = 1,padding = 'SAME'):
    net = slim.conv2d(net,32,[3,3],stride=2,scope = 'conv1')

猜你喜欢

转载自www.cnblogs.com/zy-blogs/p/10458561.html