def __init__(self): self.reader = im_reader(is_training=True) self.net = Net() self.rpn_loss_obj = RPN_loss( self.net.rpn_predictions['rpn_coord_bias'], self.net.rpn_predictions['rpn_bk_score'], self.net.rpn_predictions['rpn_targets'], self.net.rpn_predictions['rpn_bk_label'], self.net.rpn_predictions['rpn_index'] ) self.roi_loss_obj = ROI_loss( self.net.roi_predictions['reg_bias'], self.net.roi_predictions['cls_score'], self.net.roi_predictions['roi_targets'], self.net.roi_predictions['roi_cls_label'], self.net.roi_predictions['roi_inside_w'] ) self.rpn_bk_loss, self.rpn_reg_loss = self.rpn_loss_obj.add_loss() self.roi_cls_loss, self.roi_reg_loss = self.roi_loss_obj.add_loss() self.total_loss = self.rpn_bk_loss + self.rpn_reg_loss + \ self.roi_cls_loss+self.roi_reg_loss self.loss_dict = { 'rpn_bk_loss': self.rpn_bk_loss, 'rpn_reg_loss': self.rpn_reg_loss, 'roi_cls_loss': self.roi_cls_loss, 'roi_reg_loss': self.roi_reg_loss, 'total_loss': self.total_loss } if os.path.exists('result.txt'): with open('result.txt') as f: self.loss = eval(f.read()) else: self.loss = []
def __init__(self): self.reader = im_reader(is_training=False) self.net = Net(is_training=False) self.saver = tf.train.Saver() self.num_classes = len(cfg.CLASSES)
abs_in_box_diff = tf.abs(in_box_diff) smoothL1_sign = tf.stop_gradient( tf.to_float(tf.less(abs_in_box_diff, 1. / sigma_2))) in_loss_box = tf.pow(in_box_diff, 2) * (sigma_2 / 2.) * smoothL1_sign \ + (abs_in_box_diff - (0.5 / sigma_2)) * (1. - smoothL1_sign) out_loss_box = in_loss_box loss = tf.reduce_mean(tf.reduce_sum(out_loss_box, axis=dim)) return loss if __name__ == "__main__": from network import Net from read_data import im_reader reader = im_reader(is_training=True) net = Net() data = reader.generate() _, height, width, _ = data['image'].shape rpn_loss_obj = RPN_loss(net.rpn_predictions['rpn_coord_bias'], net.rpn_predictions['rpn_bk_score'], net.rpn_predictions['rpn_targets'], net.rpn_predictions['rpn_bk_label'], net.rpn_predictions['rpn_index']) 'pred_bias, pred_bk_score, targets, true_bk_labels, keep_index' bk_loss, reg_loss = rpn_loss_obj.add_loss()