Use fn to map the output of any variable getter. Args: fn (tf.Variable -> tf.Tensor) Returns: The current variable scope with a custom_getter that maps all the variables by fn. Example: .. code-block:: python from tensorpack.tfutils im
(fn)
| 35 | |
| 36 | |
| 37 | def remap_variables(fn): |
| 38 | """ |
| 39 | Use fn to map the output of any variable getter. |
| 40 | |
| 41 | Args: |
| 42 | fn (tf.Variable -> tf.Tensor) |
| 43 | |
| 44 | Returns: |
| 45 | The current variable scope with a custom_getter that maps |
| 46 | all the variables by fn. |
| 47 | |
| 48 | Example: |
| 49 | .. code-block:: python |
| 50 | |
| 51 | from tensorpack.tfutils import varreplace |
| 52 | with varreplace.remap_variables(lambda var: quantize(var)): |
| 53 | x = FullyConnected('fc', x, 1000) # fc/{W,b} will be quantized |
| 54 | """ |
| 55 | def custom_getter(getter, *args, **kwargs): |
| 56 | v = getter(*args, **kwargs) |
| 57 | return fn(v) |
| 58 | return custom_getter_scope(custom_getter) |
| 59 | |
| 60 | |
| 61 | def freeze_variables(stop_gradient=True, skip_collection=False): |
no test coverage detected