Giter VIP home page Giter VIP logo

ref-npr's Introduction

Reference-Based Non-Photorealistic Radiance Fields for Controllable Scene Stylization (CVPR2023)

This is the official implementation of the Ref-NPR paper

  • Ref-NPR: Reference-Based Non-Photorealistic Radiance Fields for Controllable Scene Stylization
    Yuechen Zhang, Zexin He, Jinbo Xing, Xufeng Yao, Jiaya Jia
    IEEE Conference on Computer Vision and Pattern Recognition (CVPR) 2023
    [ arXiv ] [ Project Page ] [ BibTeX ] [ Video ] [ Data ]

Ref-NPR is a powerful tool for single-image scene stylization, allowing users to create stylized versions of scenes based on a given stylized view. The stylized view can be generated through various methods, including hand drawings, 2D image stylization techniques, or text-driven controllable generation (e.g., using ControlNet). Ref-NPR is also compatible with 3D objects represented in NeRF (Neural Radiance Fields) format.

Sourse Content Hand Drawing
Style Image
ControlNet
"Chinese Painting"
ControlNet
"Kyoto Animation"

For more examples, please refer our gallary in the project page.

Quick start

1. Install environment & Data download

bash ./create_env.sh
bash ./download_data.sh

2. (Optional) Photo-Realistic training (rendering) on all scenes

You can also utilize your pre-trained Plenoxel models with Ref-NPR. If you prefer not to apply basic PhotoRealistic (PR) models to all scenes, you can skip directly to step 3. This will automatically execute the appropriate PR model for the given scene.

cd opt
bash ../exps/base_pr/run_all_bases_syn.sh
bash ../exps/base_pr/run_all_bases_llff.sh
bash ../exps/base_pr/run_all_bases_tnt.sh

3. Run Ref-NPR

# Ref-NPR: 
# run_single.sh [style folder] [epoch_multi=2] [out_dir=./exps/refnpr]
bash ./exps/refnpr/run_single.sh ./data/ref_case/flower_colorful/

The optimized artistic radiance field is inside exps/refnpr/flower_control/exp_out, while the photorealistic one is inside opt/base_pr/ckpt_svox2/[scene_name(flower)].


(Optional) In addition to Ref-NPR, we provide implementations of ARF and SNeRF for comparison purposes. Please note that our SNeRF implementation is not the official version, as it is not open-sourced. We use Gatys' stylization module as a substitute in our SNeRF implementation.

# ARF: 
# run_single.sh [style folder] [epoch_multi=2] [out_dir=./exps/arf]
bash ./exps/arf/run_single.sh ./data/ref_case/flower_colorful/

# SNeRF: 
# run_single.sh [style folder] [epoch_multi=1] [out_dir=./exps/snerf]
bash ./exps/snerf/run_single.sh ./data/ref_case/flower_colorful/

4. Customization on own data

Training base on your own scene data:
Please follow the steps on Plenoxel to prepare your own custom training content data.

Use your own style reference:
If you want to customize your own style example, you can create a reference case follow the format as this:

├── data
│   ├── ref_case
│   │   ├── ref_case_1
│   │   │   ├── style.png
│   │   │   ├── data_config.json
│   │   ├── ref_case_2
│   │   │   ├── style.png
│   │   │   ├── data_config.json
└── ...

Here is an example of data_config.json. Please be noted that one of ["tmpl_idx_train", "tmpl_idx_test"] should be set to null.


To get content from training set, you can choose the image from training dataset. We provide a simple script to choose the content image and build a config. Inside this script, a dictionary is used to select scene and image.

python ./exps/ref_get_example.py

To get the test sequence content, you can run scripts ../exps/base_pr/render_all_bases_[dataset_name].sh (or part of it for a specific scene).

{
  "dataset_type": "llff",           # dataset type in ["llff", "synthetic", "tnt"]
  "scene_name": "flower",           # scene name in your used dataset
  "style_img": "./data/ref_case/flower_control/style.png", # path to reference image
  "tmpl_idx_train": null,           # index if you use a *TRAINING* set image as reference.
  "tmpl_idx_test": 112,             # index if you use a *TEST* set image as reference.
  "color_pre": true,                # whether enable the color matching loss [default true]
  "style_name": "flower_control"    # case name for output folders.
}

For multi-reference case, just use a list to store the style image and indexes:

{
  ...
  "style_img": ["./data/ref_case/playground/style_049.png",
                "./data/ref_case/playground/style_088.png",
                "./data/ref_case/playground/style_157.png"],
  "tmpl_idx_train": [49, 88, 157],
  ...
}

Citation

@inproceedings{
      zhang2023refnpr,
      title={Ref-{NPR}: Reference-Based Non-Photorealistic Radiance Fields for Controllable Scene Stylization},
      author={Zhang, Yuechen and He, Zexin and Xing, Jinbo and Yao, Xufeng and Jia, Jiaya},
      booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
      year={2023}
}

Acknowledgement and References:

This repository is built based on ARF. We would like to thank authors of Plenoxel and ARF for open-sourcing their wonderful implementations.

