CLI: Show Progress / Save Progress / Generate Progress Video - #694
blessedcoolant wants to merge 2 commits into
Conversation
|
Hi, I just tested this feature, I was looking forward to that, thank you both of you for putting in the efforts. I noticed that aborting the generation will not increment the image index, causing the next generation to replace the pictures in the intermediate folder. From the behaviour of the script when generating a single image, i was expecting for it to not remove my scraps ... even though now I realise it is not something that was directly designed originally. Also, from reading your description, I was expecting the script to post-process all intermediates pictures as well. Thank you again for implementing that, you are opening the door for other cool features to get in. |
The issue here is that the step_callback does not provide a seed number unlike image_callback. So as a result, I cannot set the file names to have the seed (which would make them unique) unless the user explicitly passes -S to the prompt. That's why in some cases like what you tested, the end up overwriting. I am trying to figure a way to either extract the seed somehow or try to find another way to uniquely name the intermediate files. If I think of something, I'll update the PR or do another one if this gets merged by then.
Nope. Makes no sense to post process images that are mostly noise. GFPGAN wont work on most of them and ESRGAN serves no purpose. No reason at all to enlarge intermediate images. |
|
Just tried it out. Like Both times it goes from ~2.0it/s to ~1.3s/it and updates every step, instead of every 5 for the second one. Tested at 837d00b EDIT: I thought show_progress would show the progress every 5 steps. Shows that it's easy to confuse. Also, I would want the progress to be computed only every few frames instead of every frame so that it doesn't affect speed much. Also |
|
Now I tried: First ~1.4s/it, second ~1.4it/s. |
|
@mh-dm Thanks for testing. I made some updates.
The value on show progress was not a So I've updated the settings. show_progress now takes two values
Usage:
If both
This should be fixed now. |
That's quite a non-intuitive quirk. I would say to raise an exception that they have to be the same.
The first image with |
I don't see a point in raising an exception here saying they have to be the same when we can do it ourselves. Why raise an exception for the user to do something that we are doing anyway? Just an extra unnecessary step.
That's just how the iterations are I think. If you log them all, you'll see that the noise extrapolates based on the number of steps. Typing Either way, the visual content of the sample images themselves is out of the scope of this PR. |
Let me restate for a bit more clarity: |
For the exact same reason that if the user types in The fun alternative would be to allow different numbers, i.e. solve a real-life version of the fizzbuzz interview question. |
That's because the first image is always being saved as an initial reference point. I can bypass this but is that necessary? |
There was a problem hiding this comment.
This is very neat indeed. For what it’s worth, I’ll let you know how well the preview window works on a firewalled HPC node. I’m going to have to do two layers of ssh X11 forwarding.
There’s also an old feature request to simply pop up the preview window when the most recent image is done. Maybe that can be funded into this?
I added a check where if you set the For example: When multiple iterations are being generated, the preview windows updates at the end of each generation. |
An initial reference point for? I wouldn't call it necessary but there is a drawback: the first step result is not that useful (it's always an unrecognizable blurry mess) and the time could be better spent on the Xth step result (for --save_progress X). |
There was a problem hiding this comment.
The save-intermediate-images and preview are working great. However, when I try to make a movie (with 'v' or 'vo'), I get a single frame of the final image only.
EDIT: This bug only occurs when you are doing post-processing. With -G1 you get a single-frame image. With no face-fixing, you get the full movie.
I note that I had to replace opencv-python with opencv-contrib python in order to get the libgtk2-compiled module on my Ubuntu system. Is this a general requirement?
|
|
||
| def image_progress(sample, step): | ||
| nonlocal step_index | ||
| nonlocal step_count |
There was a problem hiding this comment.
nonlocals make for more complex code, generally good to be avoided. Options:
- you have access to opt so you could pull step_count of that
- you could use functool.partial(image_progress, a=a) and add another arg to image_process
whatever you think gets you simpler/shorter code with less potential for errors
There was a problem hiding this comment.
The nonlocals were from the initial PR by kevin that added the progress code. It is similar to how its done on the server.py model too. I'm not a fan of it either but I didn't change it for the time being.
There was a problem hiding this comment.
I'm with mh-dm on this one. nonlocal is ugly (almost as bad as GOTO 😂)
Unless I'm reading this wrong, this could even be a function outside of main() (still in 'dream.py'), with a (rather long) list of parameters.
There was a problem hiding this comment.
The issue here is that image_callback and step_callback are predefined callbacks that I cannot pass down any values to. And unfortunately the functionality of this and the image writer need it to use values from outside the scope of these functions. And I cannot initialize step_index inside the callback either because then it'll get initialized for iteration which does not work.
With how dream.py is currently written, I don't see a way to bypass this. Probably why even lstein used nonlocals in image_writer.
Let me explore some options to see if there's a cleaner way for me to do this.
|
|
||
| if opt.show_progress is not None: | ||
| show_progress(image) | ||
| cv2.waitKey(1000) |
There was a problem hiding this comment.
Remove as you already call waitKey in show_progress?
There was a problem hiding this comment.
Not the same. The waitKey in show_progress is to keep the window alive. The waitKey here lasts for a second so the user gets a preview of the final output for atleast a second before it moves on -- added this because when a user is performing multiple iterations, the final preview gets taken off screen too quickly.
Turns out not to be a problem at all to do all the X11 forwarding. Quite fast and interactive. |
| if step_count == 0: | ||
| step_count = 5 | ||
|
|
||
| if step % int(step_count) == 0 and step < opt.steps - 1: |
There was a problem hiding this comment.
There needs to be some type checking on the argument you pass to -save_progress or -show_progress. If you pass a non-numeric argument (as I just did with -save-progress vo you get a crash.
There was a problem hiding this comment.
Agreed. I'm out at the moment. Can't work on this for a bit. If you wanna go ahead and add these tweaks in and make a PR here, I don't mind. If not, I'll do it when I'm back home.
I'll test that out and see why that is happening. Thanks for finding the bug.
Not needed on Windows. So I'm guessing it's a Linux thing? |
Very possibly. I just did a full reinstall of the environment so I think my Linux environment is consistent with the standard one. I hate doing this, but maybe we need to make a environment-lin.yaml. |
Possibly. If it helps with the setup process, then might as well Also had to ask, argparse doesn't support individual type checks for an argument which takes more than 1 value right? I'll need to do the type checking manually somewhere in the code? |
|
This is great progress! Really nice work. I'm running into a few bugs with
|
|
cv2 on OS X seems ... not great. But the fix suggested here is closing the preview window for me. Add |
|
@blessedcoolant Just let me know when you think this is ready for review again. |
Will do. While the feature is fully functional, I've bumped into a couple of issues that I am finding hard to fix. I am exploring solutions for them. This might take a day or two. I'll let you know when this is ready to go. |
No problem. I'm going to be at a conference for the next few days and likely won't be able to do code reviews. Please feel free to step in and do the merge/commits if there are any bugs, nice features or other high pri PRs. |
I'll be a tad bit busy too but I can pop in. Don't worry about it. Enjoy your trip. Have a good time in Barcelona. |
|
Still in draft, is that right? |
Yes. I'm exploring alternative solutions. I'll beep you up on this when I have some updates. |
|
Hi, I found is that the intermediates are not upscaled when using the |
| help='Directory to save generated images and a log of prompts and seeds', | ||
| ) | ||
| render_group.add_argument( | ||
| '-save_progress', |
There was a problem hiding this comment.
single-dash arguments are supposed to be used with single-letter flags
this file already has plenty of arguments so maybe you should skip the single-dash arguments entirely
There was a problem hiding this comment.
see https://serverfault.com/a/387936 for more info
|
@blessedcoolant Still a draft? I thought it was working pretty well, aside from a few minor annoyances. |
Yep. I want to leave it as a draft for the time being. The feature works well but there hiccups we know that don't exactly make for a great user experience when encountered. I want to fix them if I can. Not just that but I also want to look and explore more options than OpenCV for the image display. Especially to avoid the preview window becoming unresponsive (if left open) because it runs on the same thread. These aren't major issues but are issues I'd like to fix. I am currently super busy with the WebUI integration and redesign. Once I am done with that, I'll get back to this. Leaving this open so that if anyone who comes across this and wants to contribute can build off of this rather than start anew. Let's leave it open for the time being I'd say. Thoughts? |
|
Sounds like a plan! The WebUI is looking fantastic. Have you thought about an integrated eraser tool for inpainting? |
|
Closing this. There has ben a lot of changes since this PR and with the latent previews, there's a much more optimized way of doing this. I'll work on this at a later period. |

This is a PR that brings progress features to the CLI. This PR incorporates #623 by @kevinschaul -- Added him to Contributors list.
Features
Example Usage:
<prompt> -s 40 -G 1 -show_progress 1 3 -save_progress 1 voThis command will run the prompt and display a visual preview of the process. The final output will be displayed for 3 seconds before it closes automatically. The prompt has post processing of face restoration. The restoration will take place after the preview closes. Once the restoration is completed, the preview once again loads up to show you the final new updated image for another 3 seconds.
When the process is done, you will find a video of the generation process along with your generated image. More documentation below and in the docs.
Show Progress
Provides a visual preview of the image generation process.
-show_progress <step_count: int> <duration: float>step_count: The number of steps between each progress update. Default:5duration: The duration (in seconds) for how long you want the final image to be displayed beforethe preview closes automatically. Default:
2Enter duration as
0to keep it open forever until user presses a key. Note that this will block the codefrom running further until user input.
If you have post processing options, the preview will close after image generation and reopen again
with the updated changes.
Save Progress & Make Video
Allows you to save the intermediate steps during the image generation process and make a video out
of it.
-save_progress <step_count: int default=5> <video_options: v | vo default: None>step_count: The number of steps between each intermediate image saved. When no value is given,it defaults to
5.video_options: Allows you to generate a video from the intermediate images. Takes two options:v(Video) orvo(Video Only)Usage
-save_progress: Saves intermediate frames every 5 steps. No video generation.-save_progress 3: Saves intermediate frames every 3 steps. No video generation.-save_progress 3 v: Saves intermediate frames every 3 steps. Also generates a video from theframes at the end.
-save_progress 3 vo: Does not save intermediate frames but generates a video of the process every3 steps.
-show progress 3 -save_progress 3 vo: Shows a preview of the generation process updating every 3seconds while also saving a video of the same.
Performance
I've done testing on various combinations. No issues so far. Fixed all I could find. Feel free to test and report back to me. Thank you.