#NEWLINE# def WeightActs_python( images , hidacts , filter_rows , filter_cols , stride = 1 ) : #NEWLINE# #INDENT# if ( int ( stride ) != stride ) : #NEWLINE# #INDENT# raise TypeError ( 'stride must be an int' , stride ) #NEWLINE# #UNINDENT# stride = int ( stride ) #NEWLINE# ( channels , rows , cols , batch_size ) = images . shape #NEWLINE# ( num_filters , hidact_rows , hidact_cols , _batch_size ) = hidacts . shape #NEWLINE# assert ( _batch_size == batch_size ) #NEWLINE# assert ( filter_rows == filter_cols ) #NEWLINE# f_shape = ( channels , f , filter_cols , num_filters ) #NEWLINE# f = np . zeros ( f_shape , dtype = 'float32' ) #NEWLINE# if ( stride > 1 ) : #NEWLINE# #INDENT# if ( ( ( rows - filter_rows ) % stride ) == 0 ) : #NEWLINE# #INDENT# stride_padding_rows = 0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# stride_padding_rows = ( ( ( ( ( ( rows - filter_rows ) / stride ) + 1 ) * stride ) + filter_rows ) - rows ) #NEWLINE# #UNINDENT# idx_rows = ( ( ( rows + stride_padding_rows ) - filter_rows ) / stride ) #NEWLINE# if ( ( ( cols - filter_cols ) % stride ) == 0 ) : #NEWLINE# #INDENT# stride_padding_cols = 0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# stride_padding_cols = ( ( ( ( ( ( cols - filter_cols ) / stride ) + 1 ) * stride ) + filter_cols ) - cols ) #NEWLINE# #UNINDENT# idx_cols = ( ( ( cols + stride_padding_cols ) - filter_cols ) / stride ) #NEWLINE# new_rows = ( rows + stride_padding_rows ) #NEWLINE# new_cols = ( cols + stride_padding_cols ) #NEWLINE# idx_rows = ( ( new_rows - filter_rows ) / stride ) #NEWLINE# idx_cols = ( ( new_cols - filter_cols ) / stride ) #NEWLINE# new_images = np . zeros ( ( channels , new_rows , new_cols , batch_size ) , dtype = 'float32' ) #NEWLINE# new_images [ : , : rows , : cols , : ] = images #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# new_images = images #NEWLINE# #UNINDENT# n_dim_filter = ( ( channels * filter_rows ) * filter_cols ) #NEWLINE# for idx_filters in xrange ( num_filters ) : #NEWLINE# #INDENT# for idx_h_rows in xrange ( hidact_rows ) : #NEWLINE# #INDENT# for idx_h_cols in xrange ( hidact_cols ) : #NEWLINE# #INDENT# rc_images = new_images [ : , ( idx_h_rows * stride ) : ( ( idx_h_rows * stride ) + filter_rows ) , ( idx_h_cols * stride ) : ( ( idx_h_cols * stride ) + filter_cols ) , : ] #NEWLINE# rc_filters = np . dot ( hidacts [ idx_filters , idx_h_rows , idx_h_cols , : ] . reshape ( 1 , batch_size ) , rc_images . reshape ( n_dim_filter , batch_size ) . T ) #NEWLINE# f [ : , : , : , idx_filters ] += rc_filters . reshape ( channels , filter_rows , filter_cols ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return f