#NEWLINE# def InitializeParameter( self , param ) : #NEWLINE# #INDENT# if ( param . initialization == deepnet_pb2 . Parameter . CONSTANT ) : #NEWLINE# #INDENT# return ( np . zeros ( tuple ( param . dimensions ) ) + param . constant ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( param . initialization == deepnet_pb2 . Parameter . DENSE_GAUSSIAN ) : #NEWLINE# #INDENT# return ( param . sigma * np . random . randn ( * tuple ( param . dimensions ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( param . initialization == deepnet_pb2 . Parameter . DENSE_UNIFORM ) : #NEWLINE# #INDENT# return ( param . sigma * ( ( 2 * np . random . rand ( * tuple ( param . dimensions ) ) ) - 1 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( param . initialization == deepnet_pb2 . Parameter . DENSE_GAUSSIAN_SQRT_FAN_IN ) : #NEWLINE# #INDENT# assert ( len ( param . dimensions ) > 1 ) #NEWLINE# if ( param . conv or param . local ) : #NEWLINE# #INDENT# fan_in = np . prod ( stddev . dimensions [ 0 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# fan_in = np . prod ( param . dimensions [ 1 ] ) #NEWLINE# #UNINDENT# stddev = ( param . sigma / np . sqrt ( fan_in ) ) #NEWLINE# return ( stddev * np . random . randn ( * tuple ( param . dimensions ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( param . initialization == deepnet_pb2 . Parameter . DENSE_UNIFORM_SQRT_FAN_IN ) : #NEWLINE# #INDENT# assert ( len ( param . dimensions ) > 1 ) #NEWLINE# if ( param . conv or param . local ) : #NEWLINE# #INDENT# fan_in = np . prod ( param . dimensions [ 0 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# fan_in = np . prod ( param . dimensions [ 1 ] ) #NEWLINE# #UNINDENT# stddev = ( param . sigma / np . sqrt ( fan_in ) ) #NEWLINE# return ( stddev * ( ( 2 * np . random . rand ( * tuple ( param . dimensions ) ) ) - 1 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( param . initialization == deepnet_pb2 . Parameter . PRETRAINED ) : #NEWLINE# #INDENT# return self . LoadPretrained ( param ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise Exception ( 'Unknown parameter initialization.' )