1414# inheritance) so that nets created by caffe (e.g., by SGDSolver) will
1515# automatically have the improved interface.
1616
17- # Input preprocessing
18- Net .mean = {} # input mean (ndarray, input dimensional or broadcastable)
19- Net .input_scale = {} # for a model that expects data = input * input_scale
20- Net .channel_swap = {} # for RGB -> BGR and the like
21-
2217
2318@property
2419def _Net_blobs (self ):
@@ -187,10 +182,12 @@ def _Net_set_mean(self, input_, mean_f, mode='elementwise'):
187182
188183 Take
189184 input_: which input to assign this mean.
190- mean_f: path to mean .npy
185+ mean_f: path to mean .npy with ndarray (input dimensional or broadcastable)
191186 mode: elementwise = use the whole mean (and check dimensions)
192187 channel = channel constant (e.g. mean pixel instead of mean image)
193188 """
189+ if not hasattr (self , 'mean' ):
190+ self .mean = {}
194191 if input_ not in self .inputs :
195192 raise Exception ('Input not in {}' .format (self .inputs ))
196193 in_shape = self .blobs [input_ ].data .shape
@@ -218,6 +215,8 @@ def _Net_set_input_scale(self, input_, scale):
218215 input_: which input to assign this scale factor
219216 scale: scale coefficient
220217 """
218+ if not hasattr (self , 'input_scale' ):
219+ self .input_scale = {}
221220 if input_ not in self .inputs :
222221 raise Exception ('Input not in {}' .format (self .inputs ))
223222 self .input_scale [input_ ] = scale
@@ -233,6 +232,8 @@ def _Net_set_channel_swap(self, input_, order):
233232 order: the order to take the channels.
234233 (2,1,0) maps RGB to BGR for example.
235234 """
235+ if not hasattr (self , 'channel_swap' ):
236+ self .channel_swap = {}
236237 if input_ not in self .inputs :
237238 raise Exception ('Input not in {}' .format (self .inputs ))
238239 self .channel_swap [input_ ] = order
0 commit comments