Code Monkey home page Code Monkey logo

sd-webui-topaz-photo-ai-integration's Introduction

Topaz Photo AI integration

This extension integrates Topaz Photo AI upscaling feature into stable-diffusion-webui. So you can use it inside hires fix, upscaler_for_img2img or in extras tab. You need to have Topaz Photo AI of version >= 2.1.3 (do not confuse with topaz gigapixel), and provide a path to tpai.exe usually located in C:\Program Files\Topaz Labs LLC\Topaz Photo AI in --topaz-photo-ai-exe cmd flag of webui

Also there are Sharpe and Denoise features in extras tab

To copy path to file in Windows, you need to press right mouse click holding "Shift" button (or not, depends on OS version), and select "Copy file as path"

For Linux

If you use Linux, you need to write a script, which launches tpai.exe via wine, with all arguments passing. E.g.

#!/bin/bash
cd "$(dirname "$0")"
export WINEDEBUG=-all
export DXVK_LOG_LEVEL=warn
wine <path to tpai.exe> "$@"
rc=$?
exit $rc

You can install winetricks and run winetricks -q dxvk to allow topaz to see your gpu. But it won't work because dxvk doesn't support directx12 (directml) which is required. Vkd3d in winesticks does support it partially, gpu is utilized, but the image is blured and glitched, so it isn't a proper directml support

For portable version

If you use a portable version of Topaz Photo AI, you need to write a wrapper script which replaces Topaz Photo AI.exe with tpai.exe and starts portable version, and set path to this script instead

For Linux:

#!/bin/bash
cd "$(dirname "$0")"
export WINEDEBUG=-all
export DXVK_LOG_LEVEL=warn
if [ ! -f 'App/Topaz Photo AI/Topaz Photo AI_.exe' ]; then
    mv 'App/Topaz Photo AI/Topaz Photo AI.exe' 'App/Topaz Photo AI/Topaz Photo AI_.exe'
    mv 'App/Topaz Photo AI/tpai.exe' 'App/Topaz Photo AI/Topaz Photo AI.exe'
fi
xvfb-run wine PhotoAIportable.exe "$@"
rc=$?
if [ ! -f 'App/Topaz Photo AI/tpai.exe' ]; then
    mv 'App/Topaz Photo AI/Topaz Photo AI.exe' 'App/Topaz Photo AI/tpai.exe'
    mv 'App/Topaz Photo AI/Topaz Photo AI_.exe' 'App/Topaz Photo AI/Topaz Photo AI.exe'
fi
exit $rc

xvfb-run is not necessary, it's used for hiding cmd.exe window. Can be installed by sudo yay -S xorg-server-xvfb on Arch-based, or sudo apt install xvfb on Ubuntu-based

For Windows a similar script will work but bad with admin right request and cmd window every time. So don't use portable version in Windows

Just in case, this extension is more about fun, and adding topaz in webui just because it's possibe. If you want to get free models with similar quality, you can use 4x-Nomos8kHAT-L-otf and 4x-FaceUpDAT, place them into models/DAT directory, or even you can try StableSR

Btw in some cases Topaz shows the best quality among dedicated upscaling models. And it's significantly faster even on cpu if you need only 2x upscale of a big image

but StableSR is still better

And the fastest in pair with turbo model

sd-webui-topaz-photo-ai-integration's People

Contributors

light-and-ray avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sd-webui-topaz-photo-ai-integration's Issues

Error during upscaling

'C:\\Program Files\\Topaz Labs LLC\\Topaz Photo AI\\tpai.exe' --output C:\Users\RGWyo\AppData\Local\Temp\tmpox33m9gu --override --upscale scale=2 --face_recovery enabled=false C:\Users\RGWyo\AppData\Local\Temp\tmp98qxng2w\file.jpg
Checking if log directory should be pruned. Currently have 11 log files.
Number of logs exceeds max number to keep ( 10 ). Cleaning excess logs.
QObject::moveToThread: Cannot move objects with a parent
Logger initialized
Error | Invalid token structure QList("")
Change the following settings within the preferences panel in the app
Application settings:
  Overwrite Files: 0
  Recurse Directories: 0
  Input File Count: 1
  Output Folder: C:\Users\RGWyo\AppData\Local\Temp\tmpox33m9gu
  Output Format: Preserve
  Jpeg quality: 95
  Png compression level: 2
  Tiff compression: none
  Tiff bit depth: 16
Autopilot settings:
  Auto apply filters: true (Forced)
  Face Detection: auto
  Face Strength: 80
  Face Parts: hair,necks
  Sharpen Model: Auto
  Sharpen Levels: medium,high
  Sharpen Strength: 3
  Upscaling Model: Auto
  Auto Upscaling Type: auto
  Auto Upscaling Factor: 2
  Upscaling Denoise Strength: 3
  Upscaling Deblur Strength: 3
  Resolution Unit: 1
  Resolution: -1
  Denoise (non-RAW) Model: Auto
  Denoise (non-RAW) Levels: medium,high,severe
  Denoise (non-RAW) Strength: 3
  Denoise (RAW) Model: Auto
  Denoise (RAW) Levels: low,medium,high,severe
  Denoise (RAW) Strength: 3
  Denoise vs Sharpen: auto
  Adjust Lighting Strength: 25
  Adjust Lighting RAW Strength: 8
  Balance Color Temperature: 50
  Balance Color Opacity: 100
  Default Subject Type: Subject
ExifTool loaded!
Warning: failed to load Config_git.pl, something strange about this perl...
[ WARN:0@1,164] global matrix_expressions.cpp:1334 cv::MatOp_AddEx::assign OpenCV/MatExpr: processing of multi-channel arrays might be changed in the future: https://github.com/opencv/opencv/issues/16739
Overwriting Autopilot values
Overwriting Face Recovery enabled to true
Overwriting Face Recovery enabled to false
Overwriting Enhance enabled to true
Overwriting Enhance scale to 2
*** Error completing request
*** Arguments: ('task(2fvknpdfv61rd9y)', 0.0, <PIL.Image.Image image mode=RGBA size=1024x1024 at 0x1183EA79600>, None, '', '', True, True, 0.0, 4, 0.0, 512, 512, True, 'Topaz Photo AI - Upscale 2x', 'None', 0, False, False, 'Automatic', -1, -1, -1, False, 'Automatic', -1, -1, False, 1, False, 1, 0, False, 0.5, 0.2, False, 0.9, 0.15, 0.5, False, False, 384, 768, 4096, 409600, 'Maximize area', 0.1, False, ['Horizontal'], False, ['Deepbooru'], False, 0.03, 50, False, 'Canon', 'EF 24-70mm f/2.8L II USM', 'Melissa', '4183876', '8678391', '27,1', '32,10', '954,1000', '5127', False, False, 4, None, False, 'A1111', None, False, '0', '0', 'inswapper_128.onnx', 'CodeFormer', 1, True, 'None', 1, 1, 1, 0, 0, 0.5, 'CUDA', False, 0, 'None', '', None, False, False, 0.5, 0, False, False, 8, 'Nearest', False, 1, False, 0) {}
    Traceback (most recent call last):
      File "C:\Users\RGWyo\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 617, in _rmtree_unsafe
        os.unlink(fullname)
    PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\RGWyo\\AppData\\Local\\Temp\\tmpq8ovv9dn\\file.jpg'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "C:\Users\RGWyo\AppData\Local\Programs\Python\Python310\lib\tempfile.py", line 843, in onerror
        _os.unlink(path)
    PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\RGWyo\\AppData\\Local\\Temp\\tmpq8ovv9dn\\file.jpg'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "F:\WBC\automatic1111_dev\modules\call_queue.py", line 57, in f
        res = list(func(*args, **kwargs))
      File "F:\WBC\automatic1111_dev\modules\call_queue.py", line 36, in f
        res = func(*args, **kwargs)
      File "F:\WBC\automatic1111_dev\modules\postprocessing.py", line 131, in run_postprocessing_webui
        return run_postprocessing(*args, **kwargs)
      File "F:\WBC\automatic1111_dev\modules\postprocessing.py", line 71, in run_postprocessing
        scripts.scripts_postproc.run(initial_pp, args)
      File "F:\WBC\automatic1111_dev\modules\scripts_postprocessing.py", line 198, in run
        script.process(single_image, **process_args)
      File "F:\WBC\automatic1111_dev\scripts\postprocessing_upscale.py", line 152, in process
        upscaled_image = self.upscale(pp.image, pp.info, upscaler1, upscale_mode, upscale_by, max_side_length, upscale_to_width, upscale_to_height, upscale_crop)
      File "F:\WBC\automatic1111_dev\scripts\postprocessing_upscale.py", line 107, in upscale
        image = upscaler.scaler.upscale(image, upscale_by, upscaler.data_path)
      File "F:\WBC\automatic1111_dev\modules\upscaler.py", line 68, in upscale
        img = self.do_upscale(img, selected_model)
      File "F:\WBC\automatic1111_dev\extensions\sd-webui-topaz-photo-ai-integration\scripts\topaz_upscaler.py", line 28, in do_upscale
        return simpleUpscale(img, self.fields.scale)
      File "F:\WBC\automatic1111_dev\extensions\sd-webui-topaz-photo-ai-integration\topaz_photo_ai\main.py", line 8, in simpleUpscale
        return runTopaz(img, '--upscale', f'scale={scale}', '--face_recovery', 'enabled=false')
      File "F:\WBC\automatic1111_dev\extensions\sd-webui-topaz-photo-ai-integration\topaz_photo_ai\tools.py", line 61, in runTopaz
        tmpOutDir.cleanup()
      File "C:\Users\RGWyo\AppData\Local\Programs\Python\Python310\lib\tempfile.py", line 873, in cleanup
        self._rmtree(self.name, ignore_errors=self._ignore_cleanup_errors)
      File "C:\Users\RGWyo\AppData\Local\Programs\Python\Python310\lib\tempfile.py", line 855, in _rmtree
        _shutil.rmtree(name, onerror=onerror)
      File "C:\Users\RGWyo\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 749, in rmtree
        return _rmtree_unsafe(path, onerror)
      File "C:\Users\RGWyo\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 619, in _rmtree_unsafe
        onerror(os.unlink, fullname, sys.exc_info())
      File "C:\Users\RGWyo\AppData\Local\Programs\Python\Python310\lib\tempfile.py", line 846, in onerror
        cls._rmtree(path, ignore_errors=ignore_errors)
      File "C:\Users\RGWyo\AppData\Local\Programs\Python\Python310\lib\tempfile.py", line 855, in _rmtree
        _shutil.rmtree(name, onerror=onerror)
      File "C:\Users\RGWyo\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 749, in rmtree
        return _rmtree_unsafe(path, onerror)
      File "C:\Users\RGWyo\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 600, in _rmtree_unsafe
        onerror(os.scandir, path, sys.exc_info())
      File "C:\Users\RGWyo\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 597, in _rmtree_unsafe
        with os.scandir(path) as scandir_it:
    NotADirectoryError: [WinError 267] The directory name is invalid: 'C:\\Users\\RGWyo\\AppData\\Local\\Temp\\tmpq8ovv9dn\\file.jpg'

---

MacOS?

How do I get this to work on Mac?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.