Code Monkey home page Code Monkey logo

sax-nerf's Introduction

 

arXiv zhihu Youtube

PWC

PWC

A Toolbox for Sparse-View X-ray 3D Reconstruction

   

 

Introduction

This is a toolbox for X-ray novel view synthesis (NVS) and computed tomography (CT) reconstruction. This repo supports 10 state-of-the-art algorithms including 6 NeRF-based methods, 2 optimization-based methods, and 1 analytical method. We also provide code for fancy visualization and data generation to help your research. If you find this repo useful, please give it a star ⭐ and consider citing our paper. Thank you.

News

  • 2024.09.01 : Code of our ECCV 2024 work X-Gaussian has been released. Welcome to have a try! 🚀
  • 2024.07.09 : Our SAX-NeRF has been added to the Awesome-Transformer-Attention collection 💫
  • 2024.06.16 : I will present this work in person. Our poster session is from 10:30 am to 00:30 pm, Jun 20 at Arch 4A-E Poster #147. Welcome to chat with me in Seattle Convention Center. 😆
  • 2024.06.16 : More raw data and generation samples are provided. Feel free to use them.
  • 2024.06.03 : Code for traditional methods has been released. 🚀
  • 2024.06.03 : Code for fancy visualization and data generation has been released. 🚀
  • 2024.06.02 : Data, code, models, and training logs have been released. Feel free to use them :)
  • 2024.03.07 : Our new work X-Gaussian, the first 3DGS-based method for X-ray imaging, is now on arxiv now. Code, models, and training logs will be released at this repo. Stay tuned. 💫
  • 2024.02.26 : Our paper has been accepted by CVPR 2024. Code and pre-trained models will be released to the public before the start date of CVPR 2024 (2024.06.19). Stay tuned! 🎉 🎊
  • 2023.11.21 : The benchmark of X3D at the paper-with-code website has been set up. You are welcome to make a comparison. 🚀
  • 2023.11.21 : Our paper is on arxiv now. We will develop this repo into a baseline for X-ray novel view synthesis and CT reconstruction. All code, models, data, and training logs will be released. 💫

Performance

Novel View Synthesis

results1

results2

CT Reconstruction

results3

results4

Supported algorithms:

Coordinate System

The coordinate system in circular cone-beam X-ray scanning follows the OpenCV standards. The transformation between the camera, world, and image coordinate systems is shown below.

 

1. Create Environment:

We recommend using Conda to set up an environment.

# Create environment
conda create -n sax_nerf python=3.9
conda activate sax_nerf

# Install pytorch (hash encoder requires CUDA v11.3)
pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113

# Install other packages
pip install -r requirements.txt

We suggest you install TIGRE toolbox (2.3 version) for executing traditional CT reconstruction methods and synthesize your own CT data if you plan to do so. Please note that TIGRE v2.5 might stuck when CT is large.

# Download TIGRE
wget https://github.com/CERN/TIGRE/archive/refs/tags/v2.3.zip
unzip v2.3.zip
rm v2.3.zip

# Install TIGRE
pip install cython==0.29.25
pip install numpy==1.21.6
cd TIGRE-2.3/Python/
python setup.py develop

 

2. Prepare Dataset:

Download our processed datasets from Google drive or Baidu disk. Then put the downloaded datasets into the folder data/ as

  |--data
      |--chest_50.pickle
      |--abdomen_50.pickle
      |--aneurism_50.pickle
      |--backpack_50.pickle
      |--bonsai_50.pickle
      |--box_50.pickle
      |--carp_50.pickle
      |--engine_50.pickle
      |--foot_50.pickle
      |--head_50.pickle
      |--leg_50.pickle
      |--pancreas_50.pickle
      |--pelvis_50.pickle
      |--teapot_50.pickle
      |--jaw_50.pickle

 

3. Testing:

You can directly download our pre-trained models from Google drive or Baidu disk. Then put the downloaded models into the folder pretrained/ and run

# SAX-NeRF
python test.py --method Lineformer --category chest --config config/Lineformer/chest_50.yaml --weights pretrained/chest.tar --output_path output 

# FDK
python3 eval_traditional.py --algorithm fdk --category chest --config config/FDK/chest_50.yaml

# SART
python3 eval_traditional.py --algorithm sart --category chest --config config/SART/chest_50.yaml

# ASD_POCS
python3 eval_traditional.py --algorithm asd_pocs --category chest --config config/ASD_POCS/chest_50.yaml

For your convenience, we provide the reconstructed results in Google drive and Baidu disk.

 

4. Training:

We provide the training logs on all scenes for your convenience to debug. Please download the training logs from Google dive or Baidu disk.

# SAX-NeRF
python train_mlg.py --config config/Lineformer/chest_50.yaml

# NeRF
python train.py --config config/nerf/chest_50.yaml