ref-npr's People

Contributors

julianjuaner avatar zexinhe 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

ref-npr's Issues

the size of controlnet

hi~thanks for your excellent work🤣
I also use controlnet to generate the truck in snow, but unfortunately, I can't use refnpr to get satisfactory results.
I want to know if the problem is that controlnet generates images that are integer multiples of 64 in length and width, and then resizing them to the same size as the original image results in this error.
I would also like to ask you how to use controlnet to get an image of the same size as the reference image.

style_image_0_tnt

truck_0132

Could you share your ckpt file?

I attempted the third step to render, but encountered the following error. Could you share your ckpt file? Thanks!

FileNotFoundError: [Errno 2] No such file or directory: './exps/refnpr/flower_colorful/exp_out/ckpt.npz/ckpt.npz'

no ckpt.npz

Hi,thanks your amazing work.There is a problem.
No such file or directory:'./exps/base_pr/ckpt_svox2/llff/flower/ckpt.npz
Can you share your ckpt.npz?Thanks a lot.

Failed building wheel for svox2

Importing svox2 package under RefNPR environment will report the following error. But I can import svox2 package under base environment.
image

How can I obtain the ckpt file for testing purposes?

Hello, thank you for your excellent work. I'd be happy to help you with the issues you're encountering.

When I run the command bash ../exps/base_pr/run_all_bases_llff.sh, I encounter the following error:
AttributeError: 'NoneType' object has no attribute 'dict'
How can I resolve this?

When I skip the second step and proceed to the third step, it says I'm missing the ckpt file.
FileNotFoundError: [Errno 2] No such file or directory: './exps/refnpr/flower_colorful/exp_out/ckpt.npz/ckpt.npz'
How can I obtain the ckpt file for testing purposes?

A problem in ref_regist.py file

When I was training the ref-npr model, I met such a traceback:

Traceback (most recent call last):
File "./exps/refnpr/ref_regist.py", line 145, in
xyz_min = torch.minimum(xyz_min, torch.min(xyz_pos[depth_rep!=0].reshape(-1, 3), dim=0)[0])
IndexError: min(): Expected reduction dim 0 to have non-zero size.

It seems that for some dataset, during the iteration, depth_rep can be all 0 and xyz_pos[depth_rep] can therefore be torch.tensor([]).
How can I sovle the issue, can I firstly check torch.any(depth_rep) to deside whether running the following codes? Like:

if torch.any(depth_rep):
        xyz_min = torch.minimum(xyz_min, torch.min(xyz_pos[depth_rep!=0].reshape(-1, 3), dim=0)[0])
        xyz_max = torch.maximum(xyz_max, torch.max(xyz_pos[depth_rep!=0].reshape(-1, 3), dim=0)[0])
else:
        pass

Besides, xyz_min and xyz_max seems to stay stationary before the error occurs.

No such file or directory: './exps/refnpr/flower_colorful/exp_out/ckpt.npz/ckpt.npz'

I have successfully run Step 1 and 2. But when I run Step 3:bash ./exps/refnpr/run_single.sh ./data/ref_case/flower_colorful/, I meet the error that: "FileNotFoundError: [Errno 2] No such file or directory: './exps/refnpr/flower_colorful/exp_out/ckpt.npz/ckpt.npz'.

I found that in Step 2, I have got the file "./exps/base_pr/ckpt_svox2/llff/flower/ckpt.npz"
BUT in Sep 3, I need the file './exps/refnpr/flower_colorful/exp_out/ckpt.npz/ckpt.npz', which is not generated before.

An issue about svox2

Great work! I currently have trouble with the code. When I run the code (at step 2 and step 3), there is always a traceback:
Traceback (most recent call last):
File "opt.py", line 471, in
eval_step()
File "opt.py", line 406, in eval_step
rgb_pred_test = grid.volume_render_image(cam, use_kernel=True)
File "....../anaconda3/envs/RefNPR/lib/python3.8/site-packages/svox2/svox2.py", line 1210, in volume_render_image
and imrend_fn_name in _C.dict
AttributeError: 'NoneType' object has no attribute 'dict'
How can I solve the issue, is there a problem when creating the environment? Thank you so much!

result on tnt dataset

Congratulations on Your excellent work, but I find the result on tnt dataset is bad. The image cannot reconstruct well in the first stage. Could you please check the result.

metrics computation

Hi, I wonder how did you compute your robustness metric and Ref-LPIPS as mentioned in Figure B.1.
I noticed you compute PSNR, SSIM and LPIPS in calc_metric.py but that seems to be computed on stylized view and original view images. Did you provide codes that work for what you mentioned in Figure B.1. and Table 1? Thanks very much.

Ray Registration

Hi author,

Thanks for posting the work. I have quick question about ray registration. From Line 227, it seems that the dictionary is a tensor that can only store a single ray. In case of multiple rays falling into a single grid, the grid will be overwritten by the latest ray.
Is that correct?

position_dict[index_int[:, 0], index_int[:, 1], index_int[:, 2]] = xyz_batch

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.