Skip to main content

Trainable Joint Bilateral Filter Layer (PyTorch)

Project description

This repository implements a GPU-accelerated trainable joint bilateral filter layer (guidance image + three spatial and one range filter dimension) that can be directly included in any Pytorch graph, just as any conventional layer (FCL, CNN, …). By calculating the analytical derivative of the joint bilateral filter with respect to its parameters, the guidance image, and the input, the (so far) hyperparameters can be automatically optimized via backpropagation for a calculated loss.

Our corresponding paper Trainable Joint Bilateral Filters for Enhanced Prediction Stability in Low-dose CT can be found on arXiv (pre-print).

Citation:

If you find our code useful, please cite our work

@article{wagner2022trainable,
  title={Trainable Joint Bilateral Filters for Enhanced Prediction Stability in Low-dose CT},
  author={Wagner, Fabian and Thies, Mareike and Denzinger, Felix and Gu, Mingxuan and Patwari, Mayank and Ploner, Stefan and Maul, Noah and Pfaff, Laura and Huang, Yixing and Maier, Andreas},
  journal={arXiv preprint arXiv:2207.07368},
  year={2022},
  doi={https://arxiv.org/abs/2207.07368}
 }

Setup:

The C++/CUDA implemented forward and backward functions are compiled via the setup.py script using setuptools:

  1. Create and activate a python environment (python>=3.7).

  2. Install Torch (tested versions: 1.7.1, 1.9.0).

  3. Install the joint bilateral filter layer via pip:

pip install jointbilateralfilter_torch

In case you encounter problems with 3. install the layer directly from our GitHub repository:

  1. Download the repository.

  2. Navigate into the extracted repo.

  3. Compile/install the joint bilateral filter layer by calling

python setup.py install

Example scripts:

  • Can be found in our GitHub repository

  • Try out the forward pass by running the example_filter.py (requires Matplotlib and scikit-image).

  • Run the gradcheck.py script to verify the correct gradient implementation.

  • Run example_optimization.py to optimize the parameters of a joint bilateral filter layer to automatically denoise an image.

Optimized joint bilateral filter prediction:

https://github.com/faebstn96/trainable-joint-bilateral-filter-source/blob/main/out/example_optimization.png?raw=true

Implementation:

The general structure of the implementation follows the PyTorch documentation for creating custom C++ and CUDA extensions. The forward pass implementation of the layer is based on code from the Project MONAI framework, originally published under the Apache License, Version 2.0. The correct implementation of the analytical forward and backward pass can be verified by running the gradcheck.py script, comparing numerical gradients with the derived analytical gradient using the PyTorch built-in gradcheck function.

Troubleshooting

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jointbilateralfilter_torch-1.0.0.tar.gz (20.4 kB view details)

Uploaded Source

File details

Details for the file jointbilateralfilter_torch-1.0.0.tar.gz.

File metadata

File hashes

Hashes for jointbilateralfilter_torch-1.0.0.tar.gz
Algorithm Hash digest
SHA256 29cce6457901b82288c501c1df5f10694e46e7c866991258a2dd5dd2268a94bb
MD5 732a53391dbce488e4a42eea6d6f2807
BLAKE2b-256 1b607f5f2746f60c8d43b30f43c7a57496c07808d3f6ff0199471da317a85a0a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page