def __init__(self, input_shape, cfg, bn_d=0.1): super(DeepLIO, self).__init__() self.logger = get_app_logger() self.cfg = cfg['deeplio'] self.p = self.cfg.get('dropout', 0.) self.input_shape = input_shape self.lidar_feat_net = None self.imu_feat_net = None self.fusion_net = None self.odom_feat_net = None self.drop = None self.fc_pos = None self.fc_ori = None
def __init__(self, config, ds_type='train', transform=None, has_imu=True, has_lidar=True): """ :param root_path: :param config: Configuration file including split settings :param transform: """ ds_config_common = config['datasets'] ds_config = ds_config_common['kitti'] self._seq_size = ds_config_common[ 'sequence-size'] # Increment because we need always one sample more self.internal_seq_size = self.seq_size + 1 self.inv_depth = ds_config.get('inverse-depth', False) self.mean_img = ds_config['mean-image'] self.std_img = ds_config['std-image'] self.mean_imu = ds_config['mean-imu'] self.std_imu = ds_config['std-imu'] self.channels = config['channels'] self.has_imu = has_imu self.has_lidar = has_lidar crop_factors = ds_config.get('crop-factors', [0, 0]) self.crop_top = crop_factors[0] self.crop_left = crop_factors[1] self.ds_type = ds_type self.transform = transform self.datasets = [] self.length_each_drive = [] self.bins = [] self.images = [None] * self.internal_seq_size root_path_sync = ds_config['root-path-sync'] root_path_unsync = ds_config['root-path-unsync'] # Since we are intrested in sequence of lidar frame - e.g. multiple frame at each iteration, # depending on the sequence size and the current wanted index coming from pytorch dataloader # we must switch between each drive if not enough frames exists in that specific drive wanted from dataloader, # therefor we separate valid indices in each drive in bins. last_bin_end = -1 for date, drives in ds_config[self.ds_type].items(): for drive in drives: date = str(date).replace('-', '_') drive = '{0:04d}'.format(drive) ds = KittiRawData(root_path_sync, root_path_unsync, date, drive, ds_config_common, oxts_bin=True) length = len(ds) bin_start = last_bin_end + 1 bin_end = bin_start + length - 1 self.bins.append([bin_start, bin_end]) last_bin_end = bin_end self.length_each_drive.append(length) self.datasets.append(ds) self.bins = np.asarray(self.bins) self.length_each_drive = np.array(self.length_each_drive) self.length = self.bins.flatten()[-1] + 1 self.logger = logger.get_app_logger()
def get_model(input_shape, cfg, device): global net_logger net_logger = get_app_logger() return create_deeplio_arch(input_shape, cfg, device)
def main(args): with open(args['config']) as f: cfg = yaml.safe_load(f) ds_type = "train" batch_size = 3 num_workers = 8 OUTPUT_PATH = "{}/outputs/images".format(content_dir) # create directoy to save images Path(OUTPUT_PATH).mkdir(parents=True, exist_ok=True) # max. number of image swe want to save max_num_it = -1 # Dataset class needs a global logger, so creat it here # TODO: Remove dependecy of dataset to global logger, so it can have its own flog_name = "{}/{}_{}.log".format( OUTPUT_PATH, "Dataset-Visualization", datetime.datetime.now().strftime("%Y%m%d_%H%M%S")) logger = get_app_logger(filename=flog_name, level=logging.INFO) # create dataset andataloader kitti_dataset = Kitti(config=cfg, transform=None, ds_type=ds_type) dataloader = torch.utils.data.DataLoader(kitti_dataset, batch_size=batch_size, num_workers=num_workers, shuffle=False, collate_fn=deeplio_collate) print("Length of dataset is {}".format(len(dataloader))) pbar = tqdm(total=len(dataloader)) # Iterate through datset and save images for idx, data in enumerate(dataloader): ims = data['untrans-images'].detach().cpu() for b in range(len(ims)): metas = data['metas'][b] index = metas['index'][0] date = metas['date'][0] drive = metas['drive'][0] imgs_batch = ims[b, :, 0:3, :, :] #imgs_depth = torch.norm(imgs_batch, p=2, dim=1) #ims_depth = [F.pad(im, (0, 0, 10, 0)) for im in imgs_depth] #ims_depth = torch.cat(ims_depth, dim=0) #imgs_xyz = torch.norm(imgs_batch, p=2, dim=1) ims_xyz = [F.pad(im, (0, 0, 10, 0)) for im in imgs_batch] ims_xyz = torch.cat(ims_xyz, dim=1) ims_xyz = torch.abs(ims_xyz.permute(1, 2, 0)) imgs_normals = ims[b, :, 3:, :, :] #imgs_normals = torch.norm(imgs_normals, p=1, dim=1) imgs_normals = [F.pad(im, (0, 0, 10, 0)) for im in imgs_normals] imgs_normals = torch.cat(imgs_normals, dim=1) imgs_normals = imgs_normals.permute(1, 2, 0) fig, ax = plt.subplots(3, 1, figsize=(10, 10)) ax[0].set_title("XYZ, mean:{:.4f}, std:{:.4f}".format( ims_xyz.mean(), ims_xyz.std()), fontsize=5) ax[0].axis('off') imd = ax[0].imshow(torch.abs(ims_xyz) / ims_xyz.max()) #fig.colorbar(imd, ax=ax[0]) ax[1].set_title("Normal, mean:{:.4f}, std:{:.4f}".format( imgs_normals.mean(), imgs_normals.std()), fontsize=5) imn = ax[1].imshow((imgs_normals + 1.) / 2.) ax[1].axis('off') #fig.colorbar(imn, ax=ax[1]) ax[2].hist(ims_xyz.flatten(), bins=10, alpha=0.5, label="xyz", density=True) ax[2].hist(imgs_normals.flatten(), bins=10, alpha=0.5, label="normals", density=True) ax[2].legend() fname = "{}/{}_{}_{}_{}.png".format(OUTPUT_PATH, idx, index, date, drive) #logger.info("saving {}.".format(fname)) fig.tight_layout() fig.savefig(fname, dpi=600) plt.close(fig) pbar.update(1) if max_num_it > 0 and idx > max_num_it: break