#NEWLINE# def get_output_shape( layer_or_layers , input_shapes = None ) : #NEWLINE# #INDENT# '\n    Computes the output shape of the network at one or more given layers.\n\n    Parameters\n    ----------\n    layer_or_layers : Layer or list\n        the :class:`Layer` instance for which to compute the output\n        shapes, or a list of :class:`Layer` instances.\n\n    input_shapes : None, tuple, or dict\n        If None, uses the input shapes associated with the\n        :class:`InputLayer` instances.\n        If a tuple, this defines the input shape for a single\n        :class:`InputLayer` instance. Will throw a ValueError if there\n        are multiple :class:`InputLayer` instances.\n        If a dictionary, any :class:`Layer` instance (including the\n        input layers) can be mapped to a shape tuple to use instead of\n        its regular output shape.\n\n    Returns\n    -------\n    tuple or list\n        the output shape of the given layer(s) for the given network input\n    ' #NEWLINE# if ( ( input_shapes is None ) or ( input_shapes == { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# return [ layer . output_shape for layer in layer_or_layers ] #NEWLINE# #UNINDENT# except TypeError : #NEWLINE# #INDENT# return layer_or_layers . output_shape #NEWLINE# #UNINDENT# #UNINDENT# from . input import InputLayer #NEWLINE# from . base import MergeLayer #NEWLINE# if isinstance ( input_shapes , dict ) : #NEWLINE# #INDENT# treat_as_input = input_shapes . keys ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# treat_as_input = [ ] #NEWLINE# #UNINDENT# all_layers = get_all_layers ( layer_or_layers , treat_as_input ) #NEWLINE# all_shapes = dict ( ( ( layer , layer . shape ) for layer in all_layers if ( isinstance ( layer , InputLayer ) and ( layer not in treat_as_input ) ) ) ) #NEWLINE# if isinstance ( input_shapes , dict ) : #NEWLINE# #INDENT# all_shapes . update ( input_shapes ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( input_shapes is not None ) : #NEWLINE# #INDENT# if ( len ( all_shapes ) > 1 ) : #NEWLINE# #INDENT# raise ValueError ( 'get_output_shape() was called with a single input shape on a network with multiple input layers. Please call it with a dictionary of input shapes instead.' ) #NEWLINE# #UNINDENT# for input_layer in all_shapes : #NEWLINE# #INDENT# all_shapes [ input_layer ] = input_shapes #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for layer in all_layers : #NEWLINE# #INDENT# if ( layer not in all_shapes ) : #NEWLINE# #INDENT# if isinstance ( layer , MergeLayer ) : #NEWLINE# #INDENT# input_shapes = [ all_shapes [ input_layer ] for input_layer in layer . input_layers ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# input_shapes = all_shapes [ layer . input_layer ] #NEWLINE# #UNINDENT# all_shapes [ layer ] = layer . get_output_shape_for ( input_shapes ) #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# return [ all_shapes [ layer ] for layer in layer_or_layers ] #NEWLINE# #UNINDENT# except TypeError : #NEWLINE# #INDENT# return all_shapes [ layer_or_layers ]