BachiLi / diffvg

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

Resolve crash in 'backward' when a background image with only 3 channels is passed to 'forward' #49

Closed daniel347x closed 1 year ago

daniel347x commented 1 year ago

The existing code adds the fourth channel to the background image directly inside 'forward'.

However, this breaks back propagation because Torch's autograd framework records the shapes of all inputs to the 'forward' function and expects shapes passed to 'backward' to match. By adding a channel to the background image directly inside 'forward' and passing this to 'backward', there is an extra channel that autograd does not expect, and it raises an error, crashing the program.

The resolution is to instead raise an exception directly at the point the channel miscount is detected in 'forward', with a useful error message for the end user that they need to add a channel of all ones to the background image before passing it to the 'forward' function.

BachiLi commented 1 year ago

Thanks!