Git Product home page Git Product logo

tlio's Introduction

This code is a supplementary material to the paper "TLIO: Tight Learned Inertial Odometry". To use the code here requires the user to generate its own dataset and retrain. For more information about the paper and the video materials, please refer to our website.

Installation

All dependencies can be installed using conda via

conda env create -f environment.yaml

Then the virtual environment is accessible with:

conda activate tlio

Next commands should be run from this environment.

Dataset

A dataset is needed in numpy format to run with this code. We have released the dataset used in the paper. The data can be downloaded here or with the following command (with the conda env activated) at the root of the repo:

gdown 14YKW7PsozjHo_EdxivKvumsQB7JMw1eg
mkdir -p local_data/ # or ln -s /path/to/data_drive/ local_data/
unzip golden-new-format-cc-by-nc-with-imus-v1.5.zip -d local_data/
rm golden-new-format-cc-by-nc-with-imus-v1.5.zip

https://drive.google.com/file/d/14YKW7PsozjHo_EdxivKvumsQB7JMw1eg/view?usp=share_link The dataset tree structure looks like this. Assume for the examples we have extracted the data under root directory local_data/tlio_golden:

local_data/tlio_golden
├── 1008221029329889
│   ├── calibration.json
│   ├── imu0_resampled_description.json
│   ├── imu0_resampled.npy
│   └── imu_samples_0.csv
├── 1014753008676428
│   ├── calibration.json
│   ├── imu0_resampled_description.json
│   ├── imu0_resampled.npy
│   └── imu_samples_0.csv
...
├── test_list.txt
├── train_list.txt
└── val_list.txt

imu0_resampled.npy contains calibrated IMU data and processed VIO ground truth data. imu0_resampled_description.json describes what the different columns in the data are. The test sequences contain imu_samples_0.csv which is the raw IMU data for running the filter. calibration.json contains the offline calibration. Attitude filter data is not included with the release.

Network training and evaluation

For training or evaluation of one model

There are three different modes for the network part.--mode parameter defines the behaviour of main_net.py. Select between train, test
train: training a network model with training and validation dataset.
test: running an existing network model on testing dataset to obtain concatenated trajectories and metrics. \

1. Training:

Parameters:

--root_dir: dataset root directory. Each subfolder of root directory is a dataset.
--out_dir: training output directory, where checkpoints and logs folders will be created to store trained models and tensorboard logs respectively. A parameters.json file will also be saved.

Example:

python3 src/main_net.py \
--mode train \
--root_dir local_data/tlio_golden \
--out_dir models/resnet \
--epochs 100

Note: We offer multiple types of dataloaders to help speed up training. The --dataset_style arg can be ram, mmap, or iter. ram stores all the sequences in RAM, mmap uses memmapping to only keep part of the sequences in RAM at once, and iter is an iterable-style dataloader for larger datasets, which sacrifices true randomness. The default is mmap, which offers the best tradeoff, and typically works for the dataset provided. However, we found that on server-style machines, the memmapping can cause RAM to fill up for some reason (it seems to work best on personal desktops). If the training is getting killed by your OS or taking up too much RAM, you may try setting --workers to 1, --dataset_style to ram, and/or --no-persistent_workers.

tensorboard --logdir models/resnet/logs/

2. Testing:

Parameters:

--model_path: path of the trained model to test with.
--out_dir: testing output directory, where a folder for each dataset tested will be created containing estimated trajectory as trajectory.txt and plots if specified. metrics.json contains the statistics for each dataset.

Example:

python3 src/main_net.py \
--mode test \
--root_dir local_data/tlio_golden \
--model_path models/resnet/checkpoint_*.pt \
--out_dir test_outputs

Warning: network testing use the ground truth orientations for displacement integration. Please do not consider them as benchmarks, they are more like a debugging tool.

For batch testing on multiple models

Batch scripts are under src/batch_analysis module. Execute batch scripts from the src folder.

