Returns the names of all uninitialized resources in resource_list. If the returned tensor is empty then all resources have been initialized. Args: resource_list: resources to check. If None, will use shared_resources() + local_resources(). name: name for the resource-checking op.
(resource_list=None,
name="report_uninitialized_resources")
| 68 | |
| 69 | |
| 70 | def report_uninitialized_resources(resource_list=None, |
| 71 | name="report_uninitialized_resources"): |
| 72 | """Returns the names of all uninitialized resources in resource_list. |
| 73 | |
| 74 | If the returned tensor is empty then all resources have been initialized. |
| 75 | |
| 76 | Args: |
| 77 | resource_list: resources to check. If None, will use shared_resources() + |
| 78 | local_resources(). |
| 79 | name: name for the resource-checking op. |
| 80 | |
| 81 | Returns: |
| 82 | Tensor containing names of the handles of all resources which have not |
| 83 | yet been initialized. |
| 84 | |
| 85 | """ |
| 86 | if resource_list is None: |
| 87 | resource_list = shared_resources() + local_resources() |
| 88 | with ops.name_scope(name): |
| 89 | # Run all operations on CPU |
| 90 | local_device = os.environ.get( |
| 91 | "TF_DEVICE_FOR_UNINITIALIZED_VARIABLE_REPORTING", "/cpu:0") |
| 92 | with ops.device(local_device): |
| 93 | if not resource_list: |
| 94 | # Return an empty tensor so we only need to check for returned tensor |
| 95 | # size being 0 as an indication of model ready. |
| 96 | return array_ops.constant([], dtype=dtypes.string) |
| 97 | # Get a 1-D boolean tensor listing whether each resource is initialized. |
| 98 | variables_mask = math_ops.logical_not( |
| 99 | array_ops.stack([r.is_initialized for r in resource_list])) |
| 100 | # Get a 1-D string tensor containing all the resource names. |
| 101 | variable_names_tensor = array_ops.constant( |
| 102 | [s.handle.name for s in resource_list]) |
| 103 | # Return a 1-D tensor containing all the names of uninitialized resources. |
| 104 | return array_ops.boolean_mask(variable_names_tensor, variables_mask) |
| 105 | |
| 106 | |
| 107 | @tf_should_use.should_use_result |
nothing calls this directly
no test coverage detected