Commit b5ca3021 authored by Yuxin Wu's avatar Yuxin Wu

update docs about variable scope (#1153)

parent a57fa460
...@@ -14,9 +14,9 @@ TensorFlow itself also changes API and those are not listed here. ...@@ -14,9 +14,9 @@ TensorFlow itself also changes API and those are not listed here.
code that relies on internals of `InputDesc`. code that relies on internals of `InputDesc`.
To use `tf.TensorSpec` in your `ModelDesc`: To use `tf.TensorSpec` in your `ModelDesc`:
```python ```python
def inputs(self): def inputs(self):
return [tf.TensorSpec((None, 28, 28, 1), tf.float32, 'image'), return [tf.TensorSpec((None, 28, 28, 1), tf.float32, 'image'),
tf.TensorSpec((None,), tf.int32, 'label')] tf.TensorSpec((None,), tf.int32, 'label')]
``` ```
+ [2018/08/27] msgpack is used for "serialization to disk", because pyarrow + [2018/08/27] msgpack is used for "serialization to disk", because pyarrow
has no compatibility between versions. To use pyarrow instead, `export TENSORPACK_COMPATIBLE_SERIALIZE=pyarrow`. has no compatibility between versions. To use pyarrow instead, `export TENSORPACK_COMPATIBLE_SERIALIZE=pyarrow`.
...@@ -25,7 +25,7 @@ TensorFlow itself also changes API and those are not listed here. ...@@ -25,7 +25,7 @@ TensorFlow itself also changes API and those are not listed here.
It's later found that pyarrow is unstable and may lead to crash. It's later found that pyarrow is unstable and may lead to crash.
So the default serialization is changed back to msgpack. So the default serialization is changed back to msgpack.
+ [2018/03/20] `ModelDesc` starts to use simplified interfaces: + [2018/03/20] `ModelDesc` starts to use simplified interfaces:
+ `_get_inputs()` renamed to `inputs()` and returns `tf.placeholder`s. + `_get_inputs()` renamed to `inputs()` and returns `tf.TensorSpec`.
+ `build_graph(self, tensor1, tensor2)` returns the cost tensor directly. + `build_graph(self, tensor1, tensor2)` returns the cost tensor directly.
+ `_get_optimizer()` renamed to `optimizer()`. + `_get_optimizer()` renamed to `optimizer()`.
Old interface will still be available for a while, but new ones are recommended. Old interface will still be available for a while, but new ones are recommended.
...@@ -38,7 +38,7 @@ TensorFlow itself also changes API and those are not listed here. ...@@ -38,7 +38,7 @@ TensorFlow itself also changes API and those are not listed here.
+ [2017/10/18] + [2017/10/18]
`TrainConfig(predict_tower)` was deprecated. You can set the inference device directly when creating the `InferenceRunner` callback. `TrainConfig(predict_tower)` was deprecated. You can set the inference device directly when creating the `InferenceRunner` callback.
+ [2017/10/12](https://github.com/tensorpack/tensorpack/commit/7e963996f615b85f7459455596b4ee9bbd0bce8e). + [2017/10/12](https://github.com/tensorpack/tensorpack/commit/7e963996f615b85f7459455596b4ee9bbd0bce8e).
`tensorpack.RL` was deprecated. The RL examples are written with OpenAI gym interface instead. `tensorpack.RL` was deprecated. The RL examples are rewritten with OpenAI gym interface instead.
+ [2017/10/10](https://github.com/tensorpack/tensorpack/commit/7d40e049691d92018f50dc7d45bba5e8b140becc). + [2017/10/10](https://github.com/tensorpack/tensorpack/commit/7d40e049691d92018f50dc7d45bba5e8b140becc).
`tfutils.distributions` was deprecated in favor of `tf.distributions` introduced in TF 1.3. `tfutils.distributions` was deprecated in favor of `tf.distributions` introduced in TF 1.3.
+ [2017/08/02](https://github.com/tensorpack/tensorpack/commit/875f4d7dbb5675f54eae5675fa3a0948309a8465). + [2017/08/02](https://github.com/tensorpack/tensorpack/commit/875f4d7dbb5675f54eae5675fa3a0948309a8465).
......
...@@ -361,9 +361,9 @@ def process_signature(app, what, name, obj, options, signature, ...@@ -361,9 +361,9 @@ def process_signature(app, what, name, obj, options, signature,
# add scope name to layer signatures: # add scope name to layer signatures:
if hasattr(obj, 'use_scope') and hasattr(obj, 'symbolic_function'): if hasattr(obj, 'use_scope') and hasattr(obj, 'symbolic_function'):
if obj.use_scope: if obj.use_scope:
signature = signature[0] + 'scope_name, ' + signature[1:] signature = signature[0] + 'variable_scope_name, ' + signature[1:]
elif obj.use_scope is None: elif obj.use_scope is None:
signature = signature[0] + '[scope_name,] ' + signature[1:] signature = signature[0] + '[variable_scope_name,] ' + signature[1:]
# signature: arg list # signature: arg list
return signature, return_annotation return signature, return_annotation
......
...@@ -68,10 +68,9 @@ def layer_register( ...@@ -68,10 +68,9 @@ def layer_register(
Args: Args:
log_shape (bool): log input/output shape of this layer log_shape (bool): log input/output shape of this layer
use_scope (bool or None): use_scope (bool or None):
Whether to call this layer with an extra first argument as scope. Whether to call this layer with an extra first argument as variable scope.
When set to None, it can be called either with or without When set to None, it can be called either with or without
the scope name argument. the scope name argument, depend on whether the first argument
It will try to figure out by checking if the first argument
is string or not. is string or not.
Returns: Returns:
...@@ -84,6 +83,9 @@ def layer_register( ...@@ -84,6 +83,9 @@ def layer_register(
@layer_register(use_scope=True) @layer_register(use_scope=True)
def add10(x): def add10(x):
return x + tf.get_variable('W', shape=[10]) return x + tf.get_variable('W', shape=[10])
# use it:
output = add10('layer_name', input) # the function will be called under variable scope "layer_name".
""" """
def wrapper(func): def wrapper(func):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment