#NEWLINE# def py_conv_scipy( img , kern , mode , subsample ) : #NEWLINE# #INDENT# assert ( img . shape [ 1 ] == kern . shape [ 1 ] ) #NEWLINE# if ( mode == 'valid' ) : #NEWLINE# #INDENT# outshp = ( img . shape [ 0 ] , kern . shape [ 0 ] , ( ( img . shape [ 2 ] - kern . shape [ 2 ] ) + 1 ) , ( ( img . shape [ 3 ] - kern . shape [ 3 ] ) + 1 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# outshp = ( img . shape [ 0 ] , kern . shape [ 0 ] , ( ( img . shape [ 2 ] + kern . shape [ 2 ] ) - 1 ) , ( ( img . shape [ 3 ] + kern . shape [ 3 ] ) - 1 ) ) #NEWLINE# #UNINDENT# out = numpy . zeros ( outshp , dtype = 'float32' ) #NEWLINE# for b in xrange ( out . shape [ 0 ] ) : #NEWLINE# #INDENT# for k in xrange ( out . shape [ 1 ] ) : #NEWLINE# #INDENT# for s in xrange ( img . shape [ 1 ] ) : #NEWLINE# #INDENT# out [ b , k , : , : ] += convolve2d ( img [ b , s , : , : ] , kern [ k , s , : , : ] , mode ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return out [ : , : , : : subsample [ 0 ] , : : subsample [ 1 ] ]