From b75aa16b11ce96d7088dfaa8e7338e7ab5fa74b2 Mon Sep 17 00:00:00 2001 From: Gourieff <777@lovemet.ru> Date: Sat, 4 Nov 2023 22:37:07 +0700 Subject: [PATCH] UPDATE: CUDA Support - Full support of ORT-GPU alongside with ORT - New opton in Settings: Execution Provider selector - Many different fixes and improvements VersionUP (0.5.0 alpha2) --- .gitignore | 1 + README.md | 84 +++++++++---------------------- README_RU.md | 78 ++++++++-------------------- example/ReActor_logo_red.png | Bin 7759 -> 0 bytes example/api_example.py | 1 + example/api_external.curl | 3 +- example/api_external.json | 3 +- example/demo_crop.jpg | Bin 305397 -> 0 bytes example/example.jpg | Bin 90721 -> 0 bytes example/multiple-faces.png | Bin 15461 -> 0 bytes example/pp-order.png | Bin 31832 -> 0 bytes example/roop-off.png | Bin 13310 -> 0 bytes install.py | 57 +++++++++++++++++++-- requirements.txt | 1 - scripts/reactor_api.py | 5 +- scripts/reactor_faceswap.py | 95 +++++++++++++++++++++++------------ scripts/reactor_globals.py | 17 +++++++ scripts/reactor_helpers.py | 11 ++++ scripts/reactor_swapper.py | 44 +++++++++++----- scripts/reactor_version.py | 2 +- 20 files changed, 230 insertions(+), 172 deletions(-) delete mode 100644 example/ReActor_logo_red.png delete mode 100644 example/demo_crop.jpg delete mode 100644 example/example.jpg delete mode 100644 example/multiple-faces.png delete mode 100644 example/pp-order.png delete mode 100644 example/roop-off.png diff --git a/.gitignore b/.gitignore index 792ad62..17b7059 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ __pycache__/ example toDo.txt +last_device.txt diff --git a/README.md b/README.md index 1925068..1535b1e 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,9 @@
+
- 
+ 
- |
-
- for Any GPU
-
- - - NVIDIA / AMD / Intel - - |
-
-
- for NVIDIA GPU
- - - 8Gb VRAM or more - - - |
-
+
## Installation
@@ -100,8 +71,8 @@
2. In web-ui, go to the "Extensions" tab and use this URL `https://github.com/Gourieff/sd-webui-reactor` in the "Install from URL" tab and click "Install"
3. Please, wait for several minutes until the installation process will be finished
4. Check the last message in your SD-WebUI Console:
-* If you see the message "--- PLEASE, RESTART the Server! ---" - so, do it, stop the Server (CTRL+C or CMD+C) and start it again - or just go to the "Installed" tab (*if you have any other Roop-based extension enabled - disable it, otherwise this extension won't work*), click "Apply and restart UI"
-* If you see the message "Done!", just go to the "Installed" tab (*if you have any other Roop-based extension enabled - disable it, otherwise this extension won't work*), click "Apply and restart UI" - or you can just simply reload the UI
+* If you see the message "--- PLEASE, RESTART the Server! ---" - so, do it, stop the Server (CTRL+C or CMD+C) and start it again - or just go to the "Installed" tab, click "Apply and restart UI"
+* If you see the message "Done!", just reload the UI
5. Enjoy!
If you use [SD.Next](https://github.com/vladmandic/automatic):
@@ -113,15 +84,15 @@
5. Run SD.Next, go to the "Extensions" tab and use this URL `https://github.com/Gourieff/sd-webui-reactor` in the "Install from URL" tab and click "Install"
6. Please, wait for several minutes until the installation process will be finished
7. Check the last message in your SD.Next Console:
-* If you see the message "--- PLEASE, RESTART the Server! ---" - so, do it, stop the Server (CTRL+C or CMD+C) and start it again - or just go to the "Installed" tab (*if you have any other Roop-based extension enabled - disable it, otherwise this extension won't work*), click "Restart the UI"
-8. Stop SD.Next, go to the `automatic\extensions\sd-webui-reactor` directory - if you see there `models\insightface` folder with the file `inswapper_128.onnx`, just move the file to the `automatic\models\insightface` folder
+* If you see the message "--- PLEASE, RESTART the Server! ---" - stop the Server (CTRL+C or CMD+C) or just close your console
+8. Go to the `automatic\extensions\sd-webui-reactor` directory - if you see there `models\insightface` folder with the file `inswapper_128.onnx`, just move the file to the `automatic\models\insightface` folder
9. Run your SD.Next WebUI and enjoy!
If you use [Cagliostro Colab UI](https://github.com/Linaqruf/sd-notebook-collection):
1. In active WebUI, go to the "Extensions" tab and use this URL `https://github.com/Gourieff/sd-webui-reactor` in the "Install from URL" tab and click "Install"
2. Please, wait for several minutes until the installation process will be finished
-3. When you see the message "--- PLEASE, RESTART the Server! ---" (in your Colab Notebook Start UI section "Start Cagliostro Colab UI") - just go to the "Installed" tab and click "Apply and restart UI" (*if you have any other Roop-based extension enabled - disable it before restart, otherwise this extension won't work*)
+3. When you see the message "--- PLEASE, RESTART the Server! ---" (in your Colab Notebook Start UI section "Start Cagliostro Colab UI") - just go to the "Installed" tab and click "Apply and restart UI"
4. Enjoy!
## Features
@@ -135,6 +106,7 @@
- Ability to set the **Postprocessing order**
- **100% compatibility** with different **SD WebUIs**: Automatic1111, SD.Next, Cagliostro Colab UI
- **Fast performance** even with CPU, ReActor for SD WebUI is absolutely not picky about how powerful your GPU is
+- **CUDA** acceleration support from the version 0.5.0
- **[API](/API.md) support**: both SD WebUI built-in and external (via POST/GET requests)
- **ComfyUI [support](https://github.com/Gourieff/comfyui-reactor-node)**
- **Mac M1/M2 [support](https://github.com/Gourieff/sd-webui-reactor/issues/42)**
@@ -149,7 +121,7 @@
2. Turn on the "Enable" checkbox;
3. That's it, now the generated result will have the face you selected.
-
+
### Face Indexes
@@ -172,18 +144,18 @@ ReActor will swap a face only if it meets the given condition.
### The result face is blurry
Use the "Restore Face" option. You can also try the "Upscaler" option or for more finer control, use an upscaler from the "Extras" tab.
You can also set the postproduction order (from 0.1.0 version):
-
+
*The old logic was the opposite (Upscale -> then Restore), resulting in worse face quality (and big texture differences) after upscaling.*
### There are multiple faces in result
Select the face numbers you wish to swap using the "Comma separated face number(s)" option for swap-source and result images. You can use different index order.
-
+
### ~~The result is totally black~~
~~This means NSFW filter detected that your image is NSFW.~~
-
+
### Img2Img
@@ -191,21 +163,11 @@ You can choose to activate the swap on the source image or on the generated imag
ReActor works with Inpainting - but only the masked part will be swapped.
## API
@@ -236,7 +198,7 @@ Please, check the path where "inswapper_128.onnx" model is stored. It must be in
7. Then one-by-one:
- `pip install insightface==0.7.3`
- `pip install onnx`
- - `pip install onnxruntime`
+ - `pip install onnxruntime-gpu>=1.16.1` if you have CUDA, otherwise `pip install onnxruntime`
- `pip install opencv-python`
- `pip install tqdm`
8. Type `deactivate`, you can close your Terminal or Console and start your SD WebUI, ReActor should start OK - if not, welcome to the Issues section.
@@ -245,7 +207,7 @@ Please, check the path where "inswapper_128.onnx" model is stored. It must be in
First of all - you need to disable any other Roop-based extensions:
- Go to 'Extensions -> Installed' tab and uncheck any Roop-based extensions except this one
-
+
- Click 'Apply and restart UI'
Alternative solutions:
@@ -254,7 +216,7 @@ Alternative solutions:
### **IV. "AttributeError: 'FaceSwapScript' object has no attribute 'enable'"**
-You need to disable the "SD-CN-Animation" extension (or perhaps some another that causes the conflict)
+Probably, you need to disable the "SD-CN-Animation" extension (or perhaps some another that causes the conflict)
### **V. "INVALID_PROTOBUF : Load model from <...>\models\insightface\inswapper_128.onnx failed:Protobuf parsing failed" OR "AttributeError: 'NoneType' object has no attribute 'get'" OR "AttributeError: 'FaceSwapScript' object has no attribute 'save_original'"**
@@ -270,10 +232,10 @@ and put it to the `stable-diffusion-webui\models\insightface` replacing existing
3. Go to the (Windows)`venv\Scripts` or (MacOS/Linux)`venv/bin` run Terminal or Console (cmd) there and type `activate`
4. Then:
- `python -m pip install -U pip`
-- `pip uninstall -y onnx onnxruntime onnxruntime-gpu onnxruntime-silicon onnxruntime-extensions`
-- `pip install onnx==1.14.1 onnxruntime`
+- `pip uninstall -y onnxruntime onnxruntime-gpu onnxruntime-silicon onnxruntime-extensions`
+- `pip install onnxruntime-gpu>=1.16.1` if you have CUDA, otherwise `pip install onnxruntime`
-If it didn't help - it seems that you have another extension reinstalling `onnxruntime` when SD WebUI checks requirements. Please see your extensions list. If you find there "WD14 tagger" - try to disable it and then follow the steps above once again. This extension causes reinstalling of `onnxruntime` to `onnxruntime-gpu` or `onnxruntime==1.16.0` every time SD WebUI runs.
+
- 
+ 
- |
-
- для любых GPU
-
- - - NVIDIA / AMD / Intel - - |
-
-
- для GPU NVIDIA
- - - 8Гб VRAM или более - - - |
-
+
@@ -98,8 +72,8 @@
2. Внутри SD Web-UI перейдите во вкладку "Extensions" и вставьте ссылку `https://github.com/Gourieff/sd-webui-reactor` в "Install from URL" и нажмите "Install"
3. Пожалуйста, подождите несколько минут, пока процесс установки полностью не завершится
4. Проверьте последнее сообщение в консоли SD-WebUI:
-* Если вы видите "--- PLEASE, RESTART the Server! ---" - остановите Сервер (CTRL+C или CMD+C) и запустите его заново - ИЛИ же перейдите во вкладку "Installed" (*если у вас имееются какие-либо другие расширение, основанные на Roop или клонах ReActor - отключите их, иначе данное расширение может не работать*), нажмите "Apply and restart UI"
-* Если вы видите "Done!", перейдите во вкладку "Installed" (*если у вас имееются какие-либо другие расширение, основанные на Roop или клонах ReActor - отключите их, иначе данное расширение может не работать*), нажмите "Apply and restart UI" - или же просто перезагрузите UI, нажав на "Reload UI"
+* Если вы видите "--- PLEASE, RESTART the Server! ---" - остановите Сервер (CTRL+C или CMD+C) и запустите его заново - ИЛИ же перейдите во вкладку "Installed", нажмите "Apply and restart UI"
+* Если вы видите "Done!", просто перезагрузите UI, нажав на "Reload UI"
5. Готово!
Если вы используете [SD.Next](https://github.com/vladmandic/automatic):
@@ -111,15 +85,15 @@
5. Запустите SD.Next, перейдите во вкладку "Extensions", вставьте эту ссылку `https://github.com/Gourieff/sd-webui-reactor` в "Install from URL" и нажмите "Install"
6. Пожалуйста, подождите несколько минут, пока процесс установки полностью не завершится
7. Проверьте последнее сообщение в консоли SD.Next:
-* Если вы видите "--- PLEASE, RESTART the Server! ---" - остановите Сервер (CTRL+C или CMD+C) и запустите его заново - ИЛИ же перейдите во вкладку "Installed" (*если у вас имееются какие-либо другие расширение, основанные на Roop или клонах ReActor - отключите их, иначе данное расширение может не работать*), нажмите "Restart the UI"
-8. Остановите Сервер SD.Next, перейдите в директорию `automatic\extensions\sd-webui-reactor` - если вы видите там папку `models\insightface` с файлом `inswapper_128.onnx` внутри, переместите его в папку `automatic\models\insightface`
+* Если вы видите "--- PLEASE, RESTART the Server! ---" - остановите Сервер (CTRL+C или CMD+C) или просто закройте консоль
+8. Перейдите в директорию `automatic\extensions\sd-webui-reactor` - если вы видите там папку `models\insightface` с файлом `inswapper_128.onnx` внутри, переместите его в папку `automatic\models\insightface`
9. Готово, можете запустить SD.Next WebUI!
Если вы используете [Cagliostro Colab UI](https://github.com/Linaqruf/sd-notebook-collection):
1. В активном WebUI, перейдите во вкладку "Extensions", вставьте ссылку `https://github.com/Gourieff/sd-webui-reactor` в "Install from URL" и нажмите "Install"
2. Пожалуйста, подождите некоторое время, пока процесс установки полностью не завершится
-3. Когда вы увидите сообщение "--- PLEASE, RESTART the Server! ---" (в секции "Start UI" вашего ноутбука "Start Cagliostro Colab UI") - перейдите во вкладку "Installed" и нажмите "Apply and restart UI" (*если у вас имееются какие-либо другие расширение, основанные на Roop или клонах ReActor - отключите их, иначе данное расширение может не работать*)
+3. Когда вы увидите сообщение "--- PLEASE, RESTART the Server! ---" (в секции "Start UI" вашего ноутбука "Start Cagliostro Colab UI") - перейдите во вкладку "Installed" и нажмите "Apply and restart UI"
4. Готово!
@@ -135,6 +109,7 @@
- Возможность задать **порядок постобработки**
- **100% совместимость** с разными **SD WebUI**: Automatic1111, SD.Next, Cagliostro Colab UI
- **Отличная производительность** даже с использованием ЦПУ, ReActor для SD WebUI абсолютно не требователен к мощности вашей видеокарты
+- **Поддержка CUDA**, начиная с версии 0.5.0
- **Поддержка [API](/API.md)**: как встроенного в SD WebUI, так и внешнего (через POST/GET запросы)
- **[Поддержка](https://github.com/Gourieff/comfyui-reactor-node) ComfyUI**
- **[Поддержка](https://github.com/Gourieff/sd-webui-reactor/issues/42) компьютеров Mac M1/M2**
@@ -151,7 +126,7 @@
2. Установите флажок "Enable";
3. Готово, теперь результат будет иметь то лицо, которое вы выбрали.
-
+
### Индексы Лиц (Face Indexes)
@@ -174,18 +149,18 @@ ReActor заменит только то лицо, которое удовлет
### Если лицо получилось нечётким
Используйте опцию "Restore Face". Также можете попробовать опцию "Upscaler". Для более точного контроля параметров используйте Upscaler во вкладке "Extras".
Также вы можете установить порядок постобработки (начиная с версии 0.1.0):
-
+
*Прежняя логика была противоположенной (Upscale -> затем Restore), что приводило к более худшему качеству изображения лица (а также к значительной разнице текстур) после увеличения.*
### Результат имеет несколько лиц
Выберите номера лиц, которые нужно поменять, используя поля "Comma separated face number(s)" для исходного изображения лица и для результата. Можно устанавливать любой, необходимый вам, порядок лиц.
-
+
### ~~Результат получился чёрным~~
~~Это значит, что сработал NSFW фильтр.~~
-
+
### Img2Img
@@ -193,22 +168,11 @@ ReActor заменит только то лицо, которое удовлет
Inpainting также работает, но замена лица происходит только в области маски.
## API
@@ -241,7 +205,7 @@ Inpainting также работает, но замена лица происх
7. Далее:
- `pip install insightface==0.7.3`
- `pip install onnx`
- - `pip install onnxruntime`
+ - `pip install onnxruntime-gpu>=1.16.1` если у весть есть GPU с CUDA, иначе `pip install onnxruntime`
- `pip install opencv-python`
- `pip install tqdm`
8. Выполните `deactivate`, закройте Терминал или Консоль и запустите SD WebUI, ReActor должен запуститься без к-л проблем - если же нет, добро пожаловать в раздел "Issues".
@@ -250,7 +214,7 @@ Inpainting также работает, но замена лица происх
Для начала отключите любые другие Roop-подобные расширения:
- Перейдите в 'Extensions -> Installed' и снимите флажок с ненужных:
-
+
- Нажмите 'Apply and restart UI'
Альтернативные решения:
@@ -275,10 +239,10 @@ Inpainting также работает, но замена лица происх
3. Перейдите в (Windows)`venv\Scripts` или (MacOS/Linux)`venv/bin`, откройте Терминал или Консоль (cmd) и выполните `activate`
4. Затем:
- `python -m pip install -U pip`
-- `pip uninstall -y onnx onnxruntime onnxruntime-gpu onnxruntime-silicon onnxruntime-extensions`
-- `pip install onnx==1.14.1 onnxruntime`
+- `pip uninstall -y onnxruntime onnxruntime-gpu onnxruntime-silicon onnxruntime-extensions`
+- `pip install onnxruntime-gpu>=1.16.1` если у весть есть GPU с CUDA, иначе `pip install onnxruntime`
-Если это не помогло - значит какое-то другое расширение переустанавливает `onnxruntime` всякий раз, когда SD WebUI проверяет требования пакетов. Внимательно посмотрите список активных расширений. Если видите там "WD14 tagger" - попробуйте отключить его и ещё раз выполнить шаги выше. Это расширение вызывает переустановку `onnxruntime` на `onnxruntime-gpu` или `onnxruntime==1.16.0` при каждом запуске SD WebUI.r^`ohxVnr@S$3R0v o7&fA*&?0!D%wY2WOL`Ya@V>Zc=Bjt~OyPG1zW8$a?p`
zn^OE6z^!R_*3>?v4DDNg<1b+El$)6ndxRx^Vj1~qj!XyPh;-w2+mrZtOhqS&KaZAY
zSUk_d+(I{K0U^FPtb571O0CNTe%A3i=&qZyRQNLij6MxI$*zN4#zbucy|f%5uL0>*
zNMCc$T0jN{R;%#!T%w02VS22{f!W4|-^19G=S`pTEiI!-1^6!;#6&a*=K0Le9v?f@
z849jDtDIiSKNuLYrCHR^525qv0Y2vvti>olu@@Z1f#uE6e$B84=2W)YPlxo{cH@ MY}syGe(b`5STNAnnulm%um8M`})6RU5!#QI|$|TA`HXrw!p14yB|B$jC_a}
z?BQ6?k)oQ|)v{Xprbm;sLrzjTIMd!9=-tc-k$fiKAhG^0Pn%#qr^<|lj!hu*TCP~b
z5ce=eMbWd_DE_#3&T!|n7HzuVRSU*z4f4Hh(c{%xL(Rt+4YRo#nE6iXlXg>uZ5y1v
zl+E6tGSoNo)3>8$6`5woTXZbP2rhd4l8;=qwve65gQa|fU4`BNCp;p=35G6wwfXE-
zy=;T(`I2A|xn
zl7iNk<%{3iE$~xz({z@Z6XW@wQw#bnzq1ITj=5X{vs2QOIHQN+mwinWOr&Z0boQh$
z|9~t;E2ZUIxiG=U?R_6Yxc#RZ=bNEu-A?^25sFRFdLtT&Iiq2OdKfk0N2|zTo*=J7
zwRmf(*1enASS|NSZlR3~owPgue82Fr9=@smje$n~hcVLZ{We(u(>jbbsxdk&Qux!9
z`uDDDI?4a>^AM57C{S~IjCwh%lI9A_#6LADE#}hItzVd1l<{nP_lt{#hw|a{;;XIh
zgY?asR=
r33k04+2g*DqRkTz76BPv;8vYhHK6Ai?S-=FGQrA#+v%8rtxJA8$ZC^k
z`bR#~6E`2tKIfdMA~#CypM%^ysCzO$mKSS1_1U
t>3U
z3Wn3d&bU9*PnqmEqZz`zJPd&QU%MUjAchqCj=%7zA$t@VtyTWabwgJD=#_IXel-1V
zPkmXE0YY3HyzucfvmDbHRO8g#KHDm{yuNxe^~%WKG>(n>yx{T5Kr