Git Product home page Git Product logo

rules_oidn's Introduction

Support Ukraine

rules_oidn -- Bazel build rules for Intel Open Image Denoise

Rules for using Intel Open Image Denoise in your Bazel builds.

What it does?

Open Image Denoise can be used to denoise your images. Given a noisy input image Open Image Denoise can produce a denoised output image:

Denoised

More comparison images can be found here.

rules_oidn helps you to embed Open Image Denoise 1.4.3 into your Bazel builds.

Current status

Currently, these rules compile on Ubuntu 22.04 (other Linux distributions should also work), Windows and macOS (Intel and arm64).

The goal of rules_oidn is not to reproduce a 1:1 binary compatible library that is equal to a CMake build. The focus is on the compilation of a working library that can be used in Bazel projects and is close to the CMake build. The following table compares the precompiled version of OIDN to this Bazel build:

Dependency Bazel Precompiled Open Image Denoise v1.4.3
oneDNN 2.7.3 2.2.4
Intel® Implicit SPMD Program Compiler v1.19.0 ?
ComputeLibrary 22.11 ?
oneTBB 5b2a49008c32c7ba3df7c9e137a894ff53710b64 oneTBB 2021.5.0

Quick start

Prerequisites:

The following tools should be installed:

  • Git
  • Bazel
  • A C++ compiler (GCC, Visual Studio, Clang, etc.)

Checkout, build, and run:

All platforms:

git clone https://github.com/Vertexwahn/rules_oidn.git
cd rules_oidn
cd tests

Run example with Ubuntu 22.04:

bazel run --config=gcc11 //:example

Run example with Visual Studio 2022:

bazel run --config=vs2022 //:example

Run example with macOS:

bazel run --config=macos //:example

See tests/.bazelrc for other supported build configs.

You can also provide the filenames of the input and output image as an argument, e.g. on Ubuntu 22.04:

bazel run --config=gcc11 //:example -- --input=${HOME}/rules_oidn/tests/data/cornell_box.naive_diffuse.box_filter.spp64.embree.exr --output=${HOME}/denoised_spp64.exr

More about the example

The example provides a noisy rendering of the Cornell Box.

Noisy

Additionally, there is a corresponding albedo image:

Noisy

And a normal image:

Noisy

Currently, only the noisy rendering serves as an input for the example. The albedo and normal images are not used. But the example code can be easily modified to use them.

Generating weights manually

python3 .\scripts\blob_to_cpp.py .\weights\rt_alb.tza -o .\weights\rt_alb.tza.cpp -H .\weights\rt_alb.tza.h
python3 .\scripts\blob_to_cpp.py .\weights\rt_hdr.tza -o .\weights\rt_hdr.tza.cpp -H .\weights\rt_hdr.tza.h
python3 .\scripts\blob_to_cpp.py .\weights\rt_hdr_alb.tza -o .\weights\rt_hdr_alb.tza.cpp -H .\weights\rt_hdr_alb.tza.h
python3 .\scripts\blob_to_cpp.py .\weights\rt_hdr_alb_nrm.tza -o .\weights\rt_hdr_alb_nrm.tza.cpp -H .\weights\rt_hdr_alb_nrm.tza.h
python3 .\scripts\blob_to_cpp.py .\weights\rt_hdr_calb_cnrm.tza -o .\weightsrt_hdr_calb_cnrm.tza.cpp -H .\weights\rt_hdr_calb_cnrm.tza.h
python3 .\scripts\blob_to_cpp.py .\weights\rt_ldr.tza -o .\weights\rt_ldr.tza.cpp -H .\weights\rt_ldr.tza.h
python3 .\scripts\blob_to_cpp.py .\weights\rt_ldr_alb.tza -o .\weights\rt_ldr_alb.tza.cpp -H .\weights\rt_ldr_alb.tza.h
python3 .\scripts\blob_to_cpp.py .\weights\rt_ldr_alb_nrm.tza -o .\weights\rt_ldr_alb_nrm.tza.cpp -H .\weights\rt_ldr_alb_nrm.tza.h
python3 .\scripts\blob_to_cpp.py .\weights\rt_ldr_calb_cnrm.tza -o .\weights\rt_ldr_calb_cnrm.tza.cpp -H .\weights\rt_ldr_calb_cnrm.tza.h
python3 .\scripts\blob_to_cpp.py .\weights\rt_nrm.tza -o .\weights\rt_nrm.tza.cpp -H .\weights\rt_nrm.tza.h
python3 .\scripts\blob_to_cpp.py .\weights\rtlightmap_dir.tza -o .\weights\rtlightmap_dir.tza.cpp -H .\weights\rtlightmap_dir.tza.h
python3 .\scripts\blob_to_cpp.py .\weights\rtlightmap_hdr.tza -o .\weights\rtlightmap_hdr.tza.cpp -H .\weights\rtlightmap_hdr.tza.h

