-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix python binding, add pytorch integration and supports denoising gp…
…u tensors (#46) * fix py binding for newer version of python * add gpu denoise implementation
- Loading branch information
Showing
17 changed files
with
167 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
if (DEFINED ENV{TORCH_INSTALL_DIR} OR DEFINED TORCH_INSTALL_DIR) | ||
if (DEFINED ENV{TORCH_INSTALL_DIR}) | ||
set( KRR_PYTORCH_ROOT $ENV{TORCH_INSTALL_DIR} CACHE PATH "PyTorch installation directory.") | ||
else() | ||
set( KRR_PYTORCH_ROOT ${TORCH_INSTALL_DIR} CACHE PATH "PyTorch installation directory.") | ||
endif() | ||
message(STATUS "Found PyTorch installation at ${KRR_PYTORCH_ROOT}.") | ||
SET(KRR_ENABLE_PYTORCH ON CACHE INTERNAL "Enable pytorch-interop support.") | ||
else() | ||
message(STATUS "Did not find pytorch. If you want to enable pytorch-interop support, specify its installation location via TORCH_INSTALL_DIR.") | ||
SET(KRR_ENABLE_PYTORCH OFF CACHE INTERNAL "Enable pytorch-interop support.") | ||
endif() | ||
|
||
if (KRR_ENABLE_PYTORCH) | ||
set(TORCH_BIN_DIR | ||
${KRR_PYTORCH_ROOT}/lib | ||
) | ||
set(TORCH_LIBS | ||
${TORCH_BIN_DIR}/c10.lib | ||
${TORCH_BIN_DIR}/c10_cuda.lib | ||
${TORCH_BIN_DIR}/torch.lib | ||
${TORCH_BIN_DIR}/torch_cpu.lib | ||
${TORCH_BIN_DIR}/torch_cuda.lib | ||
${TORCH_BIN_DIR}/torch_python.lib | ||
) | ||
set(TORCH_INCLUDE_DIRS | ||
${KRR_PYTORCH_ROOT}/include | ||
${KRR_PYTORCH_ROOT}/include/torch/csrc/api/include | ||
) | ||
#c10_cuda.lib torch_cpu.lib torch_cuda.lib | ||
add_library(torch_lib INTERFACE) | ||
target_include_directories(torch_lib INTERFACE ${TORCH_INCLUDE_DIRS}) | ||
target_link_libraries(torch_lib INTERFACE ${TORCH_LIBS}) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import os | ||
import sys | ||
import torch | ||
import argparse | ||
|
||
try: import numpy as np | ||
except: raise Exception("Install numpy for manipulating arrays.") | ||
|
||
from krr import * | ||
import pykrr | ||
|
||
def denoise_tensor(rgb:torch.Tensor, normals:torch.Tensor=None, albedo:torch.Tensor=None)->np.array: | ||
if normals is not None: | ||
assert (rgb.shape == normals.shape) | ||
if albedo is not None: | ||
assert (rgb.shape == albedo.shape) | ||
return pykrr.denoise_torch_tensor(rgb.astype(np.float32), normals, albedo) | ||
|
||
if __name__ == "__main__": | ||
a = torch.rand(size=[720, 1280, 3]) | ||
print(a) | ||
b = denoise_tensor(a) | ||
print(b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "py.h" | ||
#include "common.h" | ||
|
||
KRR_NAMESPACE_BEGIN | ||
|
||
PYBIND11_MODULE(pykrr_common, m) { | ||
// used to find necessary dlls... | ||
m.attr("vulkan_root") = KRR_VULKAN_ROOT; | ||
m.attr("pytorch_root") = KRR_PYTORCH_ROOT; | ||
} | ||
|
||
KRR_NAMESPACE_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#pragma once | ||
|
||
#include "common.h" | ||
#include "krrmath/math.h" | ||
#include "util/math_utils.h" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters