def __init__(self, cls_ref, method_name, **kwargs): self.cls_ref = cls_ref self.method_name = method_name self.cls_symbol = ( get_canonical_name_for_symbol( self.cls_ref, add_prefix_to_v1_names=True) or get_canonical_name_for_symbol( self.cls_ref, api_name='keras', add_prefix_to_v1_names=True)) if 'name' not in kwargs: kwargs['name'] = backend.unique_object_name( 'tf.' + self.cls_symbol + '.' + self.method_name, zero_based=True, avoid_observed_names=True) kwargs['autocast'] = False # Do not individually trace op layers in the SavedModel. self._must_restore_from_config = True super(ClassMethod, self).__init__(**kwargs) # Preserve all argument data structures when saving/loading a config # (e.g., don't unnest lists that contain one element) self._preserve_input_structure_in_config = True self._expects_training_arg = False self._expects_mask_arg = False
def _make_unique_name(self, name_uid_map=None, avoid_names=None, namespace='', zero_based=False): base_name = base_layer.to_snake_case(self.__class__.__name__) name = backend.unique_object_name( base_name, name_uid_map=name_uid_map, avoid_names=avoid_names, namespace=namespace, zero_based=zero_based) return (name, base_name)
def __init__(self, attr_name, **kwargs): self.attr_name = attr_name if 'name' not in kwargs: kwargs['name'] = backend.unique_object_name( 'input.' + self.attr_name, zero_based=True, avoid_observed_names=True) kwargs['autocast'] = False # Do not individually trace op layers in the SavedModel. self._must_restore_from_config = True super(InstanceProperty, self).__init__(**kwargs) # Preserve all argument data structures when saving/loading a config # (e.g., don't unnest lists that contain one element) self._preserve_input_structure_in_config = True
def __init__(self, function, **kwargs): self.function = function self.symbol = ( get_canonical_name_for_symbol( self.function, add_prefix_to_v1_names=True) or get_canonical_name_for_symbol( self.function, api_name='keras', add_prefix_to_v1_names=True)) if 'name' not in kwargs: # Generate a name. # TFOpLambda layers avoid already-observed names, # because users cannot easily control the generated names. # Without this avoidance, users would be more likely to run # into unavoidable duplicate layer name collisions. # (For standard layers users could just set `name` when creating the # layer to work around a collision, but they can't do that for # auto-generated layers) if self.symbol: name = 'tf.' + self.symbol else: name = self.function.__name__ kwargs['name'] = backend.unique_object_name( name, zero_based=True, avoid_observed_names=True) kwargs['autocast'] = False # Decorate the function to produce this layer's call method def _call_wrapper(*args, **kwargs): return self._call_wrapper(*args, **kwargs) self.call = tf.__internal__.decorator.make_decorator( function, _call_wrapper) # Do not individually trace op layers in the SavedModel. self._must_restore_from_config = True super(TFOpLambda, self).__init__(**kwargs) # Preserve all argument data structures when saving/loading a config # (e.g., don't unnest lists that contain one element) self._preserve_input_structure_in_config = True # Warning on every invocation will be quite irksome in Eager mode. self._already_warned = False self._expects_training_arg = False self._expects_mask_arg = False