def rcnn_nms(probs, deltas, rois3d, score_threshold=0.75, nms_threshold=0.001):

    cls = 1  # do for class-one only
    probs = probs[:, cls]  #see only class-1
    idx = np.where(probs > score_threshold)[0]

    #post processing
    rois3d = rois3d[idx]
    deltas = deltas[idx, cls]
    probs = probs[idx]

    if deltas.shape[1:] == (8, 3):
        boxes3d = box3d_transform_inv(rois3d, deltas)
        boxes3d = regularise_box3d(boxes3d)
        boxes = box3d_to_top_box(boxes3d)
        # dets = np.c_[boxes3d[:, 1, 0], boxes3d[:, 1, 1], boxes3d[:, 3, 0], boxes3d[:, 3, 1], probs]
        dets = np.c_[boxes, probs]
        # keep=np.logical_and((dets[:,0]<dets[:,2]),(dets[:,1]<dets[:,3]))
        # dets=dets[keep]
        keep = nms(dets, nms_threshold)
        return probs[keep], boxes3d[keep]
Exemplo n.º 2
0
def rcnn_nms( probs,  deltas,  rois3d,  score_threshold = 0.75,nms_threshold=0.001):


    cls=1  # do for class-one only
    probs = probs[:,cls] #see only class-1
    idx = np.where(probs>score_threshold)[0]

    #post processing
    rois3d = rois3d[idx]
    deltas = deltas[idx,cls]
    probs  = probs [idx]


    if deltas.shape[1:]==(8,3):
        boxes3d  = box3d_transform_inv(rois3d, deltas)
        boxes3d  = regularise_box3d(boxes3d)
        boxes=box3d_to_top_box(boxes3d)
        # dets = np.c_[boxes3d[:, 1, 0], boxes3d[:, 1, 1], boxes3d[:, 3, 0], boxes3d[:, 3, 1], probs]
        dets = np.c_[boxes, probs]
        # keep=np.logical_and((dets[:,0]<dets[:,2]),(dets[:,1]<dets[:,3]))
        # dets=dets[keep]
        keep = nms(dets, nms_threshold)
        return probs[keep], boxes3d[keep]