Batch testing tests a list of datasets using multiple models and for each model save the trajectories, plots and metrics into a separate model folder. Output tree structure looks like this:

batch_test_outputs
├── model1
│   ├── seq1
│   │   ├── trajectory.txt
│   │   └── *.png
│   ├── seq2
...
│   └── metrics.json
├── model2
│   ├── seq1
...
│   └── metrics.json
...

Create an output directory and go to the src folder

mkdir batch_test_outputs
cd src

Run batch tests. --model_globbing is the globbing pattern to find all models to test. Here we only have one.

python -m batch_runner.net_test_batch \
--root_dir ../local_data/tlio_golden \
--model_globbing "../models/*/checkpoint_best.pt" \
--out_dir ../batch_test_outputs \
--save_plot

If you saved plot, you can visualize there:

feh ../	batch_test_outputs/models-resnet/*/view.png # example using the `feh` image visualizer, use your favorite one

Running analysis and generating plots

After running testing and evaluation in batches, the statistics are saved in either metrics.json. To visualize the results and compare between models, we provide scripts that display the results in an interactive shell through iPython. The scripts are under src/analysis module.

To visualize network testing results from metrics.json including trajectory metrics and testing losses, go to src folder and run

python -m analysis.display_json \
--glob_dataset "../batch_test_outputs/*/"

This will leave you in an interactive shell with a preloaded panda DataFrame d. You can use it to visualize all metrics with the following helper function:

plot_all_stats_net(d)

Running EKF with network displacement estimates

Converting model to torchscript

The EKF expects the model to be in torchscript format.

Example: From the repo root:

python3 src/convert_model_to_torchscript.py \
--model_path models/resnet/checkpoint_best.pt \
--model_param_path models/resnet/parameters.json \
--out_dir models/resnet/

which will create models/resnet/model_torchscript.pt.

Running EKF with one network model

Use src/main_filter.py for running the filter and parsing parameters. The program supports running multiple datasets on one specified network model.

Parameters:

--model_path: path to saved model checkpoint file.
--model_param_path: path to parameter json file for this model.
--out_dir: filter output directory. This will include a parameters.json file with filter parameters, and a folder for each dataset containing the logged states, default to not_vio_state.txt.
--erase_old_log: overwrite old log files. If set to --no-erase_old_log, the program would skip running on the datasets if the output file already exists in the output directory.
--save_as_npy: convert the output txt file to npy file and append file extension (e.g. not_vio_state.txt.npy) to save space.
--initialize_with_offline_calib: initialize with offline calibration of the IMU. If set to --no-initialize_with_offline_calib the initial IMU biases will be initialized to 0.
--visualize: if set, open up an Open3D window to visualize the filter running. This is of course optional.

Example:

python3 src/main_filter.py \
--root_dir local_data/tlio_golden \
--model_path models/resnet/model_torchscript.pt \
--model_param_path models/resnet/parameters.json \
--out_dir filter_outputs \
--erase_old_log \
--save_as_npy \
--initialize_with_offline_calib \
--dataset_number 22 \
--visualize

Please refer to main_filter.py for a full list of parameters.

Batch running filter on multiple models and parameters

Batch script batch_runner/filter_batch provides functionality to run the main file in batch settings. Go to src folder to run the module and you can set the parameters to test within the script (e.g. different update frequencies).

Example:

cd src
python -m batch_runner.filter_batch \
--root_dir ../local_data/tlio_golden \
--model_globbing "../models/*/model_torchscript.pt" \
--out_dir ../batch_filter_outputs

Batch running metrics and plot generation

To generate plots of the states of the filter and to generate metrics.json file for both the filter and network concatenation approaches, batch run plot_state.py on the existing filter and network testing outputs.

Parameters:

--runname_globbing: globbing pattern for all the model names to plot. This pattern should match between filter and ronin and exist in both --filter_dir and --ronin_dir.
--no_make_plots: not to save plots. If removed plots will be saved in the filter output folders for each trajectory.

Example:

