Coder Social home page Coder Social logo

event_cnn_minimal's Introduction

event_cnn_minimal

Minimal code for running inference on models trained for Reducing the Sim-to-Real Gap for Event Cameras, ECCV'20.

Running with Anaconda

cuda_version=10.1

conda create -y -n event_cnn python=3.7
conda activate event_cnn
conda install -y pytorch torchvision cudatoolkit=$cuda_version -c pytorch
conda install -y -c conda-forge opencv
conda install -y -c conda-forge tqdm
conda install -y -c anaconda h5py 
conda install -y -c intel pandas
conda install -y -c anaconda scikit-image
pip install thop --user

As a further prerequisite, you will need to have ROS installed on your system. Make sure not to source your ROS and Conda envs at the same time, as they conflict.

Usage

Clone this repo and submodules:

git clone -b inference [email protected]:TimoStoff/event_cnn_minimal.git --recursive
cd event_cnn_minimal/events_contrast_maximization/
git checkout master
cd ..

Conversion to HDF5

This code processes the events in HDF5 format. To convert the rosbags to this format, open a new terminal and source a ROS workspace.

source /opt/ros/kinetic/setup.bash
python events_contrast_maximization/tools/rosbag_to_h5.py <path/to/rosbag/or/dir/with/rosbags> --output_dir <path/to/save_h5_events> --event_topic <event_topic> --image_topic <image_topic>

As an example, using slider_depth from "The event camera dataset and simulator":

wget http://rpg.ifi.uzh.ch/datasets/davis/slider_depth.bag -O /tmp/slider_depth.bag
source /opt/ros/kinetic/setup.bash
python events_contrast_maximization/tools/rosbag_to_h5.py /tmp/slider_depth.bag --output_dir /tmp/h5_events --event_topic /dvs/events --image_topic /dvs/image_raw

If you have access to events from a color event camera, you need to set image_topic to the topic containing events and a flag --is_color. For example, using carpet_simple.bag:

python events_contrast_maximization/tools/rosbag_to_h5.py /tmp/simple_carpet.bag --image_topic /dvs/image_color --is_color

Inference

Download the pretrained models from here, into event_cnn_minimal.

To estimate reconstruction:

python inference.py --checkpoint_path <path/to/model.pth> --device 0 --h5_file_path </path/to/events.h5> --output_folder </path/to/output/dir>

For example:

python inference.py --checkpoint_path pretrained/reconstruction/reconstruction_model.pth --device 0 --h5_file_path /tmp/h5_events/slider_depth.h5 --output_folder /tmp/reconstruction

To estimate flow:

python inference.py --checkpoint_path <path/to/model.pth> --device 0 --h5_file_path </path/to/events.h5> --output_folder </path/to/output/dir> --is_flow

For example:

python inference.py --checkpoint_path pretrained/flow/flow_model.pth --device 0 --h5_file_path /tmp/h5_events/slider_depth.h5 --output_folder /tmp/flow --is_flow

Flow is saved as both a png showing HSV color as slow vectors and as npy files. Should look something like this: Reconstruction Flow Color

We provide some of our more recent models for download. These models are prefixed with update (ie: update_flow_model.pth). These models have not necessarily been quantitatively evaluated and are not necessarily better than the models reported on in the paper Reducing the Sim-to-Real Gap for Event Cameras. If you wish to run these models, the flag --update is necessary, as the voxels are formed in a slightly different way in the updated models. Again, the models from the paper are the ones without the prefix 'update'.

Training dataset

You will need to generate the training dataset yourself, using ESIM. To find out how, please see the training data generator repo.

Training