Exemplo n.º 3
0
    def fit_iteration(self, is_validation =False, summary_it=False, summary_runmeta=False, log_image=False,
                      summary_iou=False, iou_statistic=False):

        data_set = self.validation_set if is_validation else self.train_set
        self.default_summary_writer = \
            self.val_summary_writer if is_validation else self.train_summary_writer

        self.step_name = 'validation' if is_validation else 'training'

        # load dataset
        self.batch_rgb_images, self.batch_top_view, self.batch_front_view, \
        self.batch_gt_labels, self.batch_gt_boxes3d, self.frame_id = \
            data_set.load()

        # fit_iterate log init
        if log_image:
            self.time_str = strftime("%Y_%m_%d_%H_%M", localtime())
            self.frame_info = data_set.get_frame_info()
            self.log_subdir = self.step_name + '/' + self.time_str
            self.top_image = data.draw_top_image(self.batch_top_view[0])
            # self.top_image = self.top_image_padding(top_image)


        net = self.net
        sess = self.sess

        # put tensorboard inside
        top_cls_loss = net['top_cls_loss']
        top_reg_loss = net['top_reg_loss']
        fuse_cls_loss = net['fuse_cls_loss']
        fuse_reg_loss = net['fuse_reg_loss']


        self.batch_gt_top_boxes = data.box3d_to_top_box(self.batch_gt_boxes3d[0])

        ## run propsal generation
        fd1 = {
            net['top_view']: self.batch_top_view,
            net['top_anchors']: self.top_view_anchors,
            net['top_inside_inds']: self.anchors_inside_inds,

            blocks.IS_TRAIN_PHASE: True,
            K.learning_phase(): 1
        }
        self.batch_proposals, self.batch_proposal_scores, self.batch_top_features = \
            sess.run([net['proposals'], net['proposal_scores'], net['top_features']], fd1)

        ## generate  train rois  for RPN
        self.batch_top_inds, self.batch_top_pos_inds, self.batch_top_labels, self.batch_top_targets = \
            rpn_target(self.top_view_anchors, self.anchors_inside_inds, self.batch_gt_labels[0],
                       self.batch_gt_top_boxes)

        self.batch_top_rois, self.batch_fuse_labels, self.batch_fuse_targets = \
            fusion_target(self.batch_proposals, self.batch_gt_labels[0],
                          self.batch_gt_top_boxes, self.batch_gt_boxes3d[0])

        self.batch_rois3d = project_to_roi3d(self.batch_top_rois)
        self.batch_front_rois = project_to_front_roi(self.batch_rois3d)
        self.batch_rgb_rois = project_to_rgb_roi(self.batch_rois3d)


        ## run classification and regression loss -----------
        fd2 = {
            **fd1,

            net['top_view']: self.batch_top_view,
            net['front_view']: self.batch_front_view,
            net['rgb_images']: self.batch_rgb_images,

            net['top_rois']: self.batch_top_rois,
            net['front_rois']: self.batch_front_rois,
            net['rgb_rois']: self.batch_rgb_rois,

            net['top_inds']: self.batch_top_inds,
            net['top_pos_inds']: self.batch_top_pos_inds,
            net['top_labels']: self.batch_top_labels,
            net['top_targets']: self.batch_top_targets,

            net['fuse_labels']: self.batch_fuse_labels,
            net['fuse_targets']: self.batch_fuse_targets,
        }

        if self.debug_mode:
            print('\n\nstart debug mode\n\n')
            debug_sess=tf_debug.LocalCLIDebugWrapperSession(sess)
            t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss = \
                debug_sess.run([top_cls_loss, top_reg_loss, fuse_cls_loss, fuse_reg_loss], fd2)


        if summary_it:
            run_options = None
            run_metadata = None

            if is_validation:
                t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss, tb_sum_val = \
                    sess.run([top_cls_loss, top_reg_loss, fuse_cls_loss, fuse_reg_loss, self.summ], fd2)

                self.val_summary_writer.add_summary(tb_sum_val, self.n_global_step)
                # print('added validation  summary ')
            else:
                if summary_runmeta:
                    run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
                    run_metadata = tf.RunMetadata()

                _, t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss, tb_sum_val = \
                    sess.run([self.solver_step, top_cls_loss, top_reg_loss, fuse_cls_loss, fuse_reg_loss,
                              self.summ], feed_dict=fd2, options=run_options, run_metadata=run_metadata)

                self.train_summary_writer.add_summary(tb_sum_val, self.n_global_step)
                # print('added training  summary ')

                if summary_runmeta:
                    self.train_summary_writer.add_run_metadata(run_metadata, 'step%d' % self.n_global_step)
                    # print('added runtime metadata.')

        else:
            if is_validation:
                t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss = \
                    sess.run([top_cls_loss, top_reg_loss, fuse_cls_loss, fuse_reg_loss], fd2)
            else:

                _, t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss = \
                    sess.run([self.solver_step, top_cls_loss, top_reg_loss, fuse_cls_loss, fuse_reg_loss],
                             feed_dict=fd2)

        if log_image:
            # t0 = time.time()
            step_name = 'validation' if is_validation else  'train'
            scope_name = '%s_iter_%06d' % (step_name, self.n_global_step - (self.n_global_step % self.iter_debug))

            boxes3d, lables = self.predict(self.batch_top_view, self.batch_front_view, self.batch_rgb_images)

            # get iou
            iou = -1
            inds = np.where(self.batch_gt_labels[0] != 0)
            try:
                iou = box.boxes3d_score_iou(self.batch_gt_boxes3d[0][inds], boxes3d)
                if iou_statistic: self.iou_store.append(iou)
                if summary_iou:
                    iou_aver = sum(self.iou_store)/len(self.iou_store)
                    self.iou_store=[]
                    tag = os.path.join('IOU')
                    self.summary_scalar(value=iou_aver, tag=tag, step=self.n_global_step)
                    self.log_msg.write('\n %s iou average: %.5f\n' % (self.step_name, iou_aver))
            except ValueError:
                # print("waring :", sys.exc_info()[0])
                pass

            #set scope name
            if iou == -1:
                scope_name = os.path.join(scope_name, 'iou_error'.format(range(5, 8)))
            else:
                for iou_range in self.log_iou_range:
                    if int(iou*100) in iou_range:
                        scope_name = os.path.join(scope_name , 'iou_{}'.format (iou_range))

            # print('Summary log image, scope name: {}'.format(scope_name))

            self.log_fusion_net_target(self.batch_rgb_images[0], scope_name=scope_name)
            log_info_str = 'frame info: ' + self.frame_info + '\n'
            log_info_str += self.anchors_details()
            log_info_str += self.rpn_poposal_details()
            self.log_info(self.log_subdir, log_info_str)


            self.predict_log(self.log_subdir, log_rpn=True, step=self.n_global_step,
                             scope_name=scope_name, loss=(f_cls_loss, f_reg_loss),
                             frame_tag=self.frame_id, is_train_mode=True)


            # self.log_msg.write('Image log  summary use time : {}\n'.format(time.time() - t0))


        return t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss
Exemplo n.º 4
0
    def fit_iteration(self, batch_rgb_images, batch_top_view, batch_front_view,
                      batch_gt_labels, batch_gt_boxes3d, frame_id, is_validation =False,
                      summary_it=False, summary_runmeta=False, log=False):

        net = self.net
        sess = self.sess

        # put tensorboard inside
        top_cls_loss = net['top_cls_loss']
        top_reg_loss = net['top_reg_loss']
        fuse_cls_loss = net['fuse_cls_loss']
        fuse_reg_loss = net['fuse_reg_loss']


        self.batch_gt_top_boxes = data.box3d_to_top_box(batch_gt_boxes3d[0])

        ## run propsal generation
        fd1 = {
            net['top_view']: batch_top_view,
            net['top_anchors']: self.top_view_anchors,
            net['top_inside_inds']: self.anchors_inside_inds,

            blocks.IS_TRAIN_PHASE: True,
            K.learning_phase(): 1
        }
        self.batch_proposals, self.batch_proposal_scores, self.batch_top_features = \
            sess.run([net['proposals'], net['proposal_scores'], net['top_features']], fd1)

        ## generate  train rois  for RPN
        self.batch_top_inds, self.batch_top_pos_inds, self.batch_top_labels, self.batch_top_targets = \
            rpn_target(self.top_view_anchors, self.anchors_inside_inds, batch_gt_labels[0],
                       self.batch_gt_top_boxes)
        if log:
            step_name = 'validation' if is_validation else  'train'
            scope_name = '%s_iter_%06d' % (step_name, self.n_global_step - (self.n_global_step % self.iter_debug))
            self.log_rpn(step=self.n_global_step, scope_name=scope_name)


        self.batch_top_rois, self.batch_fuse_labels, self.batch_fuse_targets = \
            rcnn_target(self.batch_proposals, batch_gt_labels[0], self.batch_gt_top_boxes, batch_gt_boxes3d[0])

        self.batch_rois3d = project_to_roi3d(self.batch_top_rois)
        self.batch_front_rois = project_to_front_roi(self.batch_rois3d)
        self.batch_rgb_rois = project_to_rgb_roi(self.batch_rois3d)

        if log: self.log_fusion_net_target(batch_rgb_images[0], scope_name=scope_name)
        if log:
            log_info_str = 'frame info: ' + self.frame_info + '\n'
            log_info_str += self.anchors_details()
            log_info_str += self.rpn_poposal_details()
            self.log_info(self.log_subdir, log_info_str)

        ## run classification and regression loss -----------
        fd2 = {
            **fd1,

            net['top_view']: batch_top_view,
            net['front_view']: batch_front_view,
            net['rgb_images']: batch_rgb_images,

            net['top_rois']: self.batch_top_rois,
            net['front_rois']: self.batch_front_rois,
            net['rgb_rois']: self.batch_rgb_rois,

            net['top_inds']: self.batch_top_inds,
            net['top_pos_inds']: self.batch_top_pos_inds,
            net['top_labels']: self.batch_top_labels,
            net['top_targets']: self.batch_top_targets,

            net['fuse_labels']: self.batch_fuse_labels,
            net['fuse_targets']: self.batch_fuse_targets,
        }

        if self.debug_mode:
            print('\n\nstart debug mode\n\n')
            debug_sess=tf_debug.LocalCLIDebugWrapperSession(sess)
            t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss = \
                debug_sess.run([top_cls_loss, top_reg_loss, fuse_cls_loss, fuse_reg_loss], fd2)


        if summary_it:
            run_options = None
            run_metadata = None

            if is_validation:
                t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss, tb_sum_val = \
                    sess.run([top_cls_loss, top_reg_loss, fuse_cls_loss, fuse_reg_loss, self.summ], fd2)
                self.val_summary_writer.add_summary(tb_sum_val, self.n_global_step)
                print('added validation  summary ')
            else:
                if summary_runmeta:
                    run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
                    run_metadata = tf.RunMetadata()

                _, t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss, tb_sum_val = \
                    sess.run([self.solver_step, top_cls_loss, top_reg_loss, fuse_cls_loss, fuse_reg_loss,
                              self.summ], feed_dict=fd2, options=run_options, run_metadata=run_metadata)
                self.train_summary_writer.add_summary(tb_sum_val, self.n_global_step)
                print('added training  summary ')

                if summary_runmeta:
                    self.train_summary_writer.add_run_metadata(run_metadata, 'step%d' % self.n_global_step)
                    print('added runtime metadata.')

        else:
            if is_validation:
                t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss = \
                    sess.run([top_cls_loss, top_reg_loss, fuse_cls_loss, fuse_reg_loss], fd2)
            else:

                _, t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss = \
                    sess.run([self.solver_step, top_cls_loss, top_reg_loss, fuse_cls_loss, fuse_reg_loss],
                             feed_dict=fd2)
        if log: self.log_prediction(batch_top_view, batch_front_view, batch_rgb_images,
                                    step=self.n_global_step, scope_name=scope_name)

        return t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss
Exemplo n.º 5
0
    def fit_iteration(self,
                      batch_rgb_images,
                      batch_top_view,
                      batch_front_view,
                      batch_gt_labels,
                      batch_gt_boxes3d,
                      frame_id,
                      is_validation=False,
                      summary_it=False,
                      summary_runmeta=False,
                      log=False):

        net = self.net
        sess = self.sess

        # put tensorboard inside
        top_cls_loss = net['top_cls_loss']
        top_reg_loss = net['top_reg_loss']
        fuse_cls_loss = net['fuse_cls_loss']
        fuse_reg_loss = net['fuse_reg_loss']

        self.batch_gt_top_boxes = data.box3d_to_top_box(batch_gt_boxes3d[0])

        ## run propsal generation
        fd1 = {
            net['top_view']: batch_top_view,
            net['top_anchors']: self.top_view_anchors,
            net['top_inside_inds']: self.anchors_inside_inds,
            blocks.IS_TRAIN_PHASE: True,
            K.learning_phase(): 1
        }
        self.batch_proposals, self.batch_proposal_scores, self.batch_top_features = \
            sess.run([net['proposals'], net['proposal_scores'], net['top_features']], fd1)

        ## generate  train rois  for RPN
        self.batch_top_inds, self.batch_top_pos_inds, self.batch_top_labels, self.batch_top_targets = \
            rpn_target(self.top_view_anchors, self.anchors_inside_inds, batch_gt_labels[0],
                       self.batch_gt_top_boxes)
        if log:
            step_name = 'validation' if is_validation else 'train'
            scope_name = '%s_iter_%06d' % (
                step_name, self.n_global_step -
                (self.n_global_step % self.iter_debug))
            self.log_rpn(step=self.n_global_step, scope_name=scope_name)


        self.batch_top_rois, self.batch_fuse_labels, self.batch_fuse_targets = \
            rcnn_target(self.batch_proposals, batch_gt_labels[0], self.batch_gt_top_boxes, batch_gt_boxes3d[0])

        self.batch_rois3d = project_to_roi3d(self.batch_top_rois)
        self.batch_front_rois = project_to_front_roi(self.batch_rois3d)
        self.batch_rgb_rois = project_to_rgb_roi(self.batch_rois3d)

        if log:
            self.log_fusion_net_target(batch_rgb_images[0],
                                       scope_name=scope_name)
        if log:
            log_info_str = 'frame info: ' + self.frame_info + '\n'
            log_info_str += self.anchors_details()
            log_info_str += self.rpn_poposal_details()
            self.log_info(self.log_subdir, log_info_str)

        ## run classification and regression loss -----------
        fd2 = {
            **fd1,
            net['top_view']: batch_top_view,
            net['front_view']: batch_front_view,
            net['rgb_images']: batch_rgb_images,
            net['top_rois']: self.batch_top_rois,
            net['front_rois']: self.batch_front_rois,
            net['rgb_rois']: self.batch_rgb_rois,
            net['top_inds']: self.batch_top_inds,
            net['top_pos_inds']: self.batch_top_pos_inds,
            net['top_labels']: self.batch_top_labels,
            net['top_targets']: self.batch_top_targets,
            net['fuse_labels']: self.batch_fuse_labels,
            net['fuse_targets']: self.batch_fuse_targets,
        }

        if self.debug_mode:
            print('\n\nstart debug mode\n\n')
            debug_sess = tf_debug.LocalCLIDebugWrapperSession(sess)
            t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss = \
                debug_sess.run([top_cls_loss, top_reg_loss, fuse_cls_loss, fuse_reg_loss], fd2)

        if summary_it:
            run_options = None
            run_metadata = None

            if is_validation:
                t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss, tb_sum_val = \
                    sess.run([top_cls_loss, top_reg_loss, fuse_cls_loss, fuse_reg_loss, self.summ], fd2)
                self.val_summary_writer.add_summary(tb_sum_val,
                                                    self.n_global_step)
                print('added validation  summary ')
            else:
                if summary_runmeta:
                    run_options = tf.RunOptions(
                        trace_level=tf.RunOptions.FULL_TRACE)
                    run_metadata = tf.RunMetadata()

                _, t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss, tb_sum_val = \
                    sess.run([self.solver_step, top_cls_loss, top_reg_loss, fuse_cls_loss, fuse_reg_loss,
                              self.summ], feed_dict=fd2, options=run_options, run_metadata=run_metadata)
                self.train_summary_writer.add_summary(tb_sum_val,
                                                      self.n_global_step)
                print('added training  summary ')

                if summary_runmeta:
                    self.train_summary_writer.add_run_metadata(
                        run_metadata, 'step%d' % self.n_global_step)
                    print('added runtime metadata.')

        else:
            if is_validation:
                t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss = \
                    sess.run([top_cls_loss, top_reg_loss, fuse_cls_loss, fuse_reg_loss], fd2)
            else:

                _, t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss = \
                    sess.run([self.solver_step, top_cls_loss, top_reg_loss, fuse_cls_loss, fuse_reg_loss],
                             feed_dict=fd2)
        if log:
            self.log_prediction(batch_top_view,
                                batch_front_view,
                                batch_rgb_images,
                                step=self.n_global_step,
                                scope_name=scope_name)

        return t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss
Exemplo n.º 6
0
    def fit_iteration(self,
                      is_validation=False,
                      summary_it=False,
                      summary_runmeta=False,
                      log_image=False,
                      summary_iou=False,
                      iou_statistic=False):

        data_set = self.validation_set if is_validation else self.train_set
        self.default_summary_writer = \
            self.val_summary_writer if is_validation else self.train_summary_writer

        self.step_name = 'validation' if is_validation else 'training'

        # load dataset
        self.batch_rgb_images, self.batch_top_view, self.batch_front_view, \
        self.batch_gt_labels, self.batch_gt_boxes3d, self.frame_id = \
            data_set.load()

        # fit_iterate log init
        if log_image:
            self.time_str = strftime("%Y_%m_%d_%H_%M", localtime())
            self.frame_info = data_set.get_frame_info()
            self.log_subdir = self.step_name + '/' + self.time_str
            self.top_image = data.draw_top_image(self.batch_top_view[0])
            # self.top_image = self.top_image_padding(top_image)

        net = self.net
        sess = self.sess

        # put tensorboard inside
        top_cls_loss = net['top_cls_loss']
        top_reg_loss = net['top_reg_loss']
        fuse_cls_loss = net['fuse_cls_loss']
        fuse_reg_loss = net['fuse_reg_loss']

        self.batch_gt_top_boxes = data.box3d_to_top_box(
            self.batch_gt_boxes3d[0])

        ## run propsal generation
        fd1 = {
            net['top_view']: self.batch_top_view,
            net['top_anchors']: self.top_view_anchors,
            net['top_inside_inds']: self.anchors_inside_inds,
            blocks.IS_TRAIN_PHASE: True,
            K.learning_phase(): 1
        }
        self.batch_proposals, self.batch_proposal_scores, self.batch_top_features = \
            sess.run([net['proposals'], net['proposal_scores'], net['top_features']], fd1)

        ## generate  train rois  for RPN
        self.batch_top_inds, self.batch_top_pos_inds, self.batch_top_labels, self.batch_top_targets = \
            rpn_target(self.top_view_anchors, self.anchors_inside_inds, self.batch_gt_labels[0],
                       self.batch_gt_top_boxes)

        self.batch_top_rois, self.batch_fuse_labels, self.batch_fuse_targets = \
            fusion_target(self.batch_proposals, self.batch_gt_labels[0],
                          self.batch_gt_top_boxes, self.batch_gt_boxes3d[0])

        self.batch_rois3d = project_to_roi3d(self.batch_top_rois)
        self.batch_front_rois = project_to_front_roi(self.batch_rois3d)
        self.batch_rgb_rois = project_to_rgb_roi(self.batch_rois3d)

        ## run classification and regression loss -----------
        fd2 = {
            **fd1,
            net['top_view']: self.batch_top_view,
            net['front_view']: self.batch_front_view,
            net['rgb_images']: self.batch_rgb_images,
            net['top_rois']: self.batch_top_rois,
            net['front_rois']: self.batch_front_rois,
            net['rgb_rois']: self.batch_rgb_rois,
            net['top_inds']: self.batch_top_inds,
            net['top_pos_inds']: self.batch_top_pos_inds,
            net['top_labels']: self.batch_top_labels,
            net['top_targets']: self.batch_top_targets,
            net['fuse_labels']: self.batch_fuse_labels,
            net['fuse_targets']: self.batch_fuse_targets,
        }

        if self.debug_mode:
            print('\n\nstart debug mode\n\n')
            debug_sess = tf_debug.LocalCLIDebugWrapperSession(sess)
            t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss = \
                debug_sess.run([top_cls_loss, top_reg_loss, fuse_cls_loss, fuse_reg_loss], fd2)

        if summary_it:
            run_options = None
            run_metadata = None

            if is_validation:
                t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss, tb_sum_val = \
                    sess.run([top_cls_loss, top_reg_loss, fuse_cls_loss, fuse_reg_loss, self.summ], fd2)

                self.val_summary_writer.add_summary(tb_sum_val,
                                                    self.n_global_step)
                # print('added validation  summary ')
            else:
                if summary_runmeta:
                    run_options = tf.RunOptions(
                        trace_level=tf.RunOptions.FULL_TRACE)
                    run_metadata = tf.RunMetadata()

                _, t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss, tb_sum_val = \
                    sess.run([self.solver_step, top_cls_loss, top_reg_loss, fuse_cls_loss, fuse_reg_loss,
                              self.summ], feed_dict=fd2, options=run_options, run_metadata=run_metadata)

                self.train_summary_writer.add_summary(tb_sum_val,
                                                      self.n_global_step)
                # print('added training  summary ')

                if summary_runmeta:
                    self.train_summary_writer.add_run_metadata(
                        run_metadata, 'step%d' % self.n_global_step)
                    # print('added runtime metadata.')

        else:
            if is_validation:
                t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss = \
                    sess.run([top_cls_loss, top_reg_loss, fuse_cls_loss, fuse_reg_loss], fd2)
            else:

                _, t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss = \
                    sess.run([self.solver_step, top_cls_loss, top_reg_loss, fuse_cls_loss, fuse_reg_loss],
                             feed_dict=fd2)

        if log_image:
            # t0 = time.time()
            step_name = 'validation' if is_validation else 'train'
            scope_name = '%s_iter_%06d' % (
                step_name, self.n_global_step -
                (self.n_global_step % self.iter_debug))

            boxes3d, lables = self.predict(self.batch_top_view,
                                           self.batch_front_view,
                                           self.batch_rgb_images)

            # get iou
            iou = -1
            inds = np.where(self.batch_gt_labels[0] != 0)
            try:
                iou = box.boxes3d_score_iou(self.batch_gt_boxes3d[0][inds],
                                            boxes3d)
                if iou_statistic: self.iou_store.append(iou)
                if summary_iou:
                    iou_aver = sum(self.iou_store) / len(self.iou_store)
                    self.iou_store = []
                    tag = os.path.join('IOU')
                    self.summary_scalar(value=iou_aver,
                                        tag=tag,
                                        step=self.n_global_step)
                    self.log_msg.write('\n %s iou average: %.5f\n' %
                                       (self.step_name, iou_aver))
            except ValueError:
                # print("waring :", sys.exc_info()[0])
                pass

            #set scope name
            if iou == -1:
                scope_name = os.path.join(scope_name,
                                          'iou_error'.format(range(5, 8)))
            else:
                for iou_range in self.log_iou_range:
                    if int(iou * 100) in iou_range:
                        scope_name = os.path.join(scope_name,
                                                  'iou_{}'.format(iou_range))

            # print('Summary log image, scope name: {}'.format(scope_name))

            self.log_fusion_net_target(self.batch_rgb_images[0],
                                       scope_name=scope_name)
            log_info_str = 'frame info: ' + self.frame_info + '\n'
            log_info_str += self.anchors_details()
            log_info_str += self.rpn_poposal_details()
            self.log_info(self.log_subdir, log_info_str)

            self.predict_log(self.log_subdir,
                             log_rpn=True,
                             step=self.n_global_step,
                             scope_name=scope_name,
                             loss=(f_cls_loss, f_reg_loss),
                             frame_tag=self.frame_id,
                             is_train_mode=True)

            # self.log_msg.write('Image log  summary use time : {}\n'.format(time.time() - t0))

        return t_cls_loss, t_reg_loss, f_cls_loss, f_reg_loss