# Intratomo
python train.py --config config/intratomo/chest_50.yaml

# NAF
python train.py --config config/naf/chest_50.yaml

# TensoRF
python train.py --config config/tensorf/chest_50.yaml

You can use this repo to run NeAT. Remember to reprocess the data first.

 

5. Visualization

To render a cool demo, we provide visualization code in the folder 3D_vis

cd 3D_vis
python 3D_vis_backpack.py
python 3D_vis_backpack_gif.py

 

6. Generate Your Own Data

We also provide code for data generation in the folder dataGenerator. To give you a quick start, we provide the raw data for your debugging. Please download the raw data from Google dive or Baidu disk and then put them into the folder dataGenerator/raw_data. Run

cd dataGenerator
python data_vis_backpack.py
cd ..
python dataGenerator/generateData_backpack.py

 

7. Citation

If this repo helps you, please consider citing our works:

# SAX-NeRF
@inproceedings{sax_nerf,
  title={Structure-Aware Sparse-View X-ray 3D Reconstruction},
  author={Yuanhao Cai and Jiahao Wang and Alan Yuille and Zongwei Zhou and Angtian Wang},
  booktitle={CVPR},
  year={2024}
}

# X-Gaussian
@inproceedings{x_gaussian,
  title={Radiative gaussian splatting for efficient x-ray novel view synthesis},
  author={Yuanhao Cai and Yixun Liang and Jiahao Wang and Angtian Wang and Yulun Zhang and Xiaokang Yang and Zongwei Zhou and Alan Yuille},
  booktitle={ECCV},
  year={2024}
}

sax-nerf's People

Contributors

caiyuanhao1998 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

sax-nerf's Issues

How to train using 2D RGB X-ray images

Is it possible to use this framework on 2D RGB X-ray images instead of CT scans?

Here are my data specifications and I want to know if it is sensible and possible to train it using your designs:

  1. Collection of 2D rgb xray images
  2. Lacks camera parameters
  3. Dynamic in nature

About hardware requirements (GPU)

Thanks for sharing your wonderful project !!
I was really looking forward to reading the scripts.

I would like to ask about the hardware requirements for training a model.
In your paper, you mentioned that all experiments were performed on RTX8000 (VRAM: 48GB).
How much VRAM does it take, for example, python train_mlg.py --config config/Lineformer/chest_50.yaml ?
With V100 (VRAM: 16GB), I got an OOM error.

I would appreciate it if you could let me know.
Thank you in advance.

About generating private datasets

Hello! The img.mat file was missing when running generatedata_backpack.py. Could you upload this data, please? FileNotFoundError: [Errno 2] No such file or directory: './dataGenerator/raw_data/backpack/img.mat' In addition, if I want to use a nii.gz format CT file to generate a training set, what should I do? I found in the generatedata.py code that the input CT needs a dictionary, which contains a lot of information.

Testing FDK error No TIGREDataset_Traditional function

Thanks for sharing your awesome project!
I try to run python3 eval_traditional.py --algorithm fdk --category chest --config config/FDK/chest_50.yaml .
But retrun some error
Traceback (most recent call last): File "/workspace/SAX-NeRF/eval_traditional.py", line 9, in <module> from src.evaluator import Evaluator File "/workspace/SAX-NeRF/src/evaluator.py", line 5, in <module> from .dataset import TIGREDataset_Traditional as Dataset ImportError: cannot import name 'TIGREDataset_Traditional' from 'src.dataset' (/workspace/SAX-NeRF/src/dataset/__init__.py)
It seems like there is no function called TIGREDataset_Traditional。

Hash encoder requires CUDA v11.3

So Nice to share the code.
I tried to follow the author's instructions to install CUDA = v11.3, and then followed a series of environment installations. But I encountered an error:


