Skip to content

Switch to patchmatch-cython from pypatchmatch due to default availability on more platforms#8788

Open
aleyan wants to merge 4 commits intoinvoke-ai:mainfrom
aleyan:pmc
Open

Switch to patchmatch-cython from pypatchmatch due to default availability on more platforms#8788
aleyan wants to merge 4 commits intoinvoke-ai:mainfrom
aleyan:pmc

Conversation

@aleyan
Copy link
Contributor

@aleyan aleyan commented Jan 26, 2026

Summary

pypatchmatch has a dependency on OpenCV, which is tricky to install and/or compile on many platforms. This replaces it for another patchmatch implementation with cython wheels prebuilt for most common platforms.

Related Issues / Discussions

Closes #8781

QA Instructions

Saw "patchmatch" option appear in canvas Compositing/Infill. Generates infill.

Merge Plan

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Tests added / updated (if applicable)
  • ❗Changes to a redux slice have a corresponding migration
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)

@github-actions github-actions bot added python PRs that change python files Root backend PRs that change backend files python-deps PRs that change python dependencies labels Jan 26, 2026
@aleyan aleyan changed the title Switch to patchmatch-cython from py patchmatch due to default availability on more platforms Switch to patchmatch-cython from pypatchmatch due to default availability on more platforms Jan 26, 2026
@iwr-redmond
Copy link

The Dockerfiles for CUDA and ROCm will also need to be updated.

@aleyan
Copy link
Contributor Author

aleyan commented Jan 26, 2026

The Dockerfiles for CUDA and ROCm will also need to be updated.

Removed building of patchmatch in Dockerfiles. Kept the installing of libopencv-dev, but it is not clear to me if opencv bindings are needed anymore.

@iwr-redmond
Copy link

iwr-redmond commented Jan 26, 2026

OpenCV is still recommended for patchmatch-cython and is required for invisible-watermark.

See also: launcher#81

@aleyan
Copy link
Contributor Author

aleyan commented Jan 27, 2026

OpenCV is still recommended for patchmatch-cython and is required for invisible-watermark.

See also: launcher#81

Ok, based on that, I will keep the opencv bindings in the Dockerfiles.

Are any other changes required?

@lstein lstein added the v6.12.0 Intended for 6.12.0 release label Jan 29, 2026
@lstein lstein moved this from 6.12.x to 6.13.x in Invoke - Community Roadmap Jan 30, 2026
@lstein lstein added v6.13.x and removed v6.12.0 Intended for 6.12.0 release labels Jan 30, 2026
@dunkeroni
Copy link
Collaborator

Seems to be working, about 3.1x faster than the pypatchmatch version, but I get significantly worse results with it. Outputs are choppy and frequently show horizontal black lines 1 pixel wide. Also, results are no longer deterministic.

@dunkeroni
Copy link
Collaborator

Is there a way to make patchmatch-cython work as well as the pypathmatch implementation that we have?
image

@iwr-redmond
Copy link

Looking at the PR code and the patchmatch-cython readme, it appears that cv2 needs to be added. Perhaps this explains the quality reduction?

@aleyan
Copy link
Contributor Author

aleyan commented Feb 6, 2026

@dunkeroni
This is worse than I experienced locally. Is the demo image just patchmatch without any model going over it?

On determinism, patchmatch-cython can take a seed value. I will hard code that to 0, but we may consider passing in the seed from the workflow.

@aleyan
Copy link
Contributor Author

aleyan commented Feb 7, 2026

I don't know how to test old patchmatch implementation because I could never get it to build (hence the motivation to get the cython one in).

I have made the following changes:

  1. Set the seed on patchmatch to 0, so that the output is deterministic.
  2. Increased the PATCH_SIZE from 3 to 5. This seems to have decreased the amount of small pixel noise.
  3. Changed the alpha threshold from 255 to 128, which seemed to have gotten rid of some 0,0,0-black lines and patch noise in the patchmatch output.

@dunkeroni Can you please test it out again?

@iwr-redmond I investigated this, patchmatch-cython will use opencv automatically, if cv2 is available, which it is.

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

Labels

backend PRs that change backend files docker python PRs that change python files python-deps PRs that change python dependencies Root v6.13.x

Projects

Status: 6.13.x

Development

Successfully merging this pull request may close these issues.

[enhancement]: Switch to patchmatch-cython

4 participants