(self)
return layers
Returns a list of (layer_name, output_expr, trainable_vars) tuples corresponding to
        individual layers of the network. Mainly intended to be used for reporting.
Returns a list of (layer_name, output_expr, trainable_vars) tuples corresponding to
        individual layers of the network. Mainly intended to be used for reporting.
Returns a list of ( layer_name output_expr trainable_vars ) tuples corresponding to individual layers of the network . Mainly intended to be used for reporting .
def list_layers(self) -> List[Tuple[str, TfExpression, List[TfExpression]]]:
        """Returns a list of (layer_name, output_expr, trainable_vars) tuples corresponding to
        individual layers of the network. Mainly intended to be used for reporting."""
        layers = []

        def recurse(scope, parent_ops, parent_vars, level):
            # Ignore specific patterns.
            if any(p in scope for p in ["/Shape", "/strided_slice", "/Cast", "/concat", "/Assign"]):
                return

            # Filter ops and vars by scope.
            global_prefix = scope + "/"
            local_prefix = global_prefix[len(self.scope) + 1:]
            cur_ops = [op for op in parent_ops if op.name.startswith(global_prefix) or op.name == global_prefix[:-1]]
            cur_vars = [(name, var) for name, var in parent_vars if name.startswith(local_prefix) or name == local_prefix[:-1]]
            if not cur_ops and not cur_vars:
                return

            # Filter out all ops related to variables.
            for var in [op for op in cur_ops if op.type.startswith("Variable")]:
                var_prefix = var.name + "/"
                cur_ops = [op for op in cur_ops if not op.name.startswith(var_prefix)]

            # Scope does not contain ops as immediate children => recurse deeper.
            contains_direct_ops = any("/" not in op.name[len(global_prefix):] and op.type not in ["Identity", "Cast", "Transpose"] for op in cur_ops)
            if (level == 0 or not contains_direct_ops) and (len(cur_ops) + len(cur_vars)) > 1:
                visited = set()
                for rel_name in [op.name[len(global_prefix):] for op in cur_ops] + [name[len(local_prefix):] for name, _var in cur_vars]:
                    token = rel_name.split("/")[0]
                    if token not in visited:
                        recurse(global_prefix + token, cur_ops, cur_vars, level + 1)
                        visited.add(token)
                return

            # Report layer.
            layer_name = scope[len(self.scope) + 1:]
            layer_output = cur_ops[-1].outputs[0] if cur_ops else cur_vars[-1][1]
            layer_trainables = [var for _name, var in cur_vars if var.trainable]
            layers.append((layer_name, layer_output, layer_trainables))

        recurse(self.scope, self.list_ops(), list(self.vars.items()), 0)
        return layers
def list_layers ( self ) -> List [ Tuple [ str , TfExpression , List [ TfExpression ] ] ] : layers = [ ] def recurse ( scope , parent_ops , parent_vars , level ) : # Ignore specific patterns. if any ( p in scope for p in [ "/Shape" , "/strided_slice" , "/Cast" , "/concat" , "/Assign" ] ) : return # Filter ops and vars by scope. global_prefix = scope + "/" local_prefix = global_prefix [ len ( self . scope ) + 1 : ] cur_ops = [ op for op in parent_ops if op . name . startswith ( global_prefix ) or op . name == global_prefix [ : - 1 ] ] cur_vars = [ ( name , var ) for name , var in parent_vars if name . startswith ( local_prefix ) or name == local_prefix [ : - 1 ] ] if not cur_ops and not cur_vars : return # Filter out all ops related to variables. for var in [ op for op in cur_ops if op . type . startswith ( "Variable" ) ] : var_prefix = var . name + "/" cur_ops = [ op for op in cur_ops if not op . name . startswith ( var_prefix ) ] # Scope does not contain ops as immediate children => recurse deeper. contains_direct_ops = any ( "/" not in op . name [ len ( global_prefix ) : ] and op . type not in [ "Identity" , "Cast" , "Transpose" ] for op in cur_ops ) if ( level == 0 or not contains_direct_ops ) and ( len ( cur_ops ) + len ( cur_vars ) ) > 1 : visited = set ( ) for rel_name in [ op . name [ len ( global_prefix ) : ] for op in cur_ops ] + [ name [ len ( local_prefix ) : ] for name , _var in cur_vars ] : token = rel_name . split ( "/" ) [ 0 ] if token not in visited : recurse ( global_prefix + token , cur_ops , cur_vars , level + 1 ) visited . add ( token ) return # Report layer. layer_name = scope [ len ( self . scope ) + 1 : ] layer_output = cur_ops [ - 1 ] . outputs [ 0 ] if cur_ops else cur_vars [ - 1 ] [ 1 ] layer_trainables = [ var for _name , var in cur_vars if var . trainable ] layers . append ( ( layer_name , layer_output , layer_trainables ) ) recurse ( self . scope , self . list_ops ( ) , list ( self . vars . items ( ) ) , 0 ) return layers