def setup_training(self, session): """ Apply sigmoid non-linearity to side layer ouputs + fuse layer outputs Compute total loss := side_layer_loss + fuse_layer_loss Compute predicted edge maps from fuse layer as pseudo performance metric to track """ self.predictions = [] # self.coord_pred = [] self.loss = 0 self.io.print_warning('Deep supervision application set to {}'.format( self.cfgs['deep_supervision'])) for idx, b in enumerate(self.side_outputs): output = tf.nn.sigmoid(b, name='output_{}'.format(idx)) #print("The {} layer's shape is:".format(idx), b.get_shape()) cost = sigmoid_cross_entropy_balanced( b, self.edgemaps, name='cross_entropy{}'.format(idx)) self.predictions.append(output) if self.cfgs['deep_supervision']: self.loss += (self.cfgs['loss_weights'] * cost) # self.coord_pred.append(self.fc3l) fuse_output = tf.nn.sigmoid(self.fuse, name='fuse') fuse_cost = sigmoid_cross_entropy_balanced(self.fuse, self.edgemaps, name='cross_entropy_fuse') # coincide_cost = vertices_and_edges_loss(self.fuse, self.fc3l, self.coordinates) coord_cost = tf.losses.huber_loss(self.coordinates, self.regressor) self.predictions.append(fuse_output) self.loss += (self.cfgs['loss_weights'] * fuse_cost) self.loss += coord_cost # self.loss += coincide_cost pred = tf.cast(tf.greater(fuse_output, 0.5), tf.int32, name='predictions') error = tf.cast(tf.not_equal(pred, tf.cast(self.edgemaps, tf.int32)), tf.float32) cd_error = tf.cast(tf.square(self.regressor - self.coordinates), tf.float32) self.cd_error = tf.reduce_mean(cd_error, name='regression_error') self.error = tf.reduce_mean(error, name='pixel_error') tf.summary.scalar('loss', self.loss) tf.summary.scalar('error', self.error) tf.summary.scalar('cd_error', self.cd_error) self.merged_summary = tf.summary.merge_all() self.train_writer = tf.summary.FileWriter( self.cfgs['save_dir'] + '/train', session.graph) self.val_writer = tf.summary.FileWriter(self.cfgs['save_dir'] + '/val')
def setup_training(self, session): """ Apply sigmoid non-linearity to side layer ouputs + fuse layer outputs Compute total loss := side_layer_loss + fuse_layer_loss Compute predicted edge maps from fuse layer as pseudo performance metric to track """ self.predictions = [] self.loss = 0 self.io.print_warning('Deep supervision application set to {}'.format( self.cfgs['deep_supervision'])) for idx, b in enumerate(self.side_outputs): #tf.summary.image('output_{}'.format(idx), b) output = tf.nn.sigmoid(b, name='output_{}'.format(idx)) cost = sigmoid_cross_entropy_balanced( b, self.edgemaps, name='cross_entropy{}'.format(idx)) self.predictions.append(output) if self.cfgs['deep_supervision']: self.loss += (self.cfgs['loss_weights'] * cost) #tf.summary.image('fuse', self.fuse) fuse_output = tf.nn.sigmoid(self.fuse, name='fuse') tf.summary.image('fuseSigmoid', fuse_output) fuse_cost = sigmoid_cross_entropy_balanced(self.fuse, self.edgemaps, name='cross_entropy_fuse') #tf.summary.image('cvSource', self.images) tf.summary.image('cvSourceEdge', self.edgemaps) self.predictions.append(fuse_output) self.loss += (self.cfgs['loss_weights'] * fuse_cost) pred = tf.cast(tf.greater(fuse_output, 0.5), tf.int32, name='predictions') error = tf.cast(tf.not_equal(pred, tf.cast(self.edgemaps, tf.int32)), tf.float32) self.error = tf.reduce_mean(error, name='pixel_error') tf.summary.scalar('loss', self.loss) tf.summary.scalar('error', self.error) self.merged_summary = tf.summary.merge_all() save_dir = self.saveDir if not os.path.exists(save_dir): os.makedirs(save_dir) self.train_writer = tf.summary.FileWriter(save_dir + '/train', session.graph) self.val_writer = tf.summary.FileWriter(save_dir + '/val')
def setup_training(self, session): """ Apply sigmoid non-linearity to side layer ouputs + fuse layer outputs Compute total loss := side_layer_loss + fuse_layer_loss Compute predicted edge maps from fuse layer as pseudo performance metric to track """ deep_supervision=True self.predictions = [] self.loss = 0 for idx, b in enumerate(self.side_outputs): output = tf.nn.sigmoid(b, name='output_{}'.format(idx)) cost = sigmoid_cross_entropy_balanced(b, self.edgemaps, name='cross_entropy{}'.format(idx)) self.predictions.append(output) if deep_supervision: self.loss += (1.0 * cost) fuse_output = tf.nn.sigmoid(self.fuse, name='fuse') fuse_cost = sigmoid_cross_entropy_balanced(self.fuse, self.edgemaps, name='cross_entropy_fuse') self.predictions.append(fuse_output) self.loss += (1.0 * fuse_cost) pred = tf.cast(tf.greater(fuse_output, 0.5), tf.int32, name='predictions') error = tf.cast(tf.not_equal(pred, tf.cast(self.edgemaps, tf.int32)), tf.float32) self.error = tf.reduce_mean(error, name='pixel_error') tf.summary.scalar('loss', self.loss) tf.summary.scalar('error', self.error) self.merged_summary = tf.summary.merge_all() self.train_writer = tf.summary.FileWriter(base_path + '/train', session.graph) self.val_writer = tf.summary.FileWriter(base_path + '/val')