Add a deferred restoration to this Layer and all children. Restorations which are requested later have higher priority, and the highest priority matching restoration is applied to a variable when it is created. Args: layer: The Layer (may not be a Network) to operate on. deferred_res
(layer, deferred_restoration)
| 845 | |
| 846 | |
| 847 | def _add_deferred_restoration(layer, deferred_restoration): |
| 848 | """Add a deferred restoration to this Layer and all children. |
| 849 | |
| 850 | Restorations which are requested later have higher priority, and the highest |
| 851 | priority matching restoration is applied to a variable when it is created. |
| 852 | |
| 853 | Args: |
| 854 | layer: The Layer (may not be a Network) to operate on. |
| 855 | deferred_restoration: A _DeferredRestoration object. |
| 856 | """ |
| 857 | # Networks don't create variables at the moment, so this append isn't strictly |
| 858 | # necessary. We could get by with only adding deferred restorations to |
| 859 | # non-Network Layers. |
| 860 | if isinstance(layer, Network): |
| 861 | layer._set_scope() |
| 862 | # Make sure this Layer has a deferred restoration queue and a custom getter, |
| 863 | # then add our request to it. |
| 864 | if not hasattr(layer, "_custom_getter"): |
| 865 | assert not hasattr(layer, "_deferred_restorations") |
| 866 | layer._custom_getter, layer._deferred_restorations = ( |
| 867 | _make_custom_getter_for_deferred_restorations()) |
| 868 | # We use set_custom_getter because it avoids recursively calling up the |
| 869 | # variable_scope tree. We've done the tree traversal ourselves and have added |
| 870 | # the request to each Layer which needs it. |
| 871 | layer._scope.set_custom_getter(layer._custom_getter) |
| 872 | layer._deferred_restorations.append(deferred_restoration) |
| 873 | if isinstance(layer, Network): |
| 874 | for sublayer in layer.layers: |
| 875 | if not isinstance(sublayer, Network): |
| 876 | layer._set_scope_for_nonnetwork_sublayer(sublayer) |
| 877 | _add_deferred_restoration(sublayer, deferred_restoration) |
| 878 | |
| 879 | |
| 880 | def _restore_existing_variables(network, save_path, map_func, user_map_func): |
no test coverage detected