#NEWLINE# def transform_source_batch( self , source , source_name ) : #NEWLINE# #INDENT# self . verify_axis_labels ( ( 'batch' , 'channel' , 'height' , 'width' ) , source . data_stream . axis_labels [ source_name ] , source_name ) #NEWLINE# ( windowed_height , windowed_width ) = self . window_shape #NEWLINE# if ( isinstance ( source , list ) and all ( ( ( isinstance ( b , numpy . ndarray ) and ( b . ndim == 3 ) ) for b in source ) ) ) : #NEWLINE# #INDENT# return [ self . transform_source_example ( im , source_name ) for im in source ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( isinstance ( source , numpy . ndarray ) and ( source . ndim == 4 ) ) : #NEWLINE# #INDENT# out = numpy . empty ( ( source . shape [ : 2 ] + self . window_shape ) , dtype = source . dtype ) #NEWLINE# batch_size = source . shape [ 0 ] #NEWLINE# ( image_height , image_width ) = source . shape [ 2 : ] #NEWLINE# max_h_off = ( image_height - windowed_height ) #NEWLINE# max_w_off = ( image_width - windowed_width ) #NEWLINE# if ( ( max_h_off < 0 ) or ( max_w_off < 0 ) ) : #NEWLINE# #INDENT# raise ValueError ( 'Got ndarray batch with image dimensions {} but requested window shape of {}' . format ( source . shape [ 2 : ] , self . window_shape ) ) #NEWLINE# #UNINDENT# offsets_w = self . rng . random_integers ( 0 , max_w_off , size = batch_size ) #NEWLINE# offsets_h = self . rng . random_integers ( 0 , max_h_off , size = batch_size ) #NEWLINE# window_batch_bchw ( source , offsets_h , offsets_w , out ) #NEWLINE# return out #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( 'uninterpretable batch format; expected a list of arrays with ndim = 3, or an array with ndim = 4' )