Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(WIN32)
find_package(Python 3.6 COMPONENTS Development REQUIRED)
find_package(Python 3.9 COMPONENTS Development REQUIRED)
else()
find_package(Python 3.7 COMPONENTS Development REQUIRED)
find_package(Python 3.9 COMPONENTS Development REQUIRED)
endif()
add_subdirectory(pybind11)

option(DIFFVG_CUDA "Build diffvg with GPU code path?" ON)

if(DIFFVG_CUDA)
message(STATUS "Build with CUDA support")
find_package(CUDA 10 REQUIRED)
find_package(CUDA 11 REQUIRED)
set(CMAKE_CUDA_STANDARD 11)
if(NOT WIN32)
# Hack: for some reason the line above doesn't work on some Linux systems.
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -std=c++11")
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -std=c++14")
#set(CUDA_NVCC_FLAGS_DEBUG "-g -G")
endif()
else()
Expand Down Expand Up @@ -94,7 +94,7 @@ if(APPLE)
# multiple Python installed. If we link a particular Python version
# here, and we import it with a different Python version later.
# likely a segmentation fault.
# The solution for Linux Mac OS machines, as mentioned in
# The solution for Linux Mac OS machines, as mentioned in
# https://github.com/pybind/pybind11/blob/master/tools/pybind11Tools.cmake
# is to not link against Python library at all and resolve the symbols
# at compile time.
Expand All @@ -118,7 +118,7 @@ elseif(APPLE)
set_target_properties(diffvg PROPERTIES INSTALL_RPATH "@loader_path")
endif()

set_property(TARGET diffvg PROPERTY CXX_STANDARD 11)
set_property(TARGET diffvg PROPERTY CXX_STANDARD 14)
set_target_properties(diffvg PROPERTIES PREFIX "")
# Still enable assertion in release mode
string( REPLACE "/DNDEBUG" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
Expand Down
5 changes: 3 additions & 2 deletions apps/gaussian_blur.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import scipy.ndimage.filters as F


def render(canvas_width, canvas_height, shapes, shape_groups):
def render(canvas_width, canvas_height, shapes, shape_groups, backward_clamp_gradient_mag=None):
_render = pydiffvg.RenderFunction.apply
scene_args = pydiffvg.RenderFunction.serialize_scene(\
canvas_width, canvas_height, shapes, shape_groups)
Expand All @@ -15,7 +15,8 @@ def render(canvas_width, canvas_height, shapes, shape_groups):
2, # num_samples_x
2, # num_samples_y
0, # seed
None,
None, # background_image
backward_clamp_gradient_mag,
*scene_args)
return img

Expand Down
7 changes: 4 additions & 3 deletions apps/generative_models/mnist_vae.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,17 @@ def _onehot(label):
return label_onehot.float()


def render(canvas_width, canvas_height, shapes, shape_groups, samples=2):
def render(canvas_width, canvas_height, shapes, shape_groups, samples=2, backward_clamp_gradient_mag=None):
_render = pydiffvg.RenderFunction.apply
scene_args = pydiffvg.RenderFunction.serialize_scene(
canvas_width, canvas_height, shapes, shape_groups)
img = _render(canvas_width,
canvas_height,
samples,
samples,
0,
None,
0, # seed
None, # background_image
backward_clamp_gradient_mag,
*scene_args)
return img

Expand Down
3 changes: 2 additions & 1 deletion apps/generative_models/rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


def render(canvas_width, canvas_height, shapes, shape_groups, samples=2,
seed=None):
seed=None, backward_clamp_gradient_mag=None):
if seed is None:
seed = random.randint(0, 1000000)
_render = pydiffvg.RenderFunction.apply
Expand All @@ -21,6 +21,7 @@ def render(canvas_width, canvas_height, shapes, shape_groups, samples=2,
img = _render(canvas_width, canvas_height, samples, samples,
seed, # seed
None, # background image
backward_clamp_gradient_mag,
*scene_args)
return img

Expand Down
5 changes: 3 additions & 2 deletions apps/render_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import torch as th


def render(canvas_width, canvas_height, shapes, shape_groups):
def render(canvas_width, canvas_height, shapes, shape_groups, backward_clamp_gradient_mag=None):
_render = pydiffvg.RenderFunction.apply
scene_args = pydiffvg.RenderFunction.serialize_scene(\
canvas_width, canvas_height, shapes, shape_groups)
Expand All @@ -16,7 +16,8 @@ def render(canvas_width, canvas_height, shapes, shape_groups):
2, # num_samples_x
2, # num_samples_y
0, # seed
None,
None, # background_image
backward_clamp_gradient_mag,
*scene_args)
return img

Expand Down
5 changes: 3 additions & 2 deletions apps/seam_carving.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def carve_seam(im):
return new_im


def render(canvas_width, canvas_height, shapes, shape_groups, samples=2):
def render(canvas_width, canvas_height, shapes, shape_groups, samples=2, backward_clamp_gradient_mag=None):
_render = pydiffvg.RenderFunction.apply
scene_args = pydiffvg.RenderFunction.serialize_scene(\
canvas_width, canvas_height, shapes, shape_groups)
Expand All @@ -116,7 +116,8 @@ def render(canvas_width, canvas_height, shapes, shape_groups, samples=2):
samples, # num_samples_x
samples, # num_samples_y
0, # seed
None,
None, # background_image
backward_clamp_gradient_mag,
*scene_args)
return img

Expand Down
5 changes: 3 additions & 2 deletions apps/svg_brush.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ def checkerboard(shape, square_size=2):
res=bin*np.array([[[1., 1., 1.,]]])+(1-bin)*np.array([[[.75, .75, .75,]]])
return torch.tensor(res,requires_grad=False,dtype=torch.float32)

def render(optim, viewport):
def render(optim, viewport, backward_clamp_gradient_mag=None):
scene_args = pydiffvg.RenderFunction.serialize_scene(*optim.build_scene())
render = pydiffvg.RenderFunction.apply
img = render(viewport[0], # width
viewport[1], # height
2, # num_samples_x
2, # num_samples_y
0, # seed
None,
None, # background_image
backward_clamp_gradient_mag,
*scene_args)
return img

Expand Down
5 changes: 3 additions & 2 deletions apps/texture_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def texture_syn(img_path):
return np.array(target_img)


def render(canvas_width, canvas_height, shapes, shape_groups, samples=2):
def render(canvas_width, canvas_height, shapes, shape_groups, samples=2, backward_clamp_gradient_mag=None):
_render = pydiffvg.RenderFunction.apply
scene_args = pydiffvg.RenderFunction.serialize_scene(\
canvas_width, canvas_height, shapes, shape_groups)
Expand All @@ -42,7 +42,8 @@ def render(canvas_width, canvas_height, shapes, shape_groups, samples=2):
samples, # num_samples_x
samples, # num_samples_y
0, # seed
None,
None, # background_image
backward_clamp_gradient_mag,
*scene_args)
return img

Expand Down
Loading