BachiLi / diffvg

Differentiable Vector Graphics Rasterization
https://people.csail.mit.edu/tzumao/diffvg/
Apache License 2.0
923 stars 155 forks source link

single_circle_tf.py calls to pydiffvg_tensorflow.render missing argument #7

Closed weinman closed 3 years ago

weinman commented 3 years ago

The calls to render in the Tensorflow example single_circle_tf.py (here, here, here, and here) are missing an argument.

Under the hood, it seems to be in position 8 (starting from 0), but in the python it's probably position 5. Based on another recent commit (5b65ad38b1768a3c0dfad7a02c4a19b73dda0dac), it's presumably the background image.

I attempted to resolve this in the same way the Torch examples did, by inserting a None in that position, but that led to a different error.

Edit: I think the error is probably deeper within, probably an issue with how render_tensorflow.py calls diffvg.render (i.e., here and here?).

I'd be happy to submit a PR myself to update/fix this if anyone can tell me what to insert as the appropriate place holder somewhere.

Here's the relevant stack trace (Ubuntu 18.04, CUDA 10.1, Python 3.8, Tensorflow v2.4.0-rc1):

Traceback (most recent call last):
  File "./single_circle_tf.py", line 18, in <module>
    img = render(tf.constant(256), # width
  File "/home/weinman/miniconda3/lib/python3.8/site-packages/tensorflow/python/ops/custom_gradient.py", line 261, in __call__
    return self._d(self._f, a, k)
  File "/home/weinman/miniconda3/lib/python3.8/site-packages/tensorflow/python/ops/custom_gradient.py", line 215, in decorated
    return _eager_mode_decorator(wrapped, args, kwargs)
  File "/home/weinman/miniconda3/lib/python3.8/site-packages/tensorflow/python/ops/custom_gradient.py", line 438, in _eager_mode_decorator
    result, grad_fn = f(*args, **kwargs)
  File "/home/weinman/miniconda3/lib/python3.8/site-packages/diffvg-0.0.1-py3.8-linux-x86_64.egg/pydiffvg_tensorflow/render_tensorflow.py", line 475, in render
    img, ctx = forward(width, height, num_samples_x, num_samples_y, seed, *args)
  File "/home/weinman/miniconda3/lib/python3.8/site-packages/diffvg-0.0.1-py3.8-linux-x86_64.egg/pydiffvg_tensorflow/render_tensorflow.py", line 425, in forward
    diffvg.render(scene,
TypeError: render(): incompatible function arguments. The following argument types are supported:
    1. (arg0: diffvg.Scene, arg1: diffvg.float_ptr, arg2: diffvg.float_ptr, arg3: diffvg.float_ptr, arg4: int, arg5: int, arg6: int, arg7: int, arg8: int, arg9: diffvg.float_ptr, arg10: diffvg.float_ptr, arg11: diffvg.float_ptr, arg12: diffvg.float_ptr, arg13: bool, arg14: diffvg.float_ptr, arg15: int) -> None

Invoked with: <diffvg.Scene object at 0x7f1df8bdd630>, <diffvg.float_ptr object at 0x7f1dac31b770>, <diffvg.float_ptr object at 0x7f1d846ec7f0>, <tf.Tensor: shape=(), dtype=int32, numpy=256>, <tf.Tensor: shape=(), dtype=int32, numpy=256>, 2, 2, <tf.Tensor: shape=(), dtype=int32, numpy=0>, <diffvg.float_ptr object at 0x7f1d846eccb0>, <diffvg.float_ptr object at 0x7f1d846eccf0>, <diffvg.float_ptr object at 0x7f1d846ecd30>, False

Thanks for this wonderful work!