Reading material

License

This work is published under the Apache 2.0 License.

Notes on copyright

This repository contains code copied from TensorFlow which is also under the Apache 2.0 License. The copyright of the corresponding files belongs to the TensorFlow authors.

rules_oidn's People

Contributors

parvit avatar vertexwahn avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

parvit

rules_oidn's Issues

Black stripes in denoised image

Note: There is a $500.00USD bounty on this issue

Apparently, there are black stripes in the denoised image:
image

Currently, the root cause for this is unclear. I opened a question about this on StackOverflow with no success so far.

I document also some of my doings and findings in some Medium posts:

How to reproduce

git clone https://github.com/Vertexwahn/rules_oidn.git
cd rules_oidn
cd tests

Run example with Ubuntu 22.04:

bazel run --config=gcc11 //:example

Run example with Visual Studio 2022:

bazel run --config=vs2022 //:example

The example takes a noisy image and denoises it.

...
int main() {
    cout << "Simple denoising example" << endl;

    Image3f color = load_image_openexr("data/cornel_box.naive_diffuse.box_filter.spp128.embree.exr");
    ...
    Image3f out{color.width(), color.height()};

    ...

    float* colorPtr = color.data();
    ...
    float* outputPtr = out.data();
    int width = out.width();
    int height = out.height();

    oidn::DeviceRef device = oidn::newDevice();
    device.set("verbose", 1);
    device.commit();

    // Create a filter for denoising a beauty (color) image using optional auxiliary images too
    oidn::FilterRef filter = device.newFilter("RT"); // generic ray tracing filter
    filter.setImage("color",  colorPtr,  oidn::Format::Float3, width, height); // beauty
    ...
    filter.setImage("output", outputPtr, oidn::Format::Float3, width, height); // denoised beauty
    filter.set("hdr", true); // beauty image is HDR
    filter.commit();

    // Filter the image
    filter.execute();

    // Check for errors
    const char* errorMessage;
    if (device.getError(errorMessage) != oidn::Error::None) {
        std::cout << "Error: " << errorMessage << std::endl;
    }

    store_open_exr("denoised.exr", out);

    return 0;
}

Unfortunately, the denoised image contains black stripes.

I tested the same input with https://github.com/DeclanRussell/IntelOIDenoiser and got the expected result (without black stripes). Therefore, the problem must be within my bazalization of OIDN or my supporting around it.

If I choose a constant color image, e.g.

// for debug reasons the color image can be initialized with a const color
if(true) { 
    for (int x = 0; x < color.width(); ++x) {
        for (int y = 0; y < color.height(); ++y) {
            color.set_pixel(x,y,.5f, .5f, .5f);
        }
    }
}

I also get black stripes.

I also created a branch of oidn that contains a "direct"
bazelization of oidn which is almost similar to rules_oidn: https://github.com/Vertexwahn/oidn/tree/add-bazel-support. In this branch I bazelized oidnTest which contains a few test cases which all pass with success. I bazelized also oidnDenoiser. You can run it via:

# the_cornell_box.pfm is in data folder in the oidn repo
bazel run --config=gcc11 //:oidnDenoise -- --hdr /home/vertexwahn/Desktop/the_cornell_box.pfm -o /home/vertexwahn/Desktop/denoised.pfm

