def eval_one_epoch(sess, ops, pls, test_writer, more=False): TEST_DATASET = Dataset(NUM_POINT, NUM_CHANNEL, '/data/ssd/public/jlliu/Kitti/object', 'val', is_training=True) test_produce_thread = Thread(target=TEST_DATASET.load, args=(False, )) test_produce_thread.start() global EPOCH_CNT is_training = False #is_training = True log_string(str(datetime.now())) log_string('---- EPOCH %03d EVALUATION ----' % (EPOCH_CNT)) # To collect statistics total_correct = 0 total_seen = 0 total_tp = 0 total_fp = 0 total_fn = 0 loss_sum = 0 num_samples = 0 iou2ds_sum = 0 iou3ds_sum = 0 total_nms = 0 total_proposal_recall = 0 while (True): batch_data, is_last_batch = TEST_DATASET.get_next_batch(BATCH_SIZE) feed_dict = { pls['pointclouds']: batch_data['pointcloud'], pls['img_inputs']: batch_data['images'], pls['calib']: batch_data['calib'], pls['seg_labels']: batch_data['seg_label'], pls['center_bin_x_labels']: batch_data['center_x_cls'], pls['center_bin_z_labels']: batch_data['center_z_cls'], pls['center_x_residuals_labels']: batch_data['center_x_res'], pls['center_y_residuals_labels']: batch_data['center_y_res'], pls['center_z_residuals_labels']: batch_data['center_z_res'], pls['heading_bin_labels']: batch_data['angle_cls'], pls['heading_residuals_labels']: batch_data['angle_res'], pls['size_class_labels']: batch_data['size_cls'], pls['size_residuals_labels']: batch_data['size_res'], pls['gt_box_of_point']: batch_data['gt_box_of_point'], pls['img_seg_softmax']: np.zeros((BATCH_SIZE, NUM_POINT, NUM_SEG_CLASSES)), pls['is_training_pl']: is_training, } if more: summary, step, loss_val, logits_val, iou2ds, iou3ds, proposal_boxes, nms_indices \ = sess.run([ ops['merged'], ops['step'], ops['loss'], ops['end_points']['foreground_logits'], ops['end_points']['iou2ds'], ops['end_points']['iou3ds'], ops['end_points']['proposal_boxes'], ops['end_points']['nms_indices']], feed_dict=feed_dict) #feed_dict=feed_dict) iou2ds_sum += np.sum(iou2ds) iou3ds_sum += np.sum(iou3ds) total_nms += len(iou2ds) # average on each frame proposal_recall = train_util.compute_proposal_recall( proposal_boxes, batch_data['gt_boxes'], nms_indices) total_proposal_recall += proposal_recall * BATCH_SIZE else: summary, step, loss_val, logits_val = sess.run([ ops['merged'], ops['step'], ops['loss'], ops['end_points']['foreground_logits'] ], feed_dict=feed_dict) test_writer.add_summary(summary, step) # segmentation acc preds_val = np.argmax(logits_val, 2) correct = np.sum(preds_val == batch_data['seg_label']) tp = np.sum( np.logical_and(preds_val == batch_data['seg_label'], batch_data['seg_label'] != 0)) fp = np.sum( np.logical_and(preds_val != batch_data['seg_label'], batch_data['seg_label'] == 0)) fn = np.sum( np.logical_and(preds_val != batch_data['seg_label'], batch_data['seg_label'] != 0)) total_tp += tp total_fp += fp total_fn += fn total_correct += correct total_seen += NUM_POINT * BATCH_SIZE loss_sum += loss_val num_samples += BATCH_SIZE if is_last_batch: break log_string('eval mean loss: %f' % (loss_sum / float(num_samples))) log_string('eval segmentation accuracy: %f'% \ (total_correct / float(total_seen))) if total_tp + total_fn > 0 and total_tp + total_fp > 0: log_string('eval segmentation recall: %f'% \ (float(total_tp)/(total_tp+total_fn))) log_string('eval segmentation precision: %f'% \ (float(total_tp)/(total_tp+total_fp))) if more: log_string('eval box IoU (ground/3D): %f / %f' % \ (iou2ds_sum / float(total_nms), iou3ds_sum / float(total_nms))) log_string('eval proposal recall: %f' % (float(total_proposal_recall) / num_samples)) EPOCH_CNT += 1 TEST_DATASET.stop_loading() test_produce_thread.join() return loss_sum / float(num_samples)
def test(split, save_result=False): if save_result and not os.path.exists('./rcnn_data_' + split): os.mkdir('./rcnn_data_' + split) is_training = False #dataset = Dataset(NUM_POINT, '/data/ssd/public/jlliu/Kitti/object', split, is_training=is_training) dataset = Dataset(NUM_POINT, KITTI_PATH, split, is_training=is_training) # data loading threads produce_thread = Thread(target=dataset.load, args=(False, )) produce_thread.start() with tf.Graph().as_default(): with tf.device('/gpu:0'): rpn_model = RPN(BATCH_SIZE, NUM_POINT, num_channel=4, is_training=is_training) pls = rpn_model.placeholders end_points = rpn_model.end_points box_center, box_angle, box_size = rpn_model.box_encoder.tf_decode( end_points) box_center = box_center + end_points['fg_points_xyz'] #box_center = tf.reshape(box_center, [BATCH_SIZE * NUM_FG_POINT,3]) #box_angle = tf.reshape(box_angle, [BATCH_SIZE * NUM_FG_POINT]) #box_size = tf.reshape(box_size, [BATCH_SIZE * NUM_FG_POINT,3]) saver = tf.train.Saver() # Create a session config = tf.ConfigProto() config.gpu_options.allow_growth = True config.allow_soft_placement = True config.log_device_placement = False sess = tf.Session(config=config) saver.restore(sess, FLAGS.model_path) with tf.Graph().as_default(): with tf.device('/gpu:0'): #img_seg_net = ImgSegNet(BATCH_SIZE, NUM_POINT, num_channel=4, bn_decay=None, is_training=is_training) #seg_softmax = img_seg_net.get_seg_softmax() #saver1 = tf.train.Saver() img_seg_net = ImgSegNet(BATCH_SIZE, NUM_POINT) #img_seg_net.load_graph('/data/ssd/public/jlliu/models/research/deeplab/exp/frozen_inference_graph.pb') img_seg_net.load_graph(FLAGS.img_model_path) seg_softmax = img_seg_net.get_seg_softmax() full_seg = img_seg_net.get_semantic_seg() # Create another session config = tf.ConfigProto() config.gpu_options.allow_growth = True config.allow_soft_placement = True config.log_device_placement = False sess1 = tf.Session(config=config) #saver1.restore(sess1, FLAGS.img_model_path) log_string(str(datetime.now())) # To collect statistics total_correct = 0 total_seen = 0 num_batches = 0 tp = {'Car': 0, 'Pedestrian': 0, 'Cyclist': 0} fp = {'Car': 0, 'Pedestrian': 0, 'Cyclist': 0} fn = {'Car': 0, 'Pedestrian': 0, 'Cyclist': 0} proposal_boxes = [] gt_boxes = [] nms_indices = [] while (True): batch_data, is_last_batch = dataset.get_next_batch(BATCH_SIZE, need_id=True) start = datetime.now() feed_dict = { pls['pointclouds']: batch_data['pointcloud'], pls['img_inputs']: batch_data['images'], pls['calib']: batch_data['calib'], pls['seg_labels']: batch_data['seg_label'], pls['center_bin_x_labels']: batch_data['center_x_cls'], pls['center_bin_z_labels']: batch_data['center_z_cls'], pls['center_x_residuals_labels']: batch_data['center_x_res'], pls['center_y_residuals_labels']: batch_data['center_y_res'], pls['center_z_residuals_labels']: batch_data['center_z_res'], pls['heading_bin_labels']: batch_data['angle_cls'], pls['heading_residuals_labels']: batch_data['angle_res'], pls['size_class_labels']: batch_data['size_cls'], pls['size_residuals_labels']: batch_data['size_res'], pls['gt_box_of_point']: batch_data['gt_box_of_point'], pls['is_training_pl']: is_training, } # segmentaion with image seg_pls = img_seg_net.placeholders img_seg_logits, full_img_seg = sess1.run( [seg_softmax, full_seg], feed_dict={ seg_pls['pointclouds']: batch_data['pointcloud'], seg_pls['img_inputs']: batch_data['images'], seg_pls['calib']: batch_data['calib'], seg_pls['seg_labels']: batch_data['seg_label'], #seg_pls['is_training_pl']: is_training }) # convert to binary segmentation img_seg_binary = np.zeros((BATCH_SIZE, NUM_POINT, 2)) img_seg_binary[..., 0] = img_seg_logits[..., 0] img_seg_binary[..., 1] = np.sum(img_seg_logits[..., 1:], axis=-1) img_seg_binary *= np.array([0, 1]) # weights feed_dict[pls['img_seg_softmax']] = img_seg_binary ''' # label to one_hot targets = batch_data['seg_label'] img_seg_logits = np.eye(NUM_SEG_CLASSES)[targets] #img_seg_logits *= np.array([2, 2, 2, 2]) # weights feed_dict[pls['img_seg_softmax']] = img_seg_logits ''' logits_val, indices_val, centers_val, angles_val, sizes_val, corners_val, ind_val, scores_val \ = sess.run([ end_points['foreground_logits'], end_points['fg_point_indices'], box_center, box_angle, box_size, end_points['proposal_boxes'], end_points['nms_indices'], end_points['proposal_scores']], feed_dict=feed_dict) print('inference time: ', datetime.now() - start) # segmentation acc preds_val = np.argmax(logits_val, 2) num_batches += 1 for c in ['Car', 'Pedestrian', 'Cyclist']: one_hot_class = g_type2onehotclass[c] tp[c] += np.sum( np.logical_and(preds_val == batch_data['seg_label'], batch_data['seg_label'] == one_hot_class)) fp[c] += np.sum( np.logical_and(preds_val != batch_data['seg_label'], batch_data['seg_label'] != one_hot_class)) fn[c] += np.sum( np.logical_and(preds_val != batch_data['seg_label'], batch_data['seg_label'] == one_hot_class)) # results for i in range(BATCH_SIZE): proposal_boxes.append(corners_val[i]) gt_boxes.append(batch_data['gt_boxes'][i]) nms_indices.append(ind_val[i]) frame_data = { 'frame_id': batch_data['ids'][i], 'segmentation': preds_val[i], 'centers': centers_val[i], 'angles': angles_val[i], 'sizes': sizes_val[i], 'proposal_boxes': corners_val[i], 'nms_indices': ind_val[i], 'scores': scores_val[i], 'pc_choices': batch_data['pc_choice'][i] } # save frame data if save_result: with open( os.path.join('./rcnn_data_' + split, batch_data['ids'][i] + '.pkl'), 'wb') as fout: pickle.dump(frame_data, fout) np.save( os.path.join('./rcnn_data_' + split, batch_data['ids'][i] + '_seg.npy'), full_img_seg[i]) if is_last_batch: break log_string('saved prediction') dataset.stop_loading() produce_thread.join() ''' all_indices = np.tile(np.arange(1024), (len(proposal_boxes),)) iou2d, iou3d = compute_box3d_iou(proposal_boxes, point_gt_boxes, all_indices) print('IOU2d: ', np.mean(iou2d)) print('IOU3d: ', np.mean(iou3d)) ''' if split in ['train', 'val']: recall = compute_proposal_recall(proposal_boxes, gt_boxes, nms_indices) print('Average recall: ', recall) print(tp, fp, fn) for c in ['Car', 'Pedestrian', 'Cyclist']: if (tp[c] + fn[c] == 0) or (tp[c] + fp[c]) == 0: continue print(c + ' segmentation recall: %f'% \ (float(tp[c])/(tp[c]+fn[c]))) print(c + ' segmentation precision: %f'% \ (float(tp[c])/(tp[c]+fp[c])))
def eval_one_epoch(sess, ops, pls, test_writer): TEST_DATASET = Dataset(NUM_POINT, '/data/ssd/public/jlliu/Kitti/object', 'val', is_training=True, train_img_seg=True) test_produce_thread = Thread(target=TEST_DATASET.load, args=(False,)) test_produce_thread.start() global EPOCH_CNT is_training = False #is_training = True log_string(str(datetime.now())) log_string('---- EPOCH %03d EVALUATION ----'%(EPOCH_CNT)) # To collect statistics total_correct = 0 total_seen = 0 total_tp = 0 total_fp = 0 total_fn = 0 tp = {'Car': 0, 'Pedestrian': 0, 'Cyclist': 0} fp = {'Car': 0, 'Pedestrian': 0, 'Cyclist': 0} fn = {'Car': 0, 'Pedestrian': 0, 'Cyclist': 0} loss_sum = 0 num_samples = 0 while(True): batch_data, is_last_batch = TEST_DATASET.get_next_batch(BATCH_SIZE) feed_dict = { pls['pointclouds']: batch_data['pointcloud'], pls['img_inputs']: batch_data['images'], pls['calib']: batch_data['calib'], pls['seg_labels']: batch_data['seg_label'], pls['is_training_pl']: is_training } summary, step, loss_val, logits_val = sess.run([ ops['merged'], ops['step'], ops['loss'], ops['end_points']['foreground_logits']], feed_dict=feed_dict) test_writer.add_summary(summary, step) # segmentation acc preds_val = np.argmax(logits_val, 2) correct = np.sum(preds_val == batch_data['seg_label']) for c in ['Car', 'Pedestrian', 'Cyclist']: one_hot_class = g_type2onehotclass[c] tp[c] += np.sum(np.logical_and(preds_val == batch_data['seg_label'], batch_data['seg_label'] == one_hot_class)) fp[c] += np.sum(np.logical_and(preds_val != batch_data['seg_label'], batch_data['seg_label'] != one_hot_class)) fn[c] += np.sum(np.logical_and(preds_val != batch_data['seg_label'], batch_data['seg_label'] == one_hot_class)) total_tp += np.sum(np.logical_and(preds_val == batch_data['seg_label'], batch_data['seg_label'] != 0)) total_fp += np.sum(np.logical_and(preds_val != batch_data['seg_label'], batch_data['seg_label'] == 0)) total_fn += np.sum(np.logical_and(preds_val != batch_data['seg_label'], batch_data['seg_label'] != 0)) total_correct += correct total_seen += NUM_POINT * BATCH_SIZE loss_sum += loss_val num_samples += BATCH_SIZE if is_last_batch: break log_string('eval mean loss: %f' % (loss_sum / float(num_samples))) log_string('eval segmentation accuracy: %f'% \ (total_correct / float(total_seen))) if total_tp+total_fn > 0 and total_tp+total_fp > 0: log_string('eval segmentation recall: %f'% \ (float(total_tp)/(total_tp+total_fn))) log_string('eval segmentation precision: %f'% \ (float(total_tp)/(total_tp+total_fp))) for c in ['Car', 'Pedestrian', 'Cyclist']: if (tp[c]+fn[c] == 0) or (tp[c]+fp[c]) == 0: continue log_string(c + 'eval segmentation recall: %f'% \ (float(tp[c])/(tp[c]+fn[c]))) log_string(c + 'eval segmentation precision: %f'% \ (float(tp[c])/(tp[c]+fp[c]))) EPOCH_CNT += 1 TEST_DATASET.stop_loading() test_produce_thread.join() return loss_sum / float(num_samples)
return learning_rate def get_bn_decay(batch): bn_momentum = tf.train.exponential_decay(BN_INIT_DECAY, batch * BATCH_SIZE, BN_DECAY_DECAY_STEP, BN_DECAY_DECAY_RATE, staircase=True) bn_decay = tf.minimum(BN_DECAY_CLIP, 1 - bn_momentum) return bn_decay TRAIN_DATASET = Dataset(NUM_POINT, NUM_CHANNEL, '/data/ssd/public/jlliu/Kitti/object', 'train', is_training=True, use_aug_scene=True) # data loading threads train_produce_thread = Thread(target=TRAIN_DATASET.load, args=(True, )) train_produce_thread.start() def train(): ''' Main function for training and simple evaluation. ''' with tf.Graph().as_default(): with tf.device('/gpu:0'): # is_training_pl = tf.placeholder(tf.bool, shape=()) # Note the global_step=batch parameter to minimize.
staircase=True) learing_rate = tf.maximum(learning_rate, 0.00001) # CLIP THE LEARNING RATE! return learning_rate def get_bn_decay(batch): bn_momentum = tf.train.exponential_decay( BN_INIT_DECAY, batch*BATCH_SIZE, BN_DECAY_DECAY_STEP, BN_DECAY_DECAY_RATE, staircase=True) bn_decay = tf.minimum(BN_DECAY_CLIP, 1 - bn_momentum) return bn_decay TRAIN_DATASET = Dataset(NUM_POINT, '/data/ssd/public/jlliu/Kitti/object', 'train', is_training=True, train_img_seg=True) # data loading threads # FIXME: don't use data augmentation with image feature before calib matrix is adjust accordingly train_produce_thread = Thread(target=TRAIN_DATASET.load, args=(True,)) train_produce_thread.start() def train(): ''' Main function for training and simple evaluation. ''' with tf.Graph().as_default(): with tf.device('/gpu:0'): # is_training_pl = tf.placeholder(tf.bool, shape=()) # Note the global_step=batch parameter to minimize. # That tells the optimizer to increment the 'batch' parameter # for you every time it trains.
BATCH_SIZE = 1 NUM_POINT = 16384 with tf.Graph().as_default() as graph: with tf.device('/gpu:0'): seg_net = ImgSegNet(BATCH_SIZE, NUM_POINT) seg_net.load_graph(sys.argv[1]) pts_softmax = seg_net.get_seg_softmax() semantic_seg = seg_net.get_semantic_seg() feat_map = seg_net.get_feature_map() config = tf.ConfigProto() config.gpu_options.allow_growth = True config.allow_soft_placement = True config.log_device_placement = False sess = tf.Session(config=config) TEST_DATASET = Dataset(NUM_POINT, '/data/ssd/public/jlliu/Kitti/object', 'val', is_training=True) #TEST_DATASET = Dataset(NUM_POINT, '/data/ssd/public/jlliu/Kitti/object', 'train', is_training=True) test_produce_thread = Thread(target=TEST_DATASET.load, args=(False, )) test_produce_thread.start() pls = seg_net.placeholders n = 0 total_seen = 0 tp = {'Car': 0, 'Pedestrian': 0, 'Cyclist': 0} fp = {'Car': 0, 'Pedestrian': 0, 'Cyclist': 0} fn = {'Car': 0, 'Pedestrian': 0, 'Cyclist': 0} g_type2onehotclass = { 'NonObject': 0, 'Car': 1, 'Pedestrian': 2,
parser.add_argument('--save_img_seg', action='store_true', help='If true, also save image segmentation result') FLAGS = parser.parse_args() # only batch_size=1 is supported now BATCH_SIZE = 1 BATCH_SIZE_RCNN = 32 GPU_INDEX = FLAGS.gpu NUM_POINT = FLAGS.num_point NUM_POINT_RCNN = 512 NUM_CHANNEL = 4 RPN_DATASET = Dataset(NUM_POINT, NUM_CHANNEL, FLAGS.kitti_path, FLAGS.split, is_training=False, use_aug_scene=False) RCNN_DATASET = FrustumDataset(NUM_POINT_RCNN, FLAGS.kitti_path, BATCH_SIZE_RCNN, FLAGS.split, data_dir='./rcnn_data_' + FLAGS.split, augmentX=1, random_shift=False, rotate_to_center=True, random_flip=False, use_gt_prop=False) def print_flush(s):
def test(split): is_training = False #dataset = Dataset(NUM_POINT, '/data/ssd/public/jlliu/Kitti/object', split, is_training=is_training) dataset = Dataset(NUM_POINT, KITTI_PATH, split, is_training=True) # data loading threads produce_thread = Thread(target=dataset.load, args=(False, )) produce_thread.start() with tf.Graph().as_default(): with tf.device('/gpu:0'): rpn_model = RPN(BATCH_SIZE, NUM_POINT, num_channel=4, is_training=is_training) pls = rpn_model.placeholders end_points = rpn_model.end_points box_center, box_angle, box_size = rpn_model.box_encoder.tf_decode( end_points) box_center = box_center + end_points['fg_points_xyz'] #box_center = tf.reshape(box_center, [BATCH_SIZE * NUM_FG_POINT,3]) #box_angle = tf.reshape(box_angle, [BATCH_SIZE * NUM_FG_POINT]) #box_size = tf.reshape(box_size, [BATCH_SIZE * NUM_FG_POINT,3]) saver = tf.train.Saver() # Create a session config = tf.ConfigProto() config.gpu_options.allow_growth = True config.allow_soft_placement = True config.log_device_placement = False sess = tf.Session(config=config) saver.restore(sess, FLAGS.model_path) with tf.Graph().as_default(): with tf.device('/gpu:0'): img_seg_net = ImgSegNet(BATCH_SIZE, NUM_POINT, num_channel=4, bn_decay=None, is_training=is_training) seg_softmax = img_seg_net.get_seg_softmax() #seg_net = ImgSegNet(BATCH_SIZE, NUM_POINT) #seg_net.load_graph('./frozen_inference_graph.pb') #seg_softmax = seg_net.get_seg_softmax() saver1 = tf.train.Saver() # Create another session config = tf.ConfigProto() config.gpu_options.allow_growth = True config.allow_soft_placement = True config.log_device_placement = False sess1 = tf.Session(config=config) saver1.restore(sess1, './log_img/model.ckpt') log_string(str(datetime.now())) # To collect statistics total_correct = 0 total_seen = 0 num_batches = 0 tp = {'Car': 0, 'Pedestrian': 0, 'Cyclist': 0} fp = {'Car': 0, 'Pedestrian': 0, 'Cyclist': 0} fn = {'Car': 0, 'Pedestrian': 0, 'Cyclist': 0} frame_ids = [] fg_indices = [] centers = [] angles = [] sizes = [] proposal_boxes = [] gt_boxes = [] nms_indices = [] scores = [] segmentation = [] # point segmentation pc_choices = [] # point sampling indices while (True): batch_data, is_last_batch = dataset.get_next_batch(BATCH_SIZE, need_id=True) start = datetime.now() feed_dict = { pls['pointclouds']: batch_data['pointcloud'], pls['img_inputs']: batch_data['images'], pls['calib']: batch_data['calib'], pls['seg_labels']: batch_data['seg_label'], pls['center_bin_x_labels']: batch_data['center_x_cls'], pls['center_bin_z_labels']: batch_data['center_z_cls'], pls['center_x_residuals_labels']: batch_data['center_x_res'], pls['center_y_residuals_labels']: batch_data['center_y_res'], pls['center_z_residuals_labels']: batch_data['center_z_res'], pls['heading_bin_labels']: batch_data['angle_cls'], pls['heading_residuals_labels']: batch_data['angle_res'], pls['size_class_labels']: batch_data['size_cls'], pls['size_residuals_labels']: batch_data['size_res'], pls['gt_box_of_point']: batch_data['gt_box_of_point'], pls['is_training_pl']: is_training, } # segmentaion with image seg_pls = img_seg_net.placeholders img_seg_logits = sess1.run(seg_softmax, feed_dict={ seg_pls['pointclouds']: batch_data['pointcloud'], seg_pls['img_inputs']: batch_data['images'], seg_pls['calib']: batch_data['calib'], seg_pls['seg_labels']: batch_data['seg_label'], seg_pls['is_training_pl']: is_training }) img_seg_logits *= np.array([0, 1]) # weights feed_dict[pls['img_seg_softmax']] = img_seg_logits ''' # label to one_hot targets = batch_data['seg_label'] img_seg_logits = np.eye(NUM_SEG_CLASSES)[targets] #img_seg_logits *= np.array([2, 2, 2, 2]) # weights feed_dict[pls['img_seg_softmax']] = img_seg_logits ''' logits_val, indices_val, centers_val, angles_val, sizes_val, corners_val, ind_val, scores_val \ = sess.run([ end_points['foreground_logits'], end_points['fg_point_indices'], box_center, box_angle, box_size, end_points['proposal_boxes'], end_points['nms_indices'], end_points['proposal_scores']], feed_dict=feed_dict) print('inference time: ', datetime.now() - start) # segmentation acc preds_val = np.argmax(logits_val, 2) num_batches += 1 for c in ['Car', 'Pedestrian', 'Cyclist']: one_hot_class = g_type2onehotclass[c] tp[c] += np.sum( np.logical_and(preds_val == batch_data['seg_label'], batch_data['seg_label'] == one_hot_class)) fp[c] += np.sum( np.logical_and(preds_val != batch_data['seg_label'], batch_data['seg_label'] != one_hot_class)) fn[c] += np.sum( np.logical_and(preds_val != batch_data['seg_label'], batch_data['seg_label'] == one_hot_class)) # results for i in range(BATCH_SIZE): frame_ids.append(batch_data['ids'][i]) segmentation.append(preds_val[i]) centers.append(centers_val[i]) angles.append(angles_val[i]) sizes.append(sizes_val[i]) proposal_boxes.append(corners_val[i]) nms_indices.append(ind_val[i]) scores.append(scores_val[i]) gt_boxes.append(batch_data['gt_boxes'][i]) pc_choices.append(batch_data['pc_choice'][i]) if is_last_batch: #if num_batches >= 500: break ''' with open('rpn_out_{0}.pkl'.format(split),'wb') as fout: pickle.dump(frame_ids, fout) pickle.dump(segmentation, fout) pickle.dump(centers, fout) pickle.dump(angles, fout) pickle.dump(sizes, fout) pickle.dump(proposal_boxes, fout) pickle.dump(nms_indices, fout) pickle.dump(scores, fout) # pickle.dump(gt_boxes, fout) pickle.dump(pc_choices, fout) log_string('saved prediction') ''' dataset.stop_loading() produce_thread.join() ''' all_indices = np.tile(np.arange(1024), (len(proposal_boxes),)) iou2d, iou3d = compute_box3d_iou(proposal_boxes, point_gt_boxes, all_indices) print('IOU2d: ', np.mean(iou2d)) print('IOU3d: ', np.mean(iou3d)) ''' recall = compute_proposal_recall(proposal_boxes, gt_boxes, nms_indices) print('Average recall: ', recall) print(tp, fp, fn) for c in ['Car', 'Pedestrian', 'Cyclist']: if (tp[c] + fn[c] == 0) or (tp[c] + fp[c]) == 0: continue print(c + ' segmentation recall: %f'% \ (float(tp[c])/(tp[c]+fn[c]))) print(c + ' segmentation precision: %f'% \ (float(tp[c])/(tp[c]+fp[c])))
parser.add_argument('--img_seg_model', type=str, default='./frozen_inference_graph.pb', help='image segmentation model path') parser.add_argument('--rcnn_model', type=str, default='log_rcnn/model.ckpt', help='rcnn model checkpoint file path [default: log/model.ckpt]') parser.add_argument('--output', type=str, default='test_results', help='output file/folder name [default: test_results]') parser.add_argument('--kitti_path', type=str, default='/data/ssd/public/jlliu/Kitti/object', help='Kitti root path') parser.add_argument('--split', type=str, default='test', help='Data split to use [default: test]') parser.add_argument('--dump_result', action='store_true', help='If true, also dump results to .pickle file') FLAGS = parser.parse_args() # only batch_size=1 is supported now BATCH_SIZE = 1 BATCH_SIZE_RCNN = 32 GPU_INDEX = FLAGS.gpu NUM_POINT = FLAGS.num_point NUM_POINT_RCNN = 512 RPN_DATASET = Dataset(NUM_POINT, FLAGS.kitti_path, FLAGS.split, is_training=False) RCNN_DATASET = FrustumDataset(NUM_POINT_RCNN, FLAGS.kitti_path, BATCH_SIZE_RCNN, FLAGS.split, data_dir='./rcnn_data_'+FLAGS.split, augmentX=1, random_shift=False, rotate_to_center=True, random_flip=False, use_gt_prop=False) def print_flush(s): print(s) sys.stdout.flush() def get_session_and_models(): ''' Define model graph, load model parameters, create session and return session handle and tensors ''' config = tf.ConfigProto() config.gpu_options.allow_growth = True config.allow_soft_placement = True