python -m batch_runner.plot_batch \
--root_dir ../local_data/tlio_golden \
--runname_globbing "*" \
--filter_dir ../batch_filter_outputs_uf20 \
--ronin_dir ../batch_test_outputs

Up to now a metrics.json file will be added to each model folder, and the tree structure would look like this:

batch_filter_outputs
├── model1
│   ├── seq1
│   │   ├── *.png
│   │   ├── not_vio_state.txt.npy
│   │   └── vio_states.npy
│   ├── seq1
│   │   ├── *.png
│   │   ├── not_vio_state.txt.npy
│   │   └── vio_states.npy
...
│   ├── metrics.json
│   └── parameters.json
├── model2
...

Visualize the plot from the filter and ronin:

feh ../batch_filter_outputs_uf20/models-resnet/*/position-2d.png # example using the `feh` image visualizer, use your favorite one

To generate plots from the metrics:

python -m analysis.display_json \
--glob_dataset "../batch_filter_outputs_uf20/*/"

# then run in the interactive session
# plot_sysperf_cdf(d)

tlio's People

Contributors

cathias avatar dvad avatar nmerrill67 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tlio's Issues

Model Test generated graphs issue

scale
No matter how close the model prediction gets the generated graph scale is always off by quite a large margin. Any idea why this must be happening?

ValueError: A value in x_new is below the interpolation range

I succeed to training & test using my own dataset, but I can't execute 'main_filter.py' with the following error:

ValueError: A value in x_new is below the interpolation range.
1649423831335748 1649423831333688 1649423831336166
Trying to do interpolation at 1649423831333688 between 1649423831335748 and 1649423831336166

As my IMU data is 400 Hz, I have set

imu_freq: 400
imu_base_freq: 800

I've also tried with --update_freq as 10 and 20, but it produces the same error as above.

I think the too large value of self.dt_interp_us may cause this problem..

How can I solve this issue?

Measurement update

Thank you for your excellent paper.
After reading your paper, I have two questions: 1. How does the updated measurement function H (x) come from? Can I interpret it as a pseudo-measurement? 2. How was the partial derivative of Formula (15) calculated? Could you give the specific derivation steps?

best wishes

Linux distribution TLIO uses?

Hi am just wondering which linux distribution TLIO uses so I can make sure mine is the same.
I am running TLIO from docker because I seem to be having some local system issues.
I am updating up to WSL2 for docker to work.

some question about Data Prepare

Hi everyong!

I have some questions about the new data file imu_samples_0.csv and imu0_resampled.npy.
In my understanding, imu_samples_0.csv contain the original IMU datas, which acc and gyr data were not calibrated, and imu0_resampled.npy's IMU data were calibrated. Could you tell me how original IMU data convert into calibrated IMU data? Just did some gravity alignment? (Rotate the axises of IMU and make the z-axis coincide with the direction of gravitry?) And let the calibrated acc data near [0, 0, 9.8] when the IMU is static?

Thank you for your explanation.

Inquiry Regarding Dataset Processing Methodology

Hello,

I'm impressed with the excellent work you've done. I'd like to test your network on a different dataset and was wondering if you could provide some insights into the process of calculating 'calibration.json', 'imu0_resampled_description.json', and 'imu0_resampled.npy' from the 'imu_samples_0.csv' file. I understand that your raw data consists solely of IMU measurements collected from a mobile device. Could you shed some light on the methodology behind generating these specific files?

Thank you!

Issue for the reproducation

Hi, I am a student who want to reproduce the paper result. I used my own imu data collected by my own imu device. I just want to ask how to generate calibrated IMU from raw IMU data cause I found that csv and npy data files are different. Can anyone answer?

get_inference and pose_integrate

Hi everyone, I would like to ask why I have to go through pose_integrate() after getting the displacement prediction from get_inference().

TLIO initialization

