Skip to content

Can't backward through a transformation matrix #101

Description

@simoncozens

I'm guessing this project is pretty dead given the lack of updates, but filing this in case it bites someone else the way it bit me: if you're using a transformation matrix (the shape_to_canvas parameter to pydiffvg.ShapeGroup), gradients don't get transformed using the matrix. An obvious symptom of this is: if you flip the coordinate space upside down using a matrix, the updates to the shape will push it down when they should push it up and vice versa.

e.g. replacing

path_group = pydiffvg.ShapeGroup(shape_ids = torch.tensor([0]),
fill_color = torch.tensor([0.3, 0.6, 0.3, 1.0]))

with

transform = torch.tensor(
    [
        [1.0, 0.0, 0.0],
        [0.0, -1.0, 256.0],
        [0.0, 0.0, 1.0],
    ]
)
path_group = pydiffvg.ShapeGroup(
    shape_ids=torch.tensor([0]),
    fill_color=torch.tensor([0.3, 0.6, 0.3, 1.0]),
    shape_to_canvas=transform,
)

loss will increase, and the final result will look like this:

Image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions