parameters: (self, input_, mean_f, mode='elementwise')
docstring: Set the mean to subtract for data centering.
  
      Take
      input_: which input to assign this mean.
      mean_f: path to mean .npy with ndarray (input dimensional or broadcastable)
      mode: elementwise = use the whole mean (and check dimensions)
            channel = channel constant (e.g. mean pixel instead of mean image)
docstring_summary: Set the mean to subtract for data centering.
docstring_tokens: Set the mean to subtract for data centering .
function: def _Net_set_mean(self, input_, mean_f, mode='elementwise'):
      """
      Set the mean to subtract for data centering.
  
      Take
      input_: which input to assign this mean.
      mean_f: path to mean .npy with ndarray (input dimensional or broadcastable)
      mode: elementwise = use the whole mean (and check dimensions)
            channel = channel constant (e.g. mean pixel instead of mean image)
      """
      if not hasattr(self, 'mean'):
          self.mean = {}
      if input_ not in self.inputs:
          raise Exception('Input not in {}'.format(self.inputs))
      in_shape = self.blobs[input_].data.shape
      mean = np.load(mean_f)
      if mode == 'elementwise':
          if mean.shape != in_shape[1:]:
              # Resize mean (which requires H x W x K input in range [0,1]).
              m_min, m_max = mean.min(), mean.max()
              normal_mean = (mean - m_min) / (m_max - m_min)
              mean = caffe.io.resize_image(normal_mean.transpose((1,2,0)),
                      in_shape[2:]).transpose((2,0,1)) * (m_max - m_min) + m_min
          self.mean[input_] = mean
      elif mode == 'channel':
          self.mean[input_] = mean.mean(1).mean(1).reshape((in_shape[1], 1, 1))
      else:
          raise Exception('Mode not in {}'.format(['elementwise', 'channel']))
function_tokens: def _Net_set_mean ( self , input_ , mean_f , mode = 'elementwise' ) : if not hasattr ( self , 'mean' ) : self . mean = { } if input_ not in self . inputs : raise Exception ( 'Input not in {}' . format ( self . inputs ) ) in_shape = self . blobs [ input_ ] . data . shape mean = np . load ( mean_f ) if mode == 'elementwise' : if mean . shape != in_shape [ 1 : ] : # Resize mean (which requires H x W x K input in range [0,1]). m_min , m_max = mean . min ( ) , mean . max ( ) normal_mean = ( mean - m_min ) / ( m_max - m_min ) mean = caffe . io . resize_image ( normal_mean . transpose ( ( 1 , 2 , 0 ) ) , in_shape [ 2 : ] ) . transpose ( ( 2 , 0 , 1 ) ) * ( m_max - m_min ) + m_min self . mean [ input_ ] = mean elif mode == 'channel' : self . mean [ input_ ] = mean . mean ( 1 ) . mean ( 1 ) . reshape ( ( in_shape [ 1 ] , 1 , 1 ) ) else : raise Exception ( 'Mode not in {}' . format ( [ 'elementwise' , 'channel' ] ) )