from .backend import _backend
File "/ai4hh/ai4h/mawen/Project/SAX-NeRF-master/src/encoder/hashencoder/backend.py", line 18, in
_backend = load(name='_hash_encoder',
File "/home/wenma/anaconda3/envs/sax_nerf/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 1144, in load return _jit_compile(
File "/home/wenma/anaconda3/envs/sax_nerf/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 1357, in _jit_compile
_write_ninja_file_and_build_library(
File "/home/wenma/anaconda3/envs/sax_nerf/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 1469, in _write_ninja_file_and_build_library
_run_ninja_build(
File "/home/wenma/anaconda3/envs/sax_nerf/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 1756, in _run_ninja_build
raise RuntimeError(message) from e

RuntimeError: Error building extension '_hash_encoder': [1/3] /usr/bin/nvcc
nvcc fatal : Unsupported gpu architecture 'compute_86'
ninja: build stopped: subcommand failed.

And
ninja --version = 1.11.1.git.kitware.jobserver-1
gcc & g++ version = 9.4.0
nvcc: 11.3

Who can save this child...

Question regarding the X3D dataset.

I appreciate the excellence of your research.
Upon reading the paper, I was wondering when I could download the X3D dataset used in the paper.
Or could you provide information on where the dataset can be downloaded?

Thank you for good research.

SAX-NeRF Testing

Hello.
I am encountering an error while testing with test.py. It seems to be a compilation-related message. How should I resolve it?
1

Raw data convert

Dear author,
If my raw data are in nii format, how could I convert them to the suitable form for SAX-NeRF, or what parameters should I stay the same?

Custom dataset

Hello!
I appreciate your research.
Your research has led to some interesting collaborations.

The data we use is too big, so we are trying to reshape it to 256256256 size like the sample you provided.
However, if we set it to 204820482160, an error occurs.
What does the z-axis mean here? What should go in place of 2160?

In addition, are there any parameters to keep in mind when using a custom dataset?
Below is our Dicom data.

Scan
Scan mode: CT
2048 Number of Detector Elements
2160 CT: Number of Projections
19 DR: Number of Lines
1 Linebinning Settings
1 Pixelbinning Settings
Measurement extension: none
1 Multi-Scan: Number of Slices
184.20 Multi Slice: Distance between two Slices [mm]
2.14 Magnification (Object Center)
0.09366268 2D-Pixel Size [mm]
0.09366286 3D-XY-Pixel Size [mm]
0.09514938 3D-Z-Pixel Size [mm]
1 CT: Number of Slices

Detector
Detector Type: Y.XRD1621
409.60 Detectorlength

Reconstruction
2048 Number of actual Detector Pixel
2048 Image Dimension
2016 Number of Z-slices
2160 Number of Projections
0.00 Rotational Offset in degree
Dose Rate Correction: on
0.00000000 Center Offset [Pixel]
0.00000000 Center Offset [mm]
1.00 Convolution Coefficient
409.60 ROI [mm]

Axis
257.12 X-Axis: Measurement Position [mm]
750.00 Y-Axis: Measurement Position [mm]
1225.60 YD-Axis: Measurement Position [mm]
281.00 ZS-Axis: Measurement Position [mm]
1225.60 Focus-Detector distance [mm]
651.64 Object-Detector distance [mm]
573.97 Focus-Object distance [mm]
500.00 Integration Time [ms] for CT and DR

X-Ray
X-Ray-Tube: MF X-Ray-Tube
Tube head: D-Target FXE 225.99 (48)
185.00 Voltage [kV]
0.49 Current [mA]
Focus: small
TXI: on
SecondTubeHead: off

Filter
Al 0.50 [mm]
Cu 0.00 [mm]
Sn 0.00 [mm]
Fe 0.00 [mm]

Remarks

Curiosity | Performance on dynamic data

Hi Authors,

Thank you for deploying the code. It's really helpful to have all architectures in one place. I have a question about how your models would perform on dynamic data. Is it possible to incorporate a temporal aspect into the existing architecture, considering that my data modality changes with time?

Training Time Comparison

Nice Work!

I have run your code on the Chest-50 data. I find that your proposed LineFormer requires much more training time than other methods. Specifically, your LineFormer requires about 6 hours for 1500 epochs while Naf only requires about 15 minutes.

Could you please provide more details about why LineFormer requires a much longer training process? Is it because LineFormer has more parameters or is it related to MLG sampling strategy?

One view 2D x-ray image to 3D images

Hello. Thank you for your great job!
I have a question for your code.

I try to convert a 2D x-ray image (only one view) to 3D images.
I just want to know if your code has this function or not.
If it has, then,
do the training data also only require only one view 2D x-ray image?

About your strategies

A great work on CT reconstruction.
I wanna ask a question. The strategies you developed in your paper: lineformer and MLG, are they suitable for natural scenes, i.e. RGB NeRF? It seems that they are not specific for X-rays.

Error with generating own data using TIGRE

Hi, thanks for sharing this awesome project!

I have already generated .mat file.
However, when I try to run 'python dataGenerator/generateData_backpack.py', I got the following errors as shown below. I followed the steps for downloading and installing TIGRE exactly without any errors during those steps. Is there any effective way to solve this problem? Thanks a lot!

image

Code release

Great work! Are there any plans to release the code?

SAX-NeRF in colab

Hello,

Apparently, SAX-NeRF code requires cuda 11.3, which seems suprising as it looks to be built on naf hash encoder that I could run on cuda 12.2. In colab, the default version is 12.2, and it is not convenient to modify that. Do you know if there is any solution to run your code in colab?

Here is what I obtain when running the code:
No CUDA runtime is found, using CUDA_HOME='/usr/local/cuda'
/usr/local/lib/python3.10/dist-packages/torch/utils/cpp_extension.py:1967: UserWarning: TORCH_CUDA_ARCH_LIST is not set, all archs for visible cards are included for compilation.
If this is not desired, please set os.environ['TORCH_CUDA_ARCH_LIST'].
warnings.warn(
Traceback (most recent call last):
File "/content/drive/MyDrive/SAX-NeRF/train_mlg.py", line 23, in
from src.trainer_mlg import Trainer
File "/content/drive/MyDrive/SAX-NeRF/src/trainer_mlg.py", line 17, in
from .encoder import get_encoder
File "/content/drive/MyDrive/SAX-NeRF/src/encoder/init.py", line 1, in
from .hashencoder import HashEncoder
File "/content/drive/MyDrive/SAX-NeRF/src/encoder/hashencoder/init.py", line 1, in
from .hashgrid import HashEncoder
File "/content/drive/MyDrive/SAX-NeRF/src/encoder/hashencoder/hashgrid.py", line 8, in
from .backend import _backend
File "/content/drive/MyDrive/SAX-NeRF/src/encoder/hashencoder/backend.py", line 6, in
_backend = load(name='_hash_encoder',
File "/usr/local/lib/python3.10/dist-packages/torch/utils/cpp_extension.py", line 1309, in load
return _jit_compile(
File "/usr/local/lib/python3.10/dist-packages/torch/utils/cpp_extension.py", line 1719, in _jit_compile
_write_ninja_file_and_build_library(
File "/usr/local/lib/python3.10/dist-packages/torch/utils/cpp_extension.py", line 1819, in _write_ninja_file_and_build_library
_write_ninja_file_to_build_library(
File "/usr/local/lib/python3.10/dist-packages/torch/utils/cpp_extension.py", line 2206, in _write_ninja_file_to_build_library
cuda_flags = common_cflags + COMMON_NVCC_FLAGS + _get_cuda_arch_flags()
File "/usr/local/lib/python3.10/dist-packages/torch/utils/cpp_extension.py", line 1987, in _get_cuda_arch_flags
arch_list[-1] += '+PTX'
IndexError: list index out of range

Thank you for your time.
Quentin

SAX-NeRF testing error

python : 3.9
cuda : 11.3
pytorch : 1.10
torch.cuda.is_available() : true

I an trying to run testing about part of sax-nerf which does not work, could you have a look please? thanks

Traceback (most recent call last):
  File "C:\3dgs\SAX-NeRF\test.py", line 29, in <module>
    from src.encoder import get_encoder
  File "C:\3dgs\SAX-NeRF\src\encoder\__init__.py", line 1, in <module>
    from .hashencoder import HashEncoder
  File "C:\3dgs\SAX-NeRF\src\encoder\hashencoder\__init__.py", line 1, in <module>
    from .hashgrid import HashEncoder
  File "C:\3dgs\SAX-NeRF\src\encoder\hashencoder\hashgrid.py", line 8, in <module>
    from .backend import _backend
  File "C:\3dgs\SAX-NeRF\src\encoder\hashencoder\backend.py", line 6, in <module>
    _backend = load(name='_hash_encoder',
  File "C:\Anaconda\envs\test\lib\site-packages\torch\utils\cpp_extension.py", line 1144, in load
    return _jit_compile(
  File "C:\Anaconda\envs\test\lib\site-packages\torch\utils\cpp_extension.py", line 1357, in _jit_compile
    _write_ninja_file_and_build_library(
  File "C:\Anaconda\envs\test\lib\site-packages\torch\utils\cpp_extension.py", line 1456, in _write_ninja_file_and_build_library
    _write_ninja_file_to_build_library(
  File "C:\Anaconda\envs\test\lib\site-packages\torch\utils\cpp_extension.py", line 1857, in _write_ninja_file_to_build_library
    cuda_flags = common_cflags + COMMON_NVCC_FLAGS + _get_cuda_arch_flags()
  File "C:\Anaconda\envs\test\lib\site-packages\torch\utils\cpp_extension.py", line 1626, in _get_cuda_arch_flags
    arch_list[-1] += '+PTX'
IndexError: list index out of range```

image saving problem

when using imageio to save image ,P.S. in this sentence specificlly iio.imwrite(osp.join(proj_pred_origin_dir, f"proj_pred_{str(i)}.png"), (cast_to_image(projs_pred[i])*255).astype(np.uint8))
there comes the problem of Can't write images with one color channel. How can this be solved?like using cv instead?

About line size of the Lineformer

In all the config files of the experiments, you set the line size as 2 for the Lineformer network, which means only the self-attention between 2 points is considered. I also try line size 4 and 8, but actually 2 is best. However, it is counter-intuitive and strange that self-attention between 2 points is good enough for reconstruction. Generally, I think more points considered will achieve better results. Can you explain why you choose 2 as the line size?

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.