Amended previous commit,to avoid crop if loss_border is 0,0-tuple or None. Updated initialise_aggregator function to allow identity aggregator.
@@ -29,6 +29,7 @@ from niftynet.layer.rgb_histogram_equilisation import \
RGBHistogramEquilisationLayer
from niftynet.evaluation.regression_evaluator import RegressionEvaluator
from niftynet.layer.rand_elastic_deform import RandomElasticDeformationLayer
+from niftynet.engine.windows_aggregator_identity import WindowAsImageAggregator
SUPPORTED_INPUT = set(['image', 'output', 'weight', 'sampler', 'inferred'])
@@ -221,6 +222,12 @@ class RegressionApplication(BaseApplication):
interp_order=self.action_param.output_interp_order,
postfix=self.action_param.output_postfix)
+ def initialise_identity_aggregator(self):
+ self.output_decoder = WindowAsImageAggregator(
+ image_reader=self.readers[0],
+ output_path=self.action_param.save_seg_dir,
+ postfix=self.action_param.output_postfix)
+
def initialise_sampler(self):
if self.is_training:
self.SUPPORTED_SAMPLING[self.net_param.window_sampling][0]()
@@ -228,6 +235,9 @@ class RegressionApplication(BaseApplication):
self.SUPPORTED_SAMPLING[self.net_param.window_sampling][1]()
def initialise_aggregator(self):
+ if self.net_param.force_identity_output_resizing:
+ self.initialise_identity_aggregator()
+ else:
self.SUPPORTED_SAMPLING[self.net_param.window_sampling][2]()
def initialise_network(self):
@@ -283,21 +293,20 @@ class RegressionApplication(BaseApplication):
learning_rate=self.action_param.lr)
loss_func = LossFunction(loss_type=self.action_param.loss_type)
- #crop_layer = CropLayer(border=self.regression_param.loss_border)
weight_map = data_dict.get('weight', None)
border=self.regression_param.loss_border
- if border > 0:
+ if border == None or tf.reduce_sum(tf.abs(border)) == 0:
+ data_loss = loss_func(
+ prediction=net_out,
+ ground_truth=data_dict['output'],
+ weight_map=weight_map)
+ else:
crop_layer = CropLayer(border)
weight_map = None if weight_map is None else crop_layer(weight_map)
data_loss = loss_func(
prediction=crop_layer(net_out),
ground_truth=crop_layer(data_dict['output']),
weight_map=weight_map)
- else:
- data_loss = loss_func(
- prediction=net_out,
- ground_truth=data_dict['output'],
- weight_map=weight_map)
reg_losses = tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES)
if self.net_param.decay > 0.0 and reg_losses:
reg_loss = tf.reduce_mean(