The generated file denoised.pfm shows the same black stripes. It seems that the black stripes are always 5 pixel wide followed by 3 correct looking color stripes.

Not sure if there are any problems with handing over memory to ISPC, or doing the Filter Operation, etc. Since I tested different image formats (OpenEXR, PFM), I assume that the error is not within my way of storing images.

Expected fix

The expected fix should identify the root cause (maybe ispc_rules, some memory layout somewhere, etc.) and provide PRs to fix it. The denoised image should look identical to the CMake build. Could be that the fix will be less than 10 lines in code - maybe single line change. In the end rules_oidn should work out of the box on Windows and Ubuntut 22.04 (as it does currently - but without the black stripes) - macOS is not expected to work since this requires a different version of oneDNN which is out of the scope of this issue.

  • The solution should be a pure Bazel solution without the use of CMake. The use of rules_foreign_cc should be avoided.
  • It is expected that oneDNN is used

Support macOS

macOS build does currently not work since oneDNN build must be modified here a bit...

input/output cli options should allow relative path

(priority: low)

Status

--input=${HOME}/rules_oidn/tests/data/cornell_box.naive_diffuse.box_filter.spp64.embree.exr --output=${HOME}/denoised_spp64.exr

Expected / Standard

--input=./data/cornell_box.naive_diffuse.box_filter.spp64.embree.exr --output=denoised_spp64.exr

Use the exact same "mkl_dnn" version as cmake

Error-source:

  • oidn uses "mkl-dnn FORK(!!!) 2.2.4"
    • oidn uses a customized version of mkl-dnn
  • bazel build uses "oneDNN-2.7.1"

Confirmed

  • version 2.7.1 does not compile within original oidn source-code

Tasks

Requirements and Feasibility Analysis "Bazelizing Open Image Denoise"

(this is in context of the bounty https://app.bountysource.com/issues/117458567-black-stripes-in-denoised-image)

Article

https://medium.com/@Vertexwahn/bazelizing-open-image-denoise-part-1-the-journey-begins-a16c78ea1b88

Requirement "Bazel"

Open Image Denoise: From CMake to Bazel
The build system of Open Image Denoise is CMake. Instead of CMake I want to use Open Image Denoise using Bazel. This requires to bazelize Open Image Denoise first.

  • Is this a hard requirement (e.g. "absolutely non-disputable requirement) ?
  • what are the main 3 reasons to use bazel / to not use Cmake?

Feasibility

  • The effort to use a non-supported (by the core team) build-system for a C++ application can be excessive
    • Achieving the initial port can become a full-time problem
    • Maintenance (update to new versions) can become non-feasible

Test/Reproducer not working

The reproducer mentioned within #1 runs fine, but is looks that it does not produce any files:

PS P:\bounty\oidn\tests> bazel run --config=vs2022 //:example
[...]
Simple denoising example

Intel(R) Open Image Denoise 1.4.3@
  Compiler: Visual C++ Compiler 19.33.3163.0
  Build   : Debug
  Platform: Windows (64-bit)
  Tasking : TBB2021.9 TBB_header_interface_12090 TBB_lib_interface_12090
  Threads : 8 (affinitized)
  ISA     : AVX2
  Neural  : DNNL (oneDNN) 2.7.1

Filter: RT

It should produce "denoised.exr", but it does not.

No other file is produced.

Workaround

as a quick workaround I used ub 22.04, the file is produced there, though not at the location expected.

EDIT: same on windows

Task

(this is essentially a bug, should be fixed. At minimum, document the location)

Provide a Compatible build

(this would be more an issue for the https://github.com/Vertexwahn/oidn repo)

The current rules_oidn builds an oidn in a different manner than the original cmake build (versions, call style).

The bazel build of oidn should be as close to the original cmake build as possible.

Rationales

Execution

The existent build is refined.

This was started in context of

Some more elaborations within #1 (comment)

Provide Reference Test Reproducer

Provide a denoising that functions, based on the original oidn cmake build.

This should be as reproducible cli instructions (ideally ubuntu and windows).

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.