Skip to content

Commit

Permalink
[ENHANCE] nnf.core.iters for Core NN Framework
Browse files Browse the repository at this point in the history
Signed-off-by: Nadith Pathirage <[email protected]>
  • Loading branch information
nadith committed Sep 15, 2017
1 parent d226fc6 commit 2f6ef4b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion +nnf/+core/+iters/+memory/BigDataNumpyArrayIterator.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

% TODO: Apply necessary transofmraiton
%%x = self.image_data_generator.random_transform(x)
%x = self.image_data_generator.standardize(x)
x = self.image_data_generator.standardize(x);
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down
3 changes: 2 additions & 1 deletion +nnf/+core/+iters/+memory/MemDataIterator.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@
% zca_whitening. Currently supported only for in memory datasets.
if (self.imdata_pp_.featurewise_center || ...
self.imdata_pp_.featurewise_std_normalization || ...
self.imdata_pp_.zca_whitening)
self.imdata_pp_.zca_whitening || ...
(~isempty(self.pp_params_) && self.pp_params_.isKey('mapminmax')))
self.imdata_pp_.fit(db, ...
self.imdata_pp_.augment, ...
self.imdata_pp_.rounds, ...
Expand Down
2 changes: 1 addition & 1 deletion +nnf/+core/+iters/ImageDataGenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
end

% x is a single image, so it doesn't have image number at index 0
img_channel_index = self.channel_index - 1
img_channel_index = self.channel_index - 1;
if self.samplewise_center
M = mean(x, img_channel_index);
x = bsxfun(@minus, x, M);
Expand Down
39 changes: 24 additions & 15 deletions +nnf/+core/+iters/ImageDataPreProcessor.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

properties (SetAccess = protected)
fn_gen_coreiter_;
nrm_vgg16_;
pp_params_;
mapminmax_setting_;
end

properties (SetAccess = protected, Dependent)
Expand Down Expand Up @@ -42,15 +43,8 @@

self = [email protected](pp_params);
self.fn_gen_coreiter_ = fn_gen_coreiter;

% VGG16Model specific pre-processing param
if (isempty(pp_params))
self.nrm_vgg16_ = false;
elseif (pp_params.isKey('normalize_vgg16'))
self.nrm_vgg16_ = pp_params.get('normalize_vgg16');
else
self.nrm_vgg16_ = false;
end
self.pp_params_ = pp_params;
self.mapminmax_setting_ = [];
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand All @@ -61,20 +55,30 @@ function apply(self, settings)
self.mean = settings.mean;
self.std = settings.std;
self.principal_components = settings.principal_components;
self.map_min_max = settings.map_min_max;
self.mapminmax_setting_ = settings.mapminmax_setting_;
self.whiten = settings.whiten;
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function x = standardize(self, x)
% Standardize data sample.
if (self.nrm_vgg16_)

% New custom pre-processing param
% VGG16Model specific pre-processing param
if (~isempty(self.pp_params_) && ...
self.pp_params_.isKey('normalize_vgg16') && ...
self.pp_params_.get('normalize_vgg16'))
x(0, :, :) = x(0, :, :) - 103.939;
x(1, :, :) = x(1, :, :) - 116.779;
x(2, :, :) = x(2, :, :) - 123.68;
end

x = [email protected](self, x);

% Map min max normalization
if (~isempty(self.mapminmax_setting_))
x = mapminmax('apply', x', self.mapminmax_setting_)';
end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand All @@ -86,7 +90,13 @@ function fit(self, X, augment, rounds, seed)
if (nargin < 3); augment = false; end

[email protected](self, X, augment, rounds, seed)

% Perform whitening/mapminmax/etc
if (~isempty(self.pp_params_) && ...
self.pp_params_.isKey('mapminmax'))
minmax_range = self.pp_params_.get('mapminmax');
[~, self.mapminmax_setting_] = mapminmax(X', minmax_range(1), minmax_range(2));
end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -118,7 +128,6 @@ function fit(self, X, augment, rounds, seed)
if (nargin < 4); nb_class = []; end
if (nargin < 3); y = []; end


if (isempty(self.fn_gen_coreiter_))
core_iter = NumpyArrayIterator(X, y, nb_class, self, params);
return;
Expand Down Expand Up @@ -190,7 +199,7 @@ function fit(self, X, augment, rounds, seed)
value.mean = self.mean;
value.std = self.std;
value.principal_components = self.principal_components;
value.map_min_max = self.map_min_max;
value.mapminmax_setting_ = self.mapminmax_setting_;
value.whiten = self.whiten;
end

Expand Down

0 comments on commit 2f6ef4b

Please sign in to comment.