def __init__(self, info_path, root_path, class_names, num_point_features, target_assigner, feature_map_size, prep_func): #with open(info_path, 'rb') as f: # infos = pickle.load(f) self._root_path = root_path self.argoverse_loader = ArgoverseTrackingLoader(root_path) self.am = ArgoverseMap() self.inform = info_path self._num_point_features = num_point_features self.class_names = class_names #print("remain number of infos:", len(self._kitti_infos)) # generate anchors cache # [352, 400] ret = target_assigner.generate_anchors(feature_map_size) anchors = ret["anchors"] anchors = anchors.reshape([-1, 7]) matched_thresholds = ret["matched_thresholds"] unmatched_thresholds = ret["unmatched_thresholds"] anchors_bv = box_np_ops.rbbox2d_to_near_bbox(anchors[:, [0, 1, 3, 4, 6]]) anchor_cache = { "anchors": anchors, "anchors_bv": anchors_bv, "matched_thresholds": matched_thresholds, "unmatched_thresholds": unmatched_thresholds, } self._prep_func = partial(prep_func, anchor_cache=anchor_cache)
def __init__(self, root_dir, split='train'): self.split = split is_test = (self.split == 'test') self.lidar_pathlist = [] self.label_pathlist = [] self.lidar_dir = os.path.join(root_dir) data_loader = ArgoverseTrackingLoader(os.path.join(root_dir)) self.lidar_pathlist.extend(data_loader.lidar_list) self.label_pathlist.extend(data_loader.label_list) #self.calib_file = data_loader.calib_filename self.lidar_filename = [x.split('.')[0].rsplit('/',1)[1] for x in self.lidar_pathlist] assert len(self.lidar_pathlist) == len(self.label_pathlist) self.num_sample = len(self.lidar_pathlist) self.lidar_idx_list = ['%06d'%l for l in range(self.num_sample)] self.lidar_idx_table = dict(zip(self.lidar_idx_list, self.lidar_filename)) self.argo_to_kitti = np.array([[0, -1, 0], [0, 0, -1], [1, 0, 0 ]]) self.ground_removal = False self.lidar_dir = os.path.join('/data/') self.label_dir = os.path.join('/data/')
def main(data_path): # avm = ArgoverseMap() # argoverse_tracker_loader = ArgoverseTrackingLoader('argoverse-tracking/') #simply change to your local path of the data # argoverse_forecasting_loader = ArgoverseForecastingLoader('argoverse-forecasting/') # argoVerseDataset = ArgoVerseDataset() # argoVerseDataset.readCameraParameters() argoverse_tracker_loader = ArgoverseTrackingLoader(data_path) camera1_name = 'ring_front_center' camera2_name = 'ring_front_right' camera3_name = 'ring_front_left' camera1_images = argoverse_tracker_loader.image_list[camera1_name] camera2_images = argoverse_tracker_loader.image_list[camera2_name] camera3_images = argoverse_tracker_loader.image_list[camera3_name] camera1_calib = argoverse_tracker_loader.calib[camera1_name] camera2_calib = argoverse_tracker_loader.calib[camera2_name] camera3_calib = argoverse_tracker_loader.calib[camera3_name] cv2.namedWindow('img1', cv2.WINDOW_NORMAL) cv2.resizeWindow('img1', 600,400) cv2.namedWindow('img2', cv2.WINDOW_NORMAL) cv2.resizeWindow('img2', 600,400) cv2.namedWindow('img3', cv2.WINDOW_NORMAL) cv2.resizeWindow('img3', 600,400) cv2.namedWindow('Stiched Img', cv2.WINDOW_NORMAL) cv2.resizeWindow('Stiched Img', 1200,800) for i in range(len(camera1_images)): im1 = cv2.imread(camera1_images[i]) im2 = cv2.imread(camera2_images[i]) im3 = cv2.imread(camera3_images[i]) #Merge Imgs into single sticker = cv2.Stitcher_create() status, stichedImg = sticker.stitch([im1, im2, im3]) # cv2.imshow('img2', im2) # cv2.waitKey() if status == 0: cv2.imshow('Stiched Img', stichedImg) cv2.imshow('img1', im1) cv2.imshow('img2', im2) cv2.imshow('img3', im3) # cv2.waitKey() if cv2.waitKey(1) & 0xFF == ord('q'): break
def build_argoverse_datasets(config): print('==> Loading Argoverse dataset...') dataroot = os.path.expandvars(config.dataroot) # Load native argoverse splits loaders = { 'train': ArgoverseTrackingLoader(os.path.join(dataroot, 'train')), 'val': ArgoverseTrackingLoader(os.path.join(dataroot, 'val')) } # Create datasets using new argoverse splits train_data = ArgoverseMapDataset(loaders, config.label_root, config.img_size, TRAIN_LOGS) val_data = ArgoverseMapDataset(loaders, config.label_root, config.img_size, VAL_LOGS) return train_data, val_data
def __init__(self, split, cfg, phase, transform=None, random_rotation=True, random_scale=True, manual_seed=False, config=None): #super().__init__(split, cfg, ) self.phase = phase self.files = [] self.data_objects = [] self.transform = transform self.voxel_size = config.voxel_size self.matching_search_voxel_size = \ config.voxel_size * config.positive_pair_search_voxel_size_multiplier self.random_scale = random_scale self.min_scale = config.min_scale self.max_scale = config.max_scale self.random_rotation = random_rotation self.rotation_range = config.rotation_range self.randg = np.random.RandomState() if manual_seed: self.reset_seed() self.root = root = os.path.join(cfg.path_dataset, 'dataset') self.split = phase self.cfg = cfg self.path_map_dict = os.path.join( root, "argo_map_files_d3feat_%s_fcgf.pkl" % self.split) # self.read_map_data() # self.prepare_kitti_ply()#split=split) from argoverse.data_loading.argoverse_tracking_loader import ArgoverseTrackingLoader self.name = "argoverse_tracking" self.cfg = cfg self.split = split self.transform_map = True if split == "train": self.list_id_log = np.load(os.path.join( self.cfg.path_dataset, 'argoverse-tracking', 'train_ids.npy')) list_folders = ["train1", "train2", "train3", "train4"] elif split == "test": self.list_id_log = np.load(os.path.join( self.cfg.path_dataset, 'argoverse-tracking', 'test_ids.npy')) list_folders = ["test"] self.dict_tracking_data_loader = {} for name_folder in list_folders: self.dict_tracking_data_loader[name_folder] = ArgoverseTrackingLoader( os.path.join(self.cfg.path_dataset, 'argoverse-tracking', name_folder)) self.transform_map = False self.read_data()
def process_split(split, map_data, config): # Create an Argoverse loader instance path = os.path.join(os.path.expandvars(config.argoverse.root), split) print("Loading Argoverse tracking data at " + path) loader = ArgoverseTrackingLoader(path) for scene in loader: process_scene(split, scene, map_data, config)
def __init__(self, root_path, subsets: list): super().__init__() self.root_path = root_path self.atls = { subset: ArgoverseTrackingLoader(Path(self.root_path) / subset) for subset in subsets } self._len = 0 pass
def __init__(self, root_dir, split='train'): self.split = split is_test = (self.split == 'test') self.lidar_pathlist = [] self.label_pathlist = [] if split == 'train': for i in np.arange(1, 5): self.imageset_dir = os.path.join(root_dir, split + str(i)) data_loader = ArgoverseTrackingLoader( os.path.join(root_dir, split + str(i))) self.log_list = data_loader.log_list for log in self.log_list: self.lidar_pathlist.extend(data_loader.get(log).lidar_list) self.label_pathlist.extend(data_loader.get(log).label_list) print(len(self.lidar_pathlist)) else: self.imageset_dir = os.path.join(root_dir, split) data_loader = ArgoverseTrackingLoader(os.path.join( root_dir, split)) self.lidar_pathlist.extend(data_loader.lidar_list) self.label_pathlist.extend(data_loader.label_list) self.calib_file = data_loader.calib_filename assert len(self.lidar_pathlist) == len(self.label_pathlist) #z = list(zip(self.lidar_pathlist, self.label_pathlist)) #random.shuffle(z) #self.lidar_pathlist[:], self.label_pathlist[:] = zip(*z) self.num_sample = len(self.lidar_pathlist) self.image_idx_list = np.arange(self.num_sample) self.argo_to_kitti = np.array( [[6.927964e-03, -9.999722e-01, -2.757829e-03], [-1.162982e-03, 2.749836e-03, -9.999955e-01], [9.999753e-01, 6.931141e-03, -1.143899e-03]]) self.ground_removal = True self.image_dir = os.path.join('/data/') self.lidar_dir = os.path.join('/data/') self.calib_dir = os.path.join('/data/') self.label_dir = os.path.join('/data/')
def __init__(self, split, cfg, config_d3feat, root, transform=None, random_rotation=True, random_scale=True, manual_seed=False, config=None, input_threads=8, first_subsampling_dl=0.30): #super().__init__(split, cfg, ) self.network_model = 'descriptor' self.num_threads = input_threads self.root = root self.icp_path = "data" # 'data/kitti/icp' self.voxel_size = first_subsampling_dl self.matching_search_voxel_size = first_subsampling_dl * 0.5 # 1.5 self.split = split # Initiate containers #self.anc_points = {'train': [], 'val': [], 'test': []} #self.files = {'train': [], 'val': [], 'test': []} self.config = config_d3feat self.path_map_dict = os.path.join( root, "argo_map_files_d3feat_%s.pkl" % self.split) # to match the dataset file used in the benchmark from argoverse.data_loading.argoverse_tracking_loader import ArgoverseTrackingLoader self.name = "argoverse_tracking" self.cfg = cfg #self.split = split self.transform_map = True if split == "train": self.list_id_log = np.load(os.path.join( self.cfg.path_dataset, 'argoverse-tracking', 'train_ids.npy')) list_folders = ["train1", "train2", "train3", "train4"] elif split == "test": self.list_id_log = np.load(os.path.join( self.cfg.path_dataset, 'argoverse-tracking', 'test_ids.npy')) list_folders = ["test"] self.dict_tracking_data_loader = {} for name_folder in list_folders: self.dict_tracking_data_loader[name_folder] = ArgoverseTrackingLoader( os.path.join(self.cfg.path_dataset, 'argoverse-tracking', name_folder)) #self.root = root = os.path.join(cfg.path_dataset, 'dataset') # self.read_map_data() # self.prepare_kitti_ply()#split=split) self.transform_map=False self.read_data()
def extract_datapoints(root_dir, test_set=False): argoverse_loader = ArgoverseTrackingLoader(root_dir=root_dir) data = [] for log_id in argoverse_loader.log_list: # print(f"Processing log: {os.path.join(root_dir, log_id)}", end="\r") argoverse_data = argoverse_loader.get(log_id=log_id) # calibL = argoverse_data.get_calibration(camera=camL, log_id=log_id) # calibR = argoverse_data.get_calibration(camera=camR, log_id=log_id) calibs = {} for cam in STEREO_CAMERA_LIST + RING_CAMERA_LIST: calibs[cam] = argoverse_data.get_calibration(camera=cam, log_id=log_id) count = 0 for lidar_timestamp in argoverse_data.lidar_timestamp_list: data_point = dict() data_point["log_id"] = log_id data_point["frame_id"] = count count += 1 for cam in STEREO_CAMERA_LIST + RING_CAMERA_LIST: cam_timestamp = argoverse_loader.sync.get_closest_cam_channel_timestamp( lidar_timestamp=lidar_timestamp, camera_name=cam, log_id=log_id) if cam_timestamp is not None: data_point[cam] = argoverse_loader.get_image_at_timestamp( timestamp=cam_timestamp, camera=cam, log_id=log_id, load=False) else: data_point[cam] = None data_point["timestamp"] = lidar_timestamp data_point["lidar"] = argoverse_loader.timestamp_lidar_dict[ lidar_timestamp] data_point["calibs"] = calibs d = argoverse_data.get_pose( argoverse_data.get_idx_from_timestamp( lidar_timestamp)).translation r = Rotation.from_dcm( argoverse_data.get_pose( argoverse_data.get_idx_from_timestamp( lidar_timestamp)).rotation) data_point["pose"] = (d, r.as_euler('xyz')) if not test_set: data_point["labels"] = argoverse_loader.get_label_object( idx=argoverse_loader.lidar_timestamp_list.index( lidar_timestamp), log_id=log_id) data.append(data_point) return data
def __init__(self, data_path, filenames, height, width, frame_idxs, num_scales, is_train=False, img_ext='.jpg'): super(Argo_MonoDataset, self).__init__() self.data_path = data_path self.filenames = filenames self.height = height #2056 self.width = width #2464 self.num_scales = num_scales self.interp = Image.ANTIALIAS self.frame_idxs = frame_idxs self.is_train = is_train self.img_ext = img_ext self.loader = argoverse_load_image self.argoverse_loader = ArgoverseTrackingLoader(self.data_path) self.camera = self.argoverse_loader.CAMERA_LIST[0] self.argoverse_data = 0 self.to_tensor = transforms.ToTensor() # We need to specify augmentations differently in newer versions of torchvision. # We first try the newer tuple version; if this fails we fall back to scalars try: self.brightness = (0.8, 1.2) self.contrast = (0.8, 1.2) self.saturation = (0.8, 1.2) self.hue = (-0.1, 0.1) transforms.ColorJitter.get_params(self.brightness, self.contrast, self.saturation, self.hue) except TypeError: self.brightness = 0.2 self.contrast = 0.2 self.saturation = 0.2 self.hue = 0.1 self.resize = {} for i in range(self.num_scales): s = 2**i self.resize[i] = transforms.Resize( (self.height // s, self.width // s), interpolation=self.interp) self.load_depth = self.check_depth()
def __init__(self, dataset_path, out_path, version='sample'): assert version in ['train', 'val', 'test', 'sample'] self.is_test = 'test' in version self.out_path = out_path self.dataset_path = join(dataset_path, version) self.argo = ArgoverseTrackingLoader(self.dataset_path) print(f"Total number of logs : {len(self.argo)}, version : {version}") self.version = version
def __init__(self, args, transform=None): self.args = args self.transform = transform self.argoverse_loader = ArgoverseTrackingLoader(args.root_dir) self.image_list = [] for log_id in self.argoverse_loader.log_list: argoverse_data = self.argoverse_loader.get(log_id) for idx in range( len(argoverse_data.image_list_sync['ring_front_center'])): self.image_list.append(str(log_id) + '@' + str(idx)) self.camera_name = [ 'ring_front_center', 'ring_side_left', 'ring_side_right', 'ring_front_left', 'ring_front_right', 'ring_rear_right', 'ring_rear_left' ]
def __init__(self, args): # Setup Argoverse loader self.dataset_dir = args.dataset_dir self.log_id = args.log_id self.argoverse_loader = ArgoverseTrackingLoader(self.dataset_dir) self.argoverse_data = self.argoverse_loader.get(self.log_id) print(self.argoverse_data) # List of cameras to publish self.cameras_list = [camera for camera in self.argoverse_loader.CAMERA_LIST if camera in args.cameras] self.load_camera_info() # Images timestamps self.image_files_dict = { camera: self.argoverse_data.timestamp_image_dict[camera] for camera in self.cameras_list} self.image_timestamps = { camera: list(self.image_files_dict[camera].keys()) for camera in self.cameras_list} # Save image files dict to be added into the bag file later using Python2 with open('/tmp/image_data_%s.json' % self.log_id, 'w') as f: data = {'image_files_dict': self.image_files_dict, 'image_timestamps': self.image_timestamps, 'cameras_list': self.cameras_list} json.dump(data, f, indent=4) # LiDAR timestamps self.lidar_files_dict = self.argoverse_data.timestamp_lidar_dict self.lidar_timestamps = list(self.lidar_files_dict.keys()) # ROSBAG output path if not os.path.isdir(args.output_dir): os.makedirs(args.output_dir) self.output_filename = os.path.join(args.output_dir, '%s_no_images.bag' % self.log_id) self.bag = rosbag.Bag(self.output_filename, 'w') # Topic names self.lidar_topic = '/argoverse/lidar/pointcloud' self.camera_info_topic_template = '/argoverse/%s/camera_info' # TF frames self.map_frame = 'city' self.vehicle_frame = 'egovehicle' self.load_camera_static_tf()
def __init__(self, question_h5, image_feature_h5_path, lidar_feature_h5_path,vocab,load_lidar=True,npoint=1024,normal_channel=True,uniform=False,cache_size=15000,drivable_area=False, mode='prefix', image_h5=None, lidar_h5=None, max_samples=None, question_families=None, image_idx_start_from=None): #############read whole question_h5 file in memory############################# self.all_questions = question_h5['questions'][:] self.all_answers = get_answer_classes(question_h5['answers'][:], vocab) self.all_image_idxs = question_h5['image_idxs'][:] self.all_video_names = (question_h5['video_names'][:]).astype(str) self.questions_length = question_h5['question_length'][:] self.image_feature_h5 = image_feature_h5_path self.load_lidar=load_lidar ############for lidar########################################################## if self.load_lidar: self.argoverse_loader = ArgoverseTrackingLoader(lidar_feature_h5_path) self.am = ArgoverseMap() self.drivable_area=drivable_area
def __init__(self, tracking_dataset_dir, dataset_name=None, argoverse_map=None, argoverse_loader=None, save_imgs=False): logger = logging.getLogger() logger.setLevel(logging.CRITICAL) self.dataset_dir = tracking_dataset_dir self.am = ArgoverseMap() if argoverse_map is None else argoverse_map self.argoverse_loader = ArgoverseTrackingLoader( tracking_dataset_dir ) if argoverse_loader is None else argoverse_loader self.dataset_prefix_name = dataset_name self.objects_from_to = self._get_objects_from_to() self.valid_target_objects = self._get_valid_target_objects( save_imgs=save_imgs)
def save_all_to_pickle(): datasets = ["train1", "train2", "train3", "train4"] final_dict = {} for dataset in datasets: tracking_dataset_dir = '/media/bartosz/hdd1TB/workspace_hdd/datasets/argodataset/argoverse-tracking/' + dataset ################### am = ArgoverseMap() argoverse_loader = ArgoverseTrackingLoader(tracking_dataset_dir) ################### argoverse = Argoverse(tracking_dataset_dir=tracking_dataset_dir, dataset_name=dataset, argoverse_map=am, argoverse_loader=argoverse_loader) final_dict.update(argoverse.valid_target_objects) print("Processed {}".format(dataset)) f = "/media/bartosz/hdd1TB/workspace_hdd/SS-LSTM/data/argoverse/train1234_48x48.pickle" pickle_out = open(f, "wb") pickle.dump(final_dict, pickle_out, protocol=2) pickle_out.close() print("Saved to pickle {}".format(f))
def __init__(self, input_log_dir: str, output_save_path: str) -> None: self.input_log_dir = input_log_dir self.output_save_path = output_save_path self.log_id = os.path.basename(input_log_dir) print("Log ID ", self.log_id) # Load Argo data dataset = os.path.dirname(self.input_log_dir) self.argoverse_loader = ArgoverseTrackingLoader(dataset) self.argoverse_data = self.argoverse_loader.get(self.log_id) # Count the number of LiDAR ply files in the log dir self.lidar_frame_counter = len( glob.glob1(os.path.join(self.input_log_dir, "lidar"), "*.ply")) # Setup depth dataset dir self.depth_data_dir_setup() # Extract depth data and ring camera frames self.depth_extraction()
def __init__(self, root, seed=None, train=True, sequence_length=3, transform=None, skip_frames=1, dataset='kitti'): np.random.seed(seed) random.seed(seed) self.root = Path(root) scene_list_path = self.root / 'train.txt' if train else self.root / 'val.txt' self.scenes = [ self.root / folder[:-1] for folder in open(scene_list_path) ] self.transform = transform self.dataset = dataset self.k = skip_frames self.root_dir = '/ssd_scratch/cvit/raghava.modhugu/' self.argoverse_loader = ArgoverseTrackingLoader(self.root_dir) self.camera = self.argoverse_loader.CAMERA_LIST[0] self.crawl_folders(sequence_length, self.camera, self.argoverse_loader)
def data_loader() -> ArgoverseTrackingLoader: return ArgoverseTrackingLoader(TEST_DATA_LOC)
def make_att_files(root_dir: str) -> None: """Write a .pkl file with difficulty attributes per track""" path_output_vis = "vis_output" filename_output = "att_file.npy" if not os.path.exists(path_output_vis): os.mkdir(path_output_vis) list_folders = ["test"] list_name_class = ["VEHICLE", "PEDESTRIAN"] count_track = 0 dict_att_all: Dict[str, Any] = {} for name_folder in list_folders: dict_att_all[name_folder] = {} list_log_folders = glob.glob(os.path.join(root_dir, name_folder, "*")) for ind_log, path_log in enumerate(list_log_folders): id_log = f"{Path(path_log).name}" print("%s %s %d/%d" % (name_folder, id_log, ind_log, len(list_log_folders))) if check_track_label_folder: list_path_label_persweep = glob.glob( os.path.join(path_log, "per_sweep_annotations_amodal", "*")) list_path_label_persweep.sort() dict_track_labels: Dict[str, Any] = {} for path_label_persweep in list_path_label_persweep: data = read_json_file(path_label_persweep) for data_obj in data: id_obj = data_obj["track_label_uuid"] if id_obj not in dict_track_labels.keys(): dict_track_labels[id_obj] = [] dict_track_labels[id_obj].append(data_obj) data_amodal: Dict[str, Any] = {} for key in dict_track_labels.keys(): dict_amodal: Dict[str, Any] = {} data_amodal[key] = dict_amodal data_amodal[key]["label_class"] = dict_track_labels[key][ 0]["label_class"] data_amodal[key]["uuid"] = dict_track_labels[key][0][ "track_label_uuid"] data_amodal[key]["log_id"] = id_log data_amodal[key]["track_label_frames"] = dict_track_labels[ key] argoverse_loader = ArgoverseTrackingLoader( os.path.join(root_dir, name_folder)) data_log = argoverse_loader.get(id_log) list_lidar_timestamp = data_log.lidar_timestamp_list dict_tracks: Dict[str, Any] = {} for id_track in data_amodal.keys(): data = data_amodal[id_track] if data["label_class"] not in list_name_class: continue data_per_frame = data["track_label_frames"] dict_per_track: Dict[str, Any] = {} dict_tracks[id_track] = dict_per_track dict_tracks[id_track]["ind_lidar_min"] = -1 dict_tracks[id_track]["ind_lidar_max"] = -1 length_log = len(list_lidar_timestamp) dict_tracks[id_track]["list_city_se3"] = [None] * length_log dict_tracks[id_track]["list_bbox"] = [None] * length_log count_track += 1 dict_tracks[id_track]["list_center"] = np.full([length_log, 3], np.nan) dict_tracks[id_track]["list_center_w"] = np.full( [length_log, 3], np.nan) dict_tracks[id_track]["list_dist"] = np.full([length_log], np.nan) dict_tracks[id_track]["exists"] = np.full([length_log], False) for box in data_per_frame: if box["timestamp"] in list_lidar_timestamp: ind_lidar = list_lidar_timestamp.index( box["timestamp"]) else: continue if dict_tracks[id_track]["ind_lidar_min"] == -1: dict_tracks[id_track]["ind_lidar_min"] = ind_lidar dict_tracks[id_track]["ind_lidar_max"] = max( ind_lidar, dict_tracks[id_track]["ind_lidar_max"]) center = np.array([ box["center"]["x"], box["center"]["y"], box["center"]["z"] ]) city_SE3_egovehicle = argoverse_loader.get_pose( ind_lidar, id_log) if city_SE3_egovehicle is None: print("Pose not found!") continue center_w = city_SE3_egovehicle.transform_point_cloud( center[np.newaxis, :])[0] dict_tracks[id_track]["list_center"][ind_lidar] = center dict_tracks[id_track]["list_center_w"][ ind_lidar] = center_w dict_tracks[id_track]["list_dist"][ ind_lidar] = np.linalg.norm(center[0:2]) dict_tracks[id_track]["exists"][ind_lidar] = True dict_tracks[id_track]["list_city_se3"][ ind_lidar] = city_SE3_egovehicle dict_tracks[id_track]["list_bbox"][ind_lidar] = box length_track = dict_tracks[id_track][ "ind_lidar_max"] - dict_tracks[id_track][ "ind_lidar_min"] + 1 assert not (dict_tracks[id_track]["ind_lidar_max"] == -1 and dict_tracks[id_track]["ind_lidar_min"] == -1), "zero-length track" dict_tracks[id_track]["length_track"] = length_track ( dict_tracks[id_track]["list_vel"], dict_tracks[id_track]["list_acc"], ) = compute_v_a(dict_tracks[id_track]["list_center_w"]) dict_tracks[id_track]["num_missing"] = ( dict_tracks[id_track]["length_track"] - dict_tracks[id_track]["exists"].sum()) dict_tracks[id_track]["difficult_att"] = [] # get scalar velocity per timestamp as 2-norm of (vx, vy) vel_abs = np.linalg.norm( dict_tracks[id_track]["list_vel"][:, 0:2], axis=1) acc_abs = np.linalg.norm( dict_tracks[id_track]["list_acc"][:, 0:2], axis=1) ind_valid = np.nonzero( 1 - np.isnan(dict_tracks[id_track]["list_dist"]))[0] ind_close = np.nonzero(dict_tracks[id_track]["list_dist"] [ind_valid] < NEAR_DISTANCE_THRESH)[0] if len(ind_close) > 0: ind_close_max = ind_close.max() + 1 ind_close_min = ind_close.min() # Only compute "fast" and "occluded" tags for near objects # The thresholds are not very meaningful for faraway objects, since they are usually pretty short. if dict_tracks[id_track]["list_dist"][ind_valid].min( ) > NEAR_DISTANCE_THRESH: dict_tracks[id_track]["difficult_att"].append("far") else: is_short_len_track1 = dict_tracks[id_track][ "length_track"] < SHORT_TRACK_LENGTH_THRESH is_short_len_track2 = dict_tracks[id_track]["exists"].sum( ) < SHORT_TRACK_COUNT_THRESH if is_short_len_track1 or is_short_len_track2: dict_tracks[id_track]["difficult_att"].append("short") else: if (ind_close_max - ind_close_min) - dict_tracks[id_track][ "exists"][ind_close_min:ind_close_max].sum( ) > MAX_OCCLUSION_PCT: dict_tracks[id_track]["difficult_att"].append( "occ") if np.quantile(vel_abs[ind_valid][ind_close], 0.9) > FAST_TRACK_THRESH: dict_tracks[id_track]["difficult_att"].append( "fast") if len(dict_tracks[id_track]["difficult_att"]) == 0: dict_tracks[id_track]["difficult_att"].append("easy") if visualize: for ind_lidar, timestamp_lidar in enumerate( list_lidar_timestamp): list_bboxes = [] list_difficulty_att = [] for id_track in dict_tracks.keys(): if dict_tracks[id_track]["exists"][ind_lidar]: list_bboxes.append( dict_tracks[id_track]["list_bbox"][ind_lidar]) list_difficulty_att.append( dict_tracks[id_track]["difficult_att"]) path_lidar = os.path.join(path_log, "lidar", "PC_%s.ply" % timestamp_lidar) pc = np.asarray(o3d.io.read_point_cloud(path_lidar).points) list_lidar_timestamp = data_log.lidar_timestamp_list save_bev_img( path_output_vis, list_bboxes, list_difficulty_att, "argoverse_%s" % name_folder, id_log, timestamp_lidar, pc, ) for id_track in dict_tracks.keys(): list_key = list(dict_tracks[id_track].keys()).copy() for key in list_key: if key != "difficult_att": del dict_tracks[id_track][key] dict_att_all[name_folder][id_log] = dict_tracks save_pkl_dictionary(filename_output, dict_att_all)
# Setup the root directory data_dir = root_dir + 'train_test/' goal_dir = root_dir + 'train_test_kitti/' if not os.path.exists(goal_dir): os.mkdir(goal_dir) os.mkdir(goal_dir + 'velodyne') os.mkdir(goal_dir + 'image_2') os.mkdir(goal_dir + 'calib') os.mkdir(goal_dir + 'label_2') os.mkdir(goal_dir + 'velodyne_reduced') # Check the number of logs(one continuous trajectory) argoverse_loader = ArgoverseTrackingLoader(data_dir) print('\nTotal number of logs:', len(argoverse_loader)) argoverse_loader.print_all() print('\n') cams = [ 'ring_front_center', 'ring_front_left', 'ring_front_right', 'ring_rear_left', 'ring_rear_right', 'ring_side_left', 'ring_side_right' ] # count total number of files total_number = 0 for q in argoverse_loader.log_list: path, dirs, files = next(os.walk(data_dir + q + '/lidar')) total_number = total_number + len(files)
import argoverse from argoverse.data_loading.argoverse_tracking_loader import ArgoverseTrackingLoader import pdb pdb.set_trace() root_dir = '/ssd_scratch/cvit/raghava.modhugu/argoverse-tracking/' argoverse_loader = ArgoverseTrackingLoader(root_dir) camera = 'ring_front_center' with open('splits/argoverse/val_files.txt') as f: for cnt, line in enumerate(f): log, index, _ = line.split() print(log, index) print( argoverse_loader.get(log).get_image(int(index), camera=camera, load=False))
split = folder_choice[len(os.path.dirname(folder_choice)) + 1:] is_test = (split == 'test') am = ArgoverseMap() print("____________SPLIT IS : {} ______________".format(split)) if split == 'train' or split == 'val': imageset_dir = os.path.join(root_dir, split) splitname = lambda x: [ x[len(imageset_dir + "/"):-4].split("/")[0], x[len( imageset_dir + "/"):-4].split("/")[2].split("_")[1] ] data_loader = ArgoverseTrackingLoader(os.path.join(root_dir, split)) log_list = data_loader.log_list path_count = 0 actual_idx_list = [] logidx_to_count_map = {} log_to_count_map = {} map_objectid_bool = {} map_saveid_objectid = {} map_class_saveid_count = {} for log_id, log in enumerate(log_list): print("converting log {} {}".format(log, log_id)) argoverse_data = data_loader.get(log) city_name = argoverse_data.city_name
def generate_weak_static(dataset_dir="", log_id="", output_dir=""): argoverse_loader = ArgoverseTrackingLoader(dataset_dir) argoverse_data = argoverse_loader.get(log_id) camera = argoverse_loader.CAMERA_LIST[7] calib = argoverse_data.get_calibration(camera) ply_fpath = os.path.join(dataset_dir, log_id, 'lidar') ply_locs = [] for idx, ply_name in enumerate(os.listdir(ply_fpath)): ply_loc = np.array([idx, int(ply_name.split('.')[0].split('_')[-1])]) ply_locs.append(ply_loc) ply_locs = np.array(ply_locs) lidar_timestamps = sorted(ply_locs[:, 1]) calib_path = f"{dataset_dir}/{log_id}/vehicle_calibration_info.json" calib_data = read_json_file(calib_path) ind = 0 for i in range(9): if calib_data['camera_data_'][i]['key'] == \ 'image_raw_stereo_front_left': ind = i break rotation = np.array(calib_data['camera_data_'][ind]['value'] ['vehicle_SE3_camera_']['rotation']['coefficients']) translation = np.array(calib_data['camera_data_'][ind]['value'] ['vehicle_SE3_camera_']['translation']) sparse_road_bev_loc = os.path.join(output_dir, log_id, 'sparse_road_bev') try: os.makedirs(sparse_road_bev_loc) except BaseException: pass dense_city_road_pts = [] for idx in range(len(lidar_timestamps)): occupancy_map = np.zeros((256, 256)) lidar_timestamp = lidar_timestamps[idx] try: img_loc = argoverse_data.get_image_list_sync(camera=camera)[idx] except BaseException: continue cam_timestamp = int(img_loc.split('.')[0].split('_')[-1]) segment_loc = os.path.join( dataset_dir, log_id, 'segment', 'stereo_front_left_' + str(cam_timestamp) + '.png') segment_img = cv2.imread(segment_loc, 0) pc = argoverse_data.get_lidar(idx) uv = calib.project_ego_to_image(pc).T idx_ = np.where( np.logical_and.reduce( (uv[0, :] >= 0.0, uv[0, :] < np.shape(segment_img)[1] - 1.0, uv[1, :] >= 0.0, uv[1, :] < np.shape(segment_img)[0] - 1.0, uv[2, :] > 0))) idx_ = idx_[0] uv1 = uv[:, idx_] uv1 = uv1.T x = uv1[:, 0].astype(np.int32) y = uv1[:, 1].astype(np.int32) col = segment_img[y, x] filt = np.logical_or(col == 13, np.logical_or(col == 24, col == 24)) road_uv1 = uv1[filt, :] lidar_road_pts = calib.project_image_to_ego(road_uv1) cam_road_pts = calib.project_ego_to_cam(lidar_road_pts) X = cam_road_pts[:, 0] Z = cam_road_pts[:, 2] filt2 = np.logical_and(X > -20, X < 20) filt2 = np.logical_and(filt2, np.logical_and(Z > 0, Z < 40)) y_img = (-Z[filt2] / res).astype(np.int32) x_img = (X[filt2] / res).astype(np.int32) x_img -= int(np.floor(-20 / res)) y_img += int(np.floor(40 / res)) occupancy_map[y_img, x_img] = 255 occ_map_loc = os.path.join( sparse_road_bev_loc, 'stereo_front_left_' + str(cam_timestamp) + '.png') cv2.imwrite(occ_map_loc, occupancy_map) pose_fpath = os.path.join( dataset_dir, log_id, "poses", "city_SE3_egovehicle_" + str(lidar_timestamp) + ".json") if not Path(pose_fpath).exists(): print("not a apth") continue pose_data = read_json_file(pose_fpath) rotation = np.array(pose_data["rotation"]) translation = np.array(pose_data["translation"]) city_to_egovehicle_se3 = SE3(rotation=quat2rotmat(rotation), translation=translation) sparse_city_road_pts = city_to_egovehicle_se3.transform_point_cloud( lidar_road_pts) try: dense_city_road_pts = np.concatenate( (dense_city_road_pts, sparse_city_road_pts), axis=0) except BaseException: dense_city_road_pts = sparse_city_road_pts dense_road_bev_loc = os.path.join(output_dir, log_id, 'dense_road_bev') try: os.makedirs(dense_road_bev_loc) except BaseException: pass for idx in range(len(lidar_timestamps)): occupancy_map = np.zeros((256, 256)) lidar_timestamp = lidar_timestamps[idx] try: img_loc = argoverse_data.get_image_list_sync(camera=camera)[idx] except BaseException: continue cam_timestamp = int(img_loc.split('.')[0].split('_')[-1]) pose_fpath = os.path.join( dataset_dir, log_id, "poses", "city_SE3_egovehicle_" + str(lidar_timestamp) + ".json") if not Path(pose_fpath).exists(): print("not a path") continue pose_data = read_json_file(pose_fpath) rotation = np.array(pose_data["rotation"]) translation = np.array(pose_data["translation"]) city_to_egovehicle_se3 = SE3(rotation=quat2rotmat(rotation), translation=translation) current_ego_frame_road_pts =\ city_to_egovehicle_se3\ .inverse_transform_point_cloud(dense_city_road_pts) current_cam_frame_road_pts = calib.project_ego_to_cam( current_ego_frame_road_pts) X = current_cam_frame_road_pts[:, 0] Z = current_cam_frame_road_pts[:, 2] filt2 = np.logical_and(X > -20, X < 20) filt2 = np.logical_and(filt2, np.logical_and(Z > 0, Z < 40)) y_img = (-Z[filt2] / res).astype(np.int32) x_img = (X[filt2] / res).astype(np.int32) x_img -= int(np.floor(-20 / res)) y_img += int(np.floor(40 / res)) - 1 occupancy_map[y_img, x_img] = 255 occ_map_loc = os.path.join( dense_road_bev_loc, 'stereo_front_left_' + str(cam_timestamp) + '.png') cv2.imwrite(occ_map_loc, occupancy_map)
def generate_road_bev(dataset_dir="", log_id="", output_dir=""): argoverse_loader = ArgoverseTrackingLoader(dataset_dir) argoverse_data = argoverse_loader.get(log_id) city_name = argoverse_data.city_name avm = ArgoverseMap() sdb = SynchronizationDB(dataset_dir, collect_single_log_id=log_id) try: path = os.path.join(output_dir, log_id, 'road_gt') command = "rm -r " + path os.system(command) except BaseException: pass try: os.makedirs(os.path.join(output_dir, log_id, 'road_gt')) except BaseException: pass ply_fpath = os.path.join(dataset_dir, log_id, 'lidar') ply_locs = [] for idx, ply_name in enumerate(os.listdir(ply_fpath)): ply_loc = np.array([idx, int(ply_name.split('.')[0].split('_')[-1])]) ply_locs.append(ply_loc) ply_locs = np.array(ply_locs) lidar_timestamps = sorted(ply_locs[:, 1]) calib_path = f"{dataset_dir}/{log_id}/vehicle_calibration_info.json" calib_data = read_json_file(calib_path) ind = 0 for i in range(9): if calib_data['camera_data_'][i]['key'] ==\ 'image_raw_stereo_front_left': ind = i break rotation = np.array(calib_data['camera_data_'][ind]['value'] ['vehicle_SE3_camera_']['rotation']['coefficients']) translation = np.array(calib_data['camera_data_'][ind]['value'] ['vehicle_SE3_camera_']['translation']) egovehicle_SE3_cam = SE3(rotation=quat2rotmat(rotation), translation=translation) for idx in range(len(lidar_timestamps)): lidar_timestamp = lidar_timestamps[idx] cam_timestamp = sdb.get_closest_cam_channel_timestamp( lidar_timestamp, "stereo_front_left", str(log_id)) occupancy_map = np.zeros((256, 256)) pose_fpath = os.path.join( dataset_dir, log_id, "poses", "city_SE3_egovehicle_" + str(lidar_timestamp) + ".json") if not Path(pose_fpath).exists(): continue pose_data = read_json_file(pose_fpath) rotation = np.array(pose_data["rotation"]) translation = np.array(pose_data["translation"]) xcenter = translation[0] ycenter = translation[1] city_to_egovehicle_se3 = SE3(rotation=quat2rotmat(rotation), translation=translation) ego_car_nearby_lane_ids = avm.get_lane_ids_in_xy_bbox( xcenter, ycenter, city_name, 50.0) occupancy_map = get_lane_bev(ego_car_nearby_lane_ids, avm, city_name, city_to_egovehicle_se3, egovehicle_SE3_cam, occupancy_map, res, 255) output_loc = os.path.join( output_dir, log_id, 'road_gt', 'stereo_front_left_' + str(cam_timestamp) + '.png') cv2.imwrite(output_loc, occupancy_map)
def main(): # set root_dir to the correct path to your dataset folder root_dir = core.data_dir( ) + '/datasets/argoverse/argoverse-tracking/sample/' vtk_window_size = (1280, 720) argoverse_loader = ArgoverseTrackingLoader(root_dir) print('Total number of logs:', len(argoverse_loader)) argoverse_loader.print_all() for i, argoverse_data in enumerate(argoverse_loader): if i >= 3: break print(argoverse_data) argoverse_data = argoverse_loader[0] print(argoverse_data) argoverse_data = argoverse_loader.get( 'c6911883-1843-3727-8eaa-41dc8cda8993') print(argoverse_data) log_id = 'c6911883-1843-3727-8eaa-41dc8cda8993' # argoverse_loader.log_list[55] frame_idx = 150 camera = argoverse_loader.CAMERA_LIST[0] argoverse_data = argoverse_loader.get(log_id) city_name = argoverse_data.city_name print('-------------------------------------------------------') print(f'Log: {log_id}, \n\tframe: {frame_idx}, camera: {camera}') print('-------------------------------------------------------\n') lidar_points = argoverse_data.get_lidar(frame_idx) img = argoverse_data.get_image_sync(frame_idx, camera=camera) objects = argoverse_data.get_label_object(frame_idx) calib = argoverse_data.get_calibration(camera) # TODO: Calculate point colours vtk_pc = VtkPointCloudGlyph() vtk_pc.set_points(lidar_points) vtk_pc.set_point_size(2) vtk_renderer = demo_utils.setup_vtk_renderer() vtk_render_window = demo_utils.setup_vtk_render_window( 'Argoverse Demo', vtk_window_size, vtk_renderer) vtk_axes = vtk.vtkAxesActor() vtk_axes.SetTotalLength(2, 2, 2) vtk_renderer.AddActor(vtk_axes) vtk_renderer.AddActor(vtk_pc.vtk_actor) current_cam = vtk_renderer.GetActiveCamera() current_cam.SetViewUp(0, 0, 1) current_cam.SetPosition(-50, 0, 15) current_cam.SetFocalPoint(30, 0, 0) vtk_interactor = demo_utils.setup_vtk_interactor(vtk_render_window) vtk_interactor.Start()
def main(): args = parser.parse_args() pdb.set_trace() if not (args.output_disp or args.output_depth): print('You must at least output one value !') return argoverse_loader = ArgoverseTrackingLoader(args.argoverse_data_path) camera = argoverse_loader.CAMERA_LIST[0] argoverse_data = argoverse_loader.get(args.argoverse_log) num_lidar = len(argoverse_data.get_image_list_sync(camera)) disp_net = DispResNet(args.resnet_layers, False).to(device) weights = torch.load(args.pretrained, map_location=device) disp_net.load_state_dict(weights['state_dict']) disp_net.eval() #dataset_dir = Path(args.dataset_dir) output_dir = Path(args.output_dir) output_dir.makedirs_p() # if args.dataset_list is not None: # with open(args.dataset_list, 'r') as f: # test_files = [dataset_dir/file for file in f.read().splitlines()] # else: # test_files = sum([dataset_dir.files('*.{}'.format(ext)) for ext in args.img_exts], []) # print('{} files to test'.format(len(test_files))) for frame in tqdm(range(0, num_lidar - 1)): file = argoverse_data.get_image_sync(frame, camera, load=False) img = imread(file).astype(np.float32) h, w, _ = img.shape if (not args.no_resize) and (h != args.img_height or w != args.img_width): img = imresize(img, (args.img_height, args.img_width)).astype( np.float32) img = np.transpose(img, (2, 0, 1)) tensor_img = torch.from_numpy(img).unsqueeze(0) tensor_img = ((tensor_img / 255 - 0.45) / 0.225).to(device) output = disp_net(tensor_img)[0] file_path, file_ext = file.relpath(args.dataset_dir).splitext() file_name = '-'.join(file_path.splitall()) if args.output_disp: disp = (255 * tensor2array(output, max_value=None, colormap='bone')).astype(np.uint8) imsave(output_dir / '{}_disp{}'.format(file_name, file_ext), np.transpose(disp, (1, 2, 0))) if args.output_depth: depth = 1 / output depth = (255 * tensor2array( depth, max_value=10, colormap='rainbow')).astype(np.uint8) imsave(output_dir / '{}_depth{}'.format(file_name, file_ext), np.transpose(depth, (1, 2, 0)))
def generate_vehicle_bev(dataset_dir="", log_id="", output_dir=""): argoverse_loader = ArgoverseTrackingLoader(dataset_dir) argoverse_data = argoverse_loader.get(log_id) camera = argoverse_loader.CAMERA_LIST[7] calib = argoverse_data.get_calibration(camera) sdb = SynchronizationDB(dataset_dir, collect_single_log_id=log_id) calib_path = f"{dataset_dir}/{log_id}/vehicle_calibration_info.json" calib_data = read_json_file(calib_path) ind = 0 for i in range(9): if calib_data['camera_data_'][i]['key'] == \ 'image_raw_stereo_front_left': ind = i break rotation = np.array(calib_data['camera_data_'][ind]['value'] ['vehicle_SE3_camera_']['rotation']['coefficients']) translation = np.array(calib_data['camera_data_'][ind]['value'] ['vehicle_SE3_camera_']['translation']) egovehicle_SE3_cam = SE3(rotation=quat2rotmat(rotation), translation=translation) if not os.path.exists(os.path.join(output_dir, log_id, "car_bev_gt")): os.makedirs(os.path.join(output_dir, log_id, "car_bev_gt")) lidar_dir = os.path.join(dataset_dir, log_id, "lidar") ply_list = os.listdir(lidar_dir) pfa = PerFrameLabelAccumulator(dataset_dir, dataset_dir, "argoverse_bev_viz", save=False, bboxes_3d=True) pfa.accumulate_per_log_data(log_id) log_timestamp_dict = pfa.log_timestamp_dict for i, ply_name in enumerate(ply_list): lidar_timestamp = ply_name.split('.')[0].split('_')[1] lidar_timestamp = int(lidar_timestamp) cam_timestamp = sdb.get_closest_cam_channel_timestamp( lidar_timestamp, "stereo_front_left", str(log_id)) image_path = os.path.join( output_dir, str(log_id), "car_bev_gt", "stereo_front_left_" + str(cam_timestamp) + ".jpg") objects = log_timestamp_dict[log_id][lidar_timestamp] top_view = np.zeros((256, 256)) all_occluded = True for frame_rec in objects: if frame_rec.occlusion_val != IS_OCCLUDED_FLAG: all_occluded = False if not all_occluded: for i, frame_rec in enumerate(objects): bbox_ego_frame = frame_rec.bbox_ego_frame uv = calib.project_ego_to_image(bbox_ego_frame).T idx_ = np.all( np.logical_and( np.logical_and( np.logical_and(uv[0, :] >= 0.0, uv[0, :] < size[1] - 1.0), np.logical_and(uv[1, :] >= 0.0, uv[1, :] < size[0] - 1.0)), uv[2, :] > 0)) if not idx_: continue bbox_cam_fr = egovehicle_SE3_cam.inverse().\ transform_point_cloud(bbox_ego_frame) X = bbox_cam_fr[:, 0] Z = bbox_cam_fr[:, 2] if (frame_rec.occlusion_val != IS_OCCLUDED_FLAG and frame_rec.obj_class_str == "VEHICLE"): y_img = (-Z / res).astype(np.int32) x_img = (X / res).astype(np.int32) x_img -= int(np.floor(-20 / res)) y_img += int(np.floor(40 / res)) box = np.array([x_img[2], y_img[2]]) box = np.vstack((box, [x_img[6], y_img[6]])) box = np.vstack((box, [x_img[7], y_img[7]])) box = np.vstack((box, [x_img[3], y_img[3]])) cv2.drawContours(top_view, [box], 0, 255, -1) cv2.imwrite(image_path, top_view)
def test(config_path=args.config_path, model_dir=args.model_dir, result_path=None, create_folder=False, pickle_result=True, include_roadmap=False, device=1): """train a VoxelNet model specified by a config file. """ if create_folder: if pathlib.Path(model_dir).exists(): model_dir = torchplus.train.create_folder(model_dir) model_dir = pathlib.Path(model_dir) model_dir.mkdir(parents=True, exist_ok=True) eval_checkpoint_dir = model_dir / 'eval_checkpoints' eval_checkpoint_dir.mkdir(parents=True, exist_ok=True) if result_path is None: result_path = model_dir / 'results' config_file_bkp = "pipeline.config" config = pipeline_pb2.TrainEvalPipelineConfig() with open(config_path, "r") as f: proto_str = f.read() text_format.Merge(proto_str, config) shutil.copyfile(config_path, str(model_dir / config_file_bkp)) input_cfg = config.train_input_reader eval_input_cfg = config.eval_input_reader model_cfg = config.model.second train_cfg = config.train_config batch_size = 1 class_names = list(input_cfg.class_names) ###################### # BUILD VOXEL GENERATOR ###################### voxel_generator = voxel_builder.build(model_cfg.voxel_generator) grid_size = voxel_generator.grid_size ###################### # BUILD TARGET ASSIGNER ###################### bv_range = voxel_generator.point_cloud_range[[0, 1, 3, 4]] box_coder = box_coder_builder.build(model_cfg.box_coder) target_assigner_cfg = model_cfg.target_assigner target_assigner = target_assigner_builder.build(target_assigner_cfg, bv_range, box_coder) ###################### # BUILD NET ###################### center_limit_range = model_cfg.post_center_limit_range net = second_builder.build(model_cfg, voxel_generator, target_assigner, include_roadmap) net.cuda().eval() print("num_trainable parameters:", len(list(net.parameters()))) # for n, p in net.named_parameters(): # print(n, p.shape) #torchplus.train.try_restore_latest_checkpoints(model_dir, [net]) torchplus.train.restore(args.model_path, net) #torchplus.train.restore("./ped_models_56/voxelnet-275130.tckpt",net) out_size_factor = model_cfg.rpn.layer_strides[ 0] / model_cfg.rpn.upsample_strides[0] print(out_size_factor) #out_size_factor *= model_cfg.middle_feature_extractor.downsample_factor out_size_factor = int(out_size_factor) feature_map_size = grid_size[:2] // out_size_factor feature_map_size = [*feature_map_size, 1][::-1] print(feature_map_size) ret = target_assigner.generate_anchors(feature_map_size) #anchors_dict = target_assigner.generate_anchors_dict(feature_map_size) anchors = ret["anchors"] anchors = anchors.reshape([-1, 7]) matched_thresholds = ret["matched_thresholds"] unmatched_thresholds = ret["unmatched_thresholds"] anchors_bv = box_np_ops.rbbox2d_to_near_bbox(anchors[:, [0, 1, 3, 4, 6]]) anchor_cache = { "anchors": anchors, "anchors_bv": anchors_bv, "matched_thresholds": matched_thresholds, "unmatched_thresholds": unmatched_thresholds, #"anchors_dict": anchors_dict, } am = ArgoverseMap() dt_annos = [] root_dir = os.path.join('./../../argodataset/argoverse-tracking/', args.set) argoverse_loader = ArgoverseTrackingLoader(root_dir) prog_cnt = 0 for seq in range(len(argoverse_loader)): argoverse_data = argoverse_loader[seq] nlf = argoverse_data.num_lidar_frame for frame in range(nlf): prog_cnt += 1 if prog_cnt % 50 == 0: print(prog_cnt) points = argoverse_data.get_lidar(frame) roi_pts = copy.deepcopy(points) city_name = argoverse_data.city_name city_to_egovehicle_se3 = argoverse_data.get_pose(frame) ''' roi_pts = city_to_egovehicle_se3.transform_point_cloud(roi_pts) # put into city coords #non roi roi_pts_flag = am.remove_non_roi_points(roi_pts, city_name) # remove non-driveable region roi_pts = roi_pts[roi_pts_flag] roi_pts = am.remove_ground_surface(roi_pts, city_name) # remove ground surface # convert city to lidar co-ordinates roi_pts = city_to_egovehicle_se3.inverse_transform_point_cloud(roi_pts) ''' if args.include_roi or args.dr_area or not args.include_road_points: roi_pts = city_to_egovehicle_se3.transform_point_cloud( roi_pts) # put into city coords if args.include_roi: roi_pts_flag = am.remove_non_roi_points( roi_pts, city_name) # remove non-driveable region roi_pts = roi_pts[roi_pts_flag] if not args.include_roi and args.dr_area: roi_pts_flag = am.remove_non_driveable_area_points( roi_pts, city_name) # remove non-driveable region roi_pts = roi_pts[roi_pts_flag] if not args.include_road_points: roi_pts = am.remove_ground_surface( roi_pts, city_name) # remove ground surface # convert city to lidar co-ordinates if args.include_roi or args.dr_area or not args.include_road_points: roi_pts = city_to_egovehicle_se3.inverse_transform_point_cloud( roi_pts) roi_pts[:, 2] = roi_pts[:, 2] - 1.73 pts_x, pts_y, pts_z = roi_pts[:, 0], roi_pts[:, 1], roi_pts[:, 2] input_dict = { 'points': roi_pts, 'pointcloud_num_features': 3, } out_size_factor = model_cfg.rpn.layer_strides[ 0] // model_cfg.rpn.upsample_strides[0] example = prep_pointcloud( input_dict=input_dict, root_path=None, voxel_generator=voxel_generator, target_assigner=target_assigner, max_voxels=input_cfg.max_number_of_voxels, class_names=list(input_cfg.class_names), training=False, create_targets=False, shuffle_points=input_cfg.shuffle_points, generate_bev=False, without_reflectivity=model_cfg.without_reflectivity, num_point_features=model_cfg.num_point_features, anchor_area_threshold=input_cfg.anchor_area_threshold, anchor_cache=anchor_cache, out_size_factor=out_size_factor, out_dtype=np.float32) if "anchors_mask" in example: example["anchors_mask"] = example["anchors_mask"].astype( np.uint8) example["image_idx"] = str(seq) + "_" + str(frame) example["image_shape"] = np.array([400, 400], dtype=np.int32) example["road_map"] = None example["include_roadmap"] = False example["points"] = roi_pts #torch.save(example,"./network_input_examples/" + info) example = merge_second_batch([example]) example_torch = example_convert_to_torch(example, device=args.device) try: result_annos = predict_kitti_to_anno( net, example_torch, input_cfg.class_names, model_cfg.post_center_limit_range, model_cfg.lidar_input) except: print(seq, frame) continue dt_annos += result_annos if pickle_result: sdi = args.save_path.rfind('/') save_dir = args.save_path[:sdi] if not os.path.exists(save_dir): os.mkdir(save_dir) with open(args.save_path, 'wb') as f: pickle.dump(dt_annos, f)