Skip to content

Commit 07c61f1

Browse files
committed
supports noisy preview in main
1 parent 27af5a4 commit 07c61f1

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

examples/cli/main.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ struct SDParams {
146146
int preview_interval = 1;
147147
std::string preview_path = "preview.png";
148148
bool taesd_preview = false;
149+
bool preview_noisy = false;
149150

150151
SDParams() {
151152
sd_sample_params_init(&sample_params);
152153
sd_sample_params_init(&high_noise_sample_params);
153154
high_noise_sample_params.sample_steps = -1;
154155
}
155-
156156
};
157157

158158
void print_params(SDParams params) {
@@ -223,7 +223,7 @@ void print_params(SDParams params) {
223223
printf(" video_frames: %d\n", params.video_frames);
224224
printf(" vace_strength: %.2f\n", params.vace_strength);
225225
printf(" fps: %d\n", params.fps);
226-
printf(" preview_mode: %s\n", previews_str[params.preview_method]);
226+
printf(" preview_mode: %s (%s)\n", previews_str[params.preview_method], params.preview_noisy ? "noisy" : "denoised");
227227
printf(" preview_interval: %d\n", params.preview_interval);
228228
free(sample_params_str);
229229
free(high_noise_sample_params_str);
@@ -604,7 +604,7 @@ void parse_args(int argc, const char** argv, SDParams& params) {
604604
"--negative-prompt",
605605
"the negative prompt (default: \"\")",
606606
&params.negative_prompt},
607-
{"",
607+
{"",
608608
"--preview-path",
609609
"path to write preview image to (default: ./preview.png)",
610610
&params.preview_path},
@@ -669,7 +669,7 @@ void parse_args(int argc, const char** argv, SDParams& params) {
669669
{"",
670670
"--preview-interval",
671671
"interval in denoising steps between consecutive updates of the image preview file (default is 1, meaning updating at every step)",
672-
&params.preview_interval},
672+
&params.preview_interval},
673673
};
674674

675675
options.float_options = {
@@ -826,8 +826,12 @@ void parse_args(int argc, const char** argv, SDParams& params) {
826826
false, &params.auto_resize_ref_image},
827827
{"",
828828
"--taesd-preview-only",
829-
std::string("prevents usage of taesd for decoding the final image. (for use with --preview ") + previews_str[PREVIEW_TAE] + ")",
830-
false, &params.taesd_preview},
829+
std::string("prevents usage of taesd for decoding the final image. (for use with --preview ") + previews_str[PREVIEW_TAE] + ")",
830+
true, &params.taesd_preview},
831+
{"",
832+
"--preview-noisy",
833+
"enables previewing noisy inputs of the models rather than the denoised outputs",
834+
true, &params.preview_noisy}
831835
};
832836

833837
auto on_mode_arg = [&](int argc, const char** argv, int index) {
@@ -1507,6 +1511,7 @@ const char* preview_path;
15071511
float preview_fps;
15081512

15091513
void step_callback(int step, int frame_count, sd_image_t* image, bool is_noisy) {
1514+
(void)step;
15101515
(void)is_noisy;
15111516
// is_noisy is set to true if the preview corresponds to noisy latents, false if it's denoised latents
15121517
// unused in this app, it will either be always noisy or always denoised here
@@ -1531,7 +1536,8 @@ int main(int argc, const char* argv[]) {
15311536
std::transform(file_ext.begin(), file_ext.end(), file_ext.begin(), ::tolower);
15321537
}
15331538
if (file_ext == ".png") {
1534-
preview_path = (base_path + ".avi").c_str();
1539+
base_path = base_path + ".avi";
1540+
preview_path = base_path.c_str();
15351541
}
15361542
}
15371543
preview_fps = params.fps;
@@ -1544,7 +1550,7 @@ int main(int argc, const char* argv[]) {
15441550
params.high_noise_sample_params.guidance.slg.layer_count = params.high_noise_skip_layers.size();
15451551

15461552
sd_set_log_callback(sd_log_cb, (void*)&params);
1547-
sd_set_preview_callback((sd_preview_cb_t)step_callback, params.preview_method, params.preview_interval, true, false);
1553+
sd_set_preview_callback((sd_preview_cb_t)step_callback, params.preview_method, params.preview_interval, !params.preview_noisy, params.preview_noisy);
15481554

15491555
if (params.verbose) {
15501556
print_params(params);

0 commit comments

Comments
 (0)