2022-12-01 23:17:07 +00:00
|
|
|
---
|
|
|
|
title: Installing PyPatchMatch
|
|
|
|
---
|
|
|
|
|
2023-01-01 20:52:05 +00:00
|
|
|
# :material-image-size-select-large: Installing PyPatchMatch
|
2022-12-01 23:17:07 +00:00
|
|
|
|
2023-01-01 20:52:05 +00:00
|
|
|
pypatchmatch is a Python module for inpainting images. It is not needed to run
|
|
|
|
InvokeAI, but it greatly improves the quality of inpainting and outpainting and
|
|
|
|
is recommended.
|
2022-12-01 23:17:07 +00:00
|
|
|
|
2023-01-01 20:52:05 +00:00
|
|
|
Unfortunately, it is a C++ optimized module and installation can be somewhat
|
|
|
|
challenging. This guide leads you through the steps.
|
2022-12-01 23:17:07 +00:00
|
|
|
|
|
|
|
## Windows
|
|
|
|
|
2023-01-01 20:52:05 +00:00
|
|
|
You're in luck! On Windows platforms PyPatchMatch will install automatically on
|
|
|
|
Windows systems with no extra intervention.
|
2022-12-01 23:17:07 +00:00
|
|
|
|
|
|
|
## Macintosh
|
|
|
|
|
2023-01-19 02:44:00 +00:00
|
|
|
You need to have opencv installed so that pypatchmatch can be built:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
brew install opencv
|
|
|
|
```
|
|
|
|
|
2023-03-10 02:03:11 +00:00
|
|
|
The next time you start `invoke`, after successfully installing opencv, pypatchmatch will be built.
|
2022-12-01 23:17:07 +00:00
|
|
|
|
|
|
|
## Linux
|
|
|
|
|
2023-01-01 20:52:05 +00:00
|
|
|
Prior to installing PyPatchMatch, you need to take the following steps:
|
2022-12-01 23:17:07 +00:00
|
|
|
|
2022-12-07 21:33:09 +00:00
|
|
|
### Debian Based Distros
|
|
|
|
|
2022-12-01 23:17:07 +00:00
|
|
|
1. Install the `build-essential` tools:
|
|
|
|
|
2023-01-01 20:52:05 +00:00
|
|
|
```sh
|
|
|
|
sudo apt update
|
|
|
|
sudo apt install build-essential
|
|
|
|
```
|
2022-12-01 23:17:07 +00:00
|
|
|
|
|
|
|
2. Install `opencv`:
|
|
|
|
|
2023-01-01 20:52:05 +00:00
|
|
|
```sh
|
|
|
|
sudo apt install python3-opencv libopencv-dev
|
|
|
|
```
|
2022-12-01 23:17:07 +00:00
|
|
|
|
2023-01-19 02:44:00 +00:00
|
|
|
3. Activate the environment you use for invokeai, either with `conda` or with a
|
2023-01-01 20:52:05 +00:00
|
|
|
virtual environment.
|
|
|
|
|
2023-01-19 02:44:00 +00:00
|
|
|
4. Install pypatchmatch:
|
2023-01-01 20:52:05 +00:00
|
|
|
|
|
|
|
```sh
|
2023-01-19 02:44:00 +00:00
|
|
|
pip install pypatchmatch
|
2023-01-01 20:52:05 +00:00
|
|
|
```
|
|
|
|
|
2023-01-19 02:44:00 +00:00
|
|
|
5. Confirm that pypatchmatch is installed. At the command-line prompt enter
|
2023-01-01 20:52:05 +00:00
|
|
|
`python`, and then at the `>>>` line type
|
2023-03-10 02:03:11 +00:00
|
|
|
`from patchmatch import patch_match`: It should look like the following:
|
2023-01-01 20:52:05 +00:00
|
|
|
|
|
|
|
```py
|
2023-09-28 13:28:41 +00:00
|
|
|
Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] on linux
|
2023-01-01 20:52:05 +00:00
|
|
|
Type "help", "copyright", "credits" or "license" for more information.
|
|
|
|
>>> from patchmatch import patch_match
|
|
|
|
Compiling and loading c extensions from "/home/lstein/Projects/InvokeAI/.invokeai-env/src/pypatchmatch/patchmatch".
|
|
|
|
rm -rf build/obj libpatchmatch.so
|
|
|
|
mkdir: created directory 'build/obj'
|
|
|
|
mkdir: created directory 'build/obj/csrc/'
|
|
|
|
[dep] csrc/masked_image.cpp ...
|
|
|
|
[dep] csrc/nnf.cpp ...
|
|
|
|
[dep] csrc/inpaint.cpp ...
|
|
|
|
[dep] csrc/pyinterface.cpp ...
|
|
|
|
[CC] csrc/pyinterface.cpp ...
|
|
|
|
[CC] csrc/inpaint.cpp ...
|
|
|
|
[CC] csrc/nnf.cpp ...
|
|
|
|
[CC] csrc/masked_image.cpp ...
|
|
|
|
[link] libpatchmatch.so ...
|
|
|
|
```
|
2022-12-01 23:17:07 +00:00
|
|
|
|
2022-12-07 21:33:09 +00:00
|
|
|
### Arch Based Distros
|
2022-12-01 23:17:07 +00:00
|
|
|
|
2022-12-07 21:33:09 +00:00
|
|
|
1. Install the `base-devel` package:
|
2023-01-01 20:52:05 +00:00
|
|
|
|
|
|
|
```sh
|
|
|
|
sudo pacman -Syu
|
|
|
|
sudo pacman -S --needed base-devel
|
|
|
|
```
|
2022-12-07 21:33:09 +00:00
|
|
|
|
2023-06-26 12:23:10 +00:00
|
|
|
2. Install `opencv` and `blas`:
|
2022-12-07 21:33:09 +00:00
|
|
|
|
2023-01-01 20:52:05 +00:00
|
|
|
```sh
|
2023-06-26 12:23:10 +00:00
|
|
|
sudo pacman -S opencv blas
|
2023-01-01 20:52:05 +00:00
|
|
|
```
|
2022-12-07 21:33:09 +00:00
|
|
|
|
2023-01-01 20:52:05 +00:00
|
|
|
or for CUDA support
|
2022-12-07 21:33:09 +00:00
|
|
|
|
2023-01-01 20:52:05 +00:00
|
|
|
```sh
|
2023-06-26 12:23:10 +00:00
|
|
|
sudo pacman -S opencv-cuda blas
|
2023-01-01 20:52:05 +00:00
|
|
|
```
|
2023-06-26 12:23:10 +00:00
|
|
|
|
2023-01-01 20:52:05 +00:00
|
|
|
3. Fix the naming of the `opencv` package configuration file:
|
2022-12-01 23:17:07 +00:00
|
|
|
|
2023-01-01 20:52:05 +00:00
|
|
|
```sh
|
|
|
|
cd /usr/lib/pkgconfig/
|
|
|
|
ln -sf opencv4.pc opencv.pc
|
|
|
|
```
|
2022-12-01 23:17:07 +00:00
|
|
|
|
2023-01-01 20:52:05 +00:00
|
|
|
[**Next, Follow Steps 4-6 from the Debian Section above**](#linux)
|
|
|
|
|
2023-03-10 02:03:11 +00:00
|
|
|
If you see no errors you're ready to go!
|