To train a model, you need to create a config file (see config/config.json for an example). In this file, you need to set what model you would like to use (you can choose from several models from the literature such as EVFlowNet etc, see the files in model/ for more. You also need to set the training parameters, the training data, the validation data and the output directory. To train the flow network and reconstruction network from the paper, see config/flow.json and config/reconstruction.json respectively. You can then start the training by invoking

python train.py --config path/to/config

If you have a model that would like to keep training from, you can use

python train.py --config path/to/config --resume /path/to/model.pth

Citations

Please cite the following if you decide to use this code in an academic context:

@Article{stoffregen2020eccv,
    title={Reducing the Sim-to-Real Gap for Event Cameras},
    author={Timo Stoffregen and Cedric Scheerlinck and Davide Scaramuzza and Tom Drummond and Nick Barnes and Lindsay Kleeman and Robert Mahony},
    journal=eccv,
    year=2020,
    month=aug
}

event_cnn_minimal's People

Contributors

cedric-scheerlinck avatar fedepare avatar timostoff avatar tobias-fischer 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

event_cnn_minimal's Issues

Evaluation code

is evaluation code available with the mentioned pretrained model

FireNet+

This is more of a question than an issue.

Besides E2VID+, could you also provide your FireNet+ model?

Thanks a lot in advance!

Problems encountered when training data

Hello!
Thank you for your outstanding work!

I successfully downloaded the HQF dataset and configured the environment you introduced.

But I encountered a problem when cloning the repo and submodules.
fatal: The remote branch inference is not found in the upstream origin
Then I manually downloaded the branch code and put it into the folder.

I want to retrain your network using the HQF dataset to replicate your work. I have converted all the rosbag data to h5 format.
Due to my stupidity, I did not understand what is contained in the data_file /tmp/extracted_data/data_file.txt in the config.json file.
Following the prompt, I filled in the location of the h5 format dataset here, but encountered an error.

~/event_cnn_minimal-master$ python train.py --config config/reconstruction.json 
Traceback (most recent call last):
  File "train.py", line 107, in <module>
    main(config)
  File "train.py", line 56, in main
    data_loader = config.init_obj('data_loader', module_data)
  File "/home/gp/event_cnn_minimal-master/parse_config.py", line 93, in init_obj
    return getattr(module, module_name)(*args, **module_args)
  File "/home/gp/event_cnn_minimal-master/data_loader/data_loaders.py", line 25, in __init__
    dataset = concatenate_datasets(data_file, SequenceDataset, sequence_kwargs)
  File "/home/gp/event_cnn_minimal-master/utils/data.py", line 38, in concatenate_datasets
    data_paths = pd.read_csv(data_file, header=None).values.flatten().tolist()
  File "/home/gp/anaconda3/envs/event_cnn/lib/python3.7/site-packages/pandas/io/parsers.py", line 605, in read_csv
    return _read(filepath_or_buffer, kwds)
  File "/home/gp/anaconda3/envs/event_cnn/lib/python3.7/site-packages/pandas/io/parsers.py", line 457, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
  File "/home/gp/anaconda3/envs/event_cnn/lib/python3.7/site-packages/pandas/io/parsers.py", line 814, in __init__
    self._engine = self._make_engine(self.engine)
  File "/home/gp/anaconda3/envs/event_cnn/lib/python3.7/site-packages/pandas/io/parsers.py", line 1045, in _make_engine
    return mapping[engine](self.f, **self.options)  # type: ignore[call-arg]
  File "/home/gp/anaconda3/envs/event_cnn/lib/python3.7/site-packages/pandas/io/parsers.py", line 1893, in __init__
    self._reader = parsers.TextReader(self.handles.handle, **kwds)
  File "pandas/_libs/parsers.pyx", line 518, in pandas._libs.parsers.TextReader.__cinit__
  File "pandas/_libs/parsers.pyx", line 717, in pandas._libs.parsers.TextReader._get_header
  File "pandas/_libs/parsers.pyx", line 814, in pandas._libs.parsers.TextReader._tokenize_rows
  File "pandas/_libs/parsers.pyx", line 1943, in pandas._libs.parsers.raise_parser_error
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte
== Timing statistics ==

I should have filled in the wrong parameters.

Looking forward to your reply, thank you for your help.

Different evaluation result using the pretrained weight!

I am trying to evaluate the pretrained model reconstruction_model.pth based on the inference.py. But the result is much different to that in paper even when only looking at the MSE? Please help!

Below is my results on HQF:

+--------------------------------------------------------------------------------------------------------------+
|                                                Results on HQF                                                |
+-------------------------+-----------------------------+--------------------------+---------------------------+
|         Sequence        | p_loss/reconstruction_model | mse/reconstruction_model | ssim/reconstruction_model |
+-------------------------+-----------------------------+--------------------------+---------------------------+
|     bike_bay_hdr.h5     |            0.298            |          0.036           |            0.48           |
+-------------------------+-----------------------------+--------------------------+---------------------------+
|         boxes.h5        |            0.264            |          0.049           |           0.497           |
+-------------------------+-----------------------------+--------------------------+---------------------------+
|       desk_fast.h5      |            0.211            |          0.032           |           0.584           |
+-------------------------+-----------------------------+--------------------------+---------------------------+
|         desk.h5         |            0.191            |          0.028           |           0.567           |
+-------------------------+-----------------------------+--------------------------+---------------------------+
|    desk_hand_only.h5    |            0.344            |          0.045           |           0.567           |
+-------------------------+-----------------------------+--------------------------+---------------------------+
|       desk_slow.h5      |            0.227            |          0.038           |            0.6            |
+-------------------------+-----------------------------+--------------------------+---------------------------+
|  engineering_posters.h5 |            0.314            |          0.041           |            0.48           |
+-------------------------+-----------------------------+--------------------------+---------------------------+
|  high_texture_plants.h5 |            0.163            |          0.026           |           0.544           |
+-------------------------+-----------------------------+--------------------------+---------------------------+
|    poster_pillar_1.h5   |            0.269            |          0.032           |           0.467           |
+-------------------------+-----------------------------+--------------------------+---------------------------+
|    poster_pillar_2.h5   |            0.239            |          0.026           |            0.49           |
+-------------------------+-----------------------------+--------------------------+---------------------------+
| reflective_materials.h5 |            0.288            |           0.04           |           0.497           |
+-------------------------+-----------------------------+--------------------------+---------------------------+
|  slow_and_fast_desk.h5  |            0.236            |          0.041           |           0.562           |
+-------------------------+-----------------------------+--------------------------+---------------------------+
|       slow_hand.h5      |            0.317            |          0.048           |           0.489           |
+-------------------------+-----------------------------+--------------------------+---------------------------+
|      still_life.h5      |            0.247            |          0.038           |           0.525           |
+-------------------------+-----------------------------+--------------------------+---------------------------+
|           Mean          |      0.2577142857142857     |   0.03714285714285714    |     0.5249285714285714    |
+-------------------------+-----------------------------+--------------------------+---------------------------+

While the result in paper is:
image

Training time

Hello! I have a question about time.
gpu=1, batch_size=2, sequence_length=40
Training on the data set simulated by coco according to the above parameters, how long did it take you to get the best results?

question about H5 files

Nice work!@TimoStoff
Due to the ubuntu version is 18.04, I got a few questions of converting bag files to h5 files. I don't know if I have the honor to get access to the HQF dataset by HDF5 format directly rather than rosbag format. THKS

link to training data

Congratulations to this great work.

You stated that the training data is open-source, as part of your contribution.

However, when I follow your link for datasets, it seems that it only shows the HQF dataset? Where can I find the training data.

Thanks

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.