Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outpainting for #405 #412

Merged
merged 48 commits into from
Dec 9, 2022
Merged

Outpainting for #405 #412

merged 48 commits into from
Dec 9, 2022

Conversation

carson-katri
Copy link
Owner

@carson-katri carson-katri commented Dec 6, 2022

I changed the way outpainting works for better performance and flexibility. Instead of specifying the expansion on each axis, it uses the specified image size and an origin point.

For example, to extend a 512x512 image to the right:

  1. Set an image size to specify the outpaint cursor area (e.g. (512, 512))
  2. Set the origin point to (448, 0) for a 64px overlap, `(384, 0) for a 128px overlap, etc.

It will only run SD on a 512x512 area, and then overlays it on an extended image at the end.

An inpainting finetuned model must be used for outpainting.

Base automatically changed from diffusers to main December 6, 2022 17:53
@carson-katri carson-katri marked this pull request as ready for review December 6, 2022 17:59
@carson-katri carson-katri added this to the v0.0.9 milestone Dec 6, 2022
Copy link
Collaborator

@NullSenseStudio NullSenseStudio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far mostly works great, some issues though.

When the outpainted image gets large enough I'm receiving this error right after the final image gets placed in Blender. I'm assuming it has to do with it being done in a background thread and not Blender's main thread.

  File "...\dream-textures\operators\dream_texture.py", line 147, in done_callback
    image['dream_textures_hash'] = image_hash
AttributeError: Writing to ID classes in this context is not allowed: 388423733, Image datablock, error setting Image.dream_textures_hash

Also for some reason there is color shifting occurring in parts of the image that aren't even being outpainted to at the time.
blender_4hO1CJdKoK

generator_process/actions/outpaint.py Outdated Show resolved Hide resolved
@carson-katri
Copy link
Owner Author

To fix the threading issues, the Actor class could use an app timer instead of a Thread to handle response messages on the frontend.

@carson-katri
Copy link
Owner Author

I haven't had it happen yet with this implementation, but it seemed pretty random in the first place so hopefully this really did fix it.

One drawback of this approach is it removes the ability to block via the Future:

Generator.shared().prompt_to_image(...).result()

Instead you need the more verbose

Generator.shared().prompt_to_image(..., _block=True).result()

I don't think this is too bad considering it's internal API.
And perhaps we shouldn't block either way for UX.

Co-authored-by: NullSenseStudio <47096043+NullSenseStudio@users.noreply.github.com>
@NullSenseStudio
Copy link
Collaborator

NullSenseStudio commented Dec 9, 2022

Perhaps the _send() function could remain how it was. Have a single threading event for each future that can be waited on for result() rather than adding in another callback. Then only create app timers when callbacks are run.

I suppose callbacks wouldn't run in this setup if result() is called on the main thread before completion, but I'd think you'd strictly use one or the other anyway.

@carson-katri
Copy link
Owner Author

carson-katri commented Dec 9, 2022

I think 9480c4b works the way you described, which does seem a bit better than the artificial delays that come with using timers as a thread.

The hf_list_installed_models calls in preferences were left with _block=True as they were deadlocking when Blender is launched from VS Code. It seemed to work OK when opening Blender manually though.

preferences.py Outdated Show resolved Hide resolved
Co-authored-by: NullSenseStudio <47096043+NullSenseStudio@users.noreply.github.com>
@NullSenseStudio
Copy link
Collaborator

Also for some reason there is color shifting occurring in parts of the image that aren't even being outpainted to at the time.

I've tracked this down to being caused by save_temp_image(). Had an image generated, made a copy via that function and brought it back into Blender with the same color shifting being visible. Perhaps it could be sent to the backend as an ndarray instead of making a temp file?

@carson-katri
Copy link
Owner Author

2280986101

3519646084

Copy link
Collaborator

@NullSenseStudio NullSenseStudio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was just about to mention those axis needing switched. Really getting tired of whoever standardized the y axis going before x.

Anyhow, everything seems to be working as intended now!

@carson-katri
Copy link
Owner Author

Me too, it's bizarre. They put the height before the width argument in the pipelines too.

@carson-katri carson-katri merged commit fcafd8b into main Dec 9, 2022
JasonHoku pushed a commit to JasonHoku/dream-textures that referenced this pull request Dec 20, 2022
* Initial diffusers backend scaffolding

* Support scheduler selection

* Add more schedulers

* Add ocio_transform action

* Support seamless generation

* Support cancellation

* Remove old intents, upscaling, actor improvements

* Add tiling to stable diffusion upscaler

* Add image_to_image and inpaint

* Update render_pass.py

* fix activating when diffusers is not installed

* load dependencies sooner

* re-add other platform requirements

* fix can_use() and cancel/stop operators

* fix non-square images

* Update optimization options

* Add proper file naming

* Fix data block removal error

* Add upscale tile blending with the 'tiler'

* Add 'tiler' to other requirements files

* Add upscale naming

* Add progress bar

* Add progress bar to upscaling

* Fix image2image

* Fix inpaint

* Raise the error in the exception_callback

* Pipeline switching

* fix upscale

* no_grad already used in pipe

* Outpainting support

* Remove .save(...)

* Re-use the same datablock

* Add warning when there is no overlap

* Consolidate labels

* update workflow requirements

* Use app timers instead of threading on the frontend

* Update generator_process/actions/outpaint.py

Co-authored-by: NullSenseStudio <47096043+NullSenseStudio@users.noreply.github.com>

* Use app timers to run callbacks

* Update preferences.py

Co-authored-by: NullSenseStudio <47096043+NullSenseStudio@users.noreply.github.com>

* Use NDArray for all init_image types

* Swap w/h

Co-authored-by: NullSenseStudio <47096043+NullSenseStudio@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants