BachiLi / diffvg

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

tensorflow interface lags Path updates #10

Open weinman opened 3 years ago

weinman commented 3 years ago

I was hoping to adapt single_path.py to Tensorflow in the vein of single_circle_tf.py. Unfortunately I have hit a roadblock.

It seems some more recent additions to the Path shape type have not been pushed over to the pydiffvg_tensorflow interface (the learnable stroke thickness and the use_distance_approx field).

I have made a feeble attempt to emulate the changes in reflected in the pydiffvg/render_pytorch.py version, but I am coming up short of a whole grokk of this massive codebase.

(The first fix was easy).

It's possible I'm 99% there, but also possible I am way off.

@BachiLi would you want to take a stab at the update? Alternatively, would you want me to push my attempt to my fork so you can perhaps try to pick up where I've left off (particularly if it's easy!)?

Thanks!

weinman commented 3 years ago

I've added a straightforward/degenerate fix (287e71a2ac158d8c8d6d720c2904a50d22a7ca1f) that seems to work. (E.g., Run apps/single_curve_tf.py and apps/single_stroke_tf.py). However, that version does not allow for the more flexible stroke width/thickness options that seem to be supported in pytorch.

In a newer version (650c3d91a25ec9bb9fd1315de8b56da9626f7b87), I get an error I am unable to trace.

The diff is hopefully enlightening, and here is the output. Any ideas on how to get the (hopefully) last 1% operational?

$ python single_stroke_tf.py 
[...Log details elided...]
Traceback (most recent call last):
  File "single_stroke_tf.py", line 26, 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 459, in _eager_mode_decorator
    input_tensors = [ops.convert_to_tensor(x) for x
  File "/home/weinman/miniconda3/lib/python3.8/site-packages/tensorflow/python/ops/custom_gradient.py", line 459, in <listcomp>
    input_tensors = [ops.convert_to_tensor(x) for x
  File "/home/weinman/miniconda3/lib/python3.8/site-packages/tensorflow/python/profiler/trace.py", line 163, in wrapped
    return func(*args, **kwargs)
  File "/home/weinman/miniconda3/lib/python3.8/site-packages/tensorflow/python/framework/ops.py", line 1540, in convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "/home/weinman/miniconda3/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py", line 339, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
  File "/home/weinman/miniconda3/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py", line 264, in constant
    return _constant_impl(value, dtype, shape, name, verify_shape=False,
  File "/home/weinman/miniconda3/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py", line 276, in _constant_impl
    return _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
  File "/home/weinman/miniconda3/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py", line 301, in _constant_eager_impl
    t = convert_to_eager_tensor(value, ctx, dtype)
  File "/home/weinman/miniconda3/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py", line 98, in convert_to_eager_tensor
    return ops.EagerTensor(value, ctx.device_name, dtype)
ValueError: Attempt to convert a value (None) with an unsupported type (<class 'NoneType'>) to a Tensor.

(Ubuntu 18.04, Python 3.8, CUDA 10.1, CuDNN 7.6.1, Tensorflow 2.4-rc4)