Thank you for sharing the code.
I have prepared a dataset and obtained a trained model.
When I test the TLIO system by using a new sequence with no ground-truth file, how can I obtain an initial state(R v p ba bg) to start the EKF filter.
Besides, how can I rotate raw IMU data in IMU local frame to obtain IMU samples in a gravity-aligned frame?

How can we change the time over which we are regressing data?

In the paper you introduce a notation of 200hz-05s-3s which you say takes 3s of 200Hz data and regresses the displacement for the last 0.5s

I see options to change the IMU frequency and window size but how can we change the middle number, time over which we regress displacement?

Also is the current settings 200Hz-1s-1s as described in the paper?

Thanks

function rot_2vec(a,b) R_ba calculating

hi, CathIAS

Why R_ba is calculated like this ?
Now that we know the rotation angle and the axis, why not directly substitute the Rodrigues formula to solve the rotation matrix ?
image

Funciton path: src/utils/math_utils.py

@jit(nopython=True, parallel=False, cache=True)
def rot_2vec(a, b):
assert a.shape == (3, 1)
assert b.shape == (3, 1)

def hat(v):
    v = v.flatten()
    R = np.array([[0, -v[2], v[1]], [v[2], 0, -v[0]], [-v[1], v[0], 0]])
    return R

a_n = np.linalg.norm(a)
b_n = np.linalg.norm(b)
a_hat = a / a_n
b_hat = b / b_n
omega = np.cross(a_hat.T, b_hat.T).T
c = 1.0 / (1 + np.dot(a_hat.T, b_hat))
**_R_ba = np.eye(3) + hat(omega) + c * hat(omega) @ hat(omega)_**
return R_ba

data preparation

Hello.

Thank you for sharing TLIO algorithm. I'm very interested in IMU and working on trying it out. I have a question about datasets.
This github doesn't contain sample datasets, so I think I need to prepare them. However, I don't know the details of the required data well from the code.

Could you tell me what kinds of data need when learning and how to make these data more clearly?

Dataset

Hello,
thank you for sharing the code, this work is very interesting to me and I'm keen to try it out. I just have a few questions concerning datasets.

  1. I was wondering if there are any plans in the future to provide a dataset and/or trained model so that I can test the code out of the box?
  2. What is inside the calib_state.txt file? Is it a single initial pose to initialize the TLIO filter? What is the data format of this file?
  3. In imu_measurements.txt which is passed to gen_fb_data.py, what is the calibrated IMU data? Do you mean the raw data with estimated biases removed?

Thank you!

Issue with window size

Hello, whenever the number of IMU measurements that the network sees is a multiple of 32, I get a layer mismatch error during the training process of the neural network.

For instance, if the IMU frequency is 200, the past size is .4s, the window size is 2s, the network sees 480 measurements, and a mismatch error is thrown.

Thank you in advance.

About the attitude.txt file used in the code.

    @classmethod
    def from_attitude_file(cls, dataset, args):
        ret = cls()
        attitude_filter_path = osp.join(args.root_dir, dataset, "atttitude.txt")
        with open(attitude_filter_path, "r") as f:
            line = f.readline()
            line = f.readline()
        init_calib = np.fromstring(line, sep=",")
        ret.accelScaleInv = init_calib[1:10].reshape((3, 3))
        ret.gyroScaleInv = init_calib[10:19].reshape((3, 3))
        ret.gyroGSense = init_calib[19:28].reshape((3, 3))
        ret.accelBias = init_calib[28:31].reshape((3, 1))
        ret.gyroBias = init_calib[31:34].reshape((3, 1))
        return ret

According to this code in src/tracker/imu_calib.py. The attitude.txt contained the information that should be provided in calib_state.txt?
And this may differ from the README?

calib_state.txt VIO calibration states at image rate (used in data_io.py)
[t, acc_scale_inv (9), gyr_scale_inv (9), gyro_g_sense (9), b_acc (3), b_gyr (3)]
Note: Changing calibration states from VIO.
atttitude.txt AHRS attitude from IMU
[t, qw, qx, qy, qz]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.