Args: layers (list or layer): layer or list of layers to apply the arguments. Returns: a context where all appearance of these layer will by default have the arguments specified by kwargs. Example: .. code-block:: python with argscope(Conv2
(layers, **kwargs)
| 21 | |
| 22 | @contextmanager |
| 23 | def argscope(layers, **kwargs): |
| 24 | """ |
| 25 | Args: |
| 26 | layers (list or layer): layer or list of layers to apply the arguments. |
| 27 | |
| 28 | Returns: |
| 29 | a context where all appearance of these layer will by default have the |
| 30 | arguments specified by kwargs. |
| 31 | |
| 32 | Example: |
| 33 | .. code-block:: python |
| 34 | |
| 35 | with argscope(Conv2D, kernel_shape=3, nl=tf.nn.relu, out_channel=32): |
| 36 | x = Conv2D('conv0', x) |
| 37 | x = Conv2D('conv1', x) |
| 38 | x = Conv2D('conv2', x, out_channel=64) # override argscope |
| 39 | |
| 40 | """ |
| 41 | if not isinstance(layers, list): |
| 42 | layers = [layers] |
| 43 | |
| 44 | for l in layers: |
| 45 | assert hasattr(l, '__argscope_enabled__'), "Argscope not supported for {}".format(l) |
| 46 | |
| 47 | # need to deepcopy so that changes to new_scope does not affect outer scope |
| 48 | new_scope = copy.deepcopy(get_arg_scope()) |
| 49 | for l in layers: |
| 50 | new_scope[l.__name__].update(kwargs) |
| 51 | _ArgScopeStack.append(new_scope) |
| 52 | yield |
| 53 | del _ArgScopeStack[-1] |
| 54 | |
| 55 | |
| 56 | def get_arg_scope(): |
no test coverage detected