feat: add capability to repeatedly run the upscaler in a row (#174)
* Add in upscale repeater logic --------- Co-authored-by: leejet <leejet714@gmail.com>
This commit is contained in:
parent
b6368868d9
commit
193fb620b1
@ -148,7 +148,7 @@ cmake --build . --config Release
|
|||||||
### Run
|
### Run
|
||||||
|
|
||||||
```
|
```
|
||||||
usage: ./bin/sd [arguments]
|
usage: ./build/bin/sd [arguments]
|
||||||
|
|
||||||
arguments:
|
arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
@ -161,6 +161,7 @@ arguments:
|
|||||||
--control-net [CONTROL_PATH] path to control net model
|
--control-net [CONTROL_PATH] path to control net model
|
||||||
--embd-dir [EMBEDDING_PATH] path to embeddings.
|
--embd-dir [EMBEDDING_PATH] path to embeddings.
|
||||||
--upscale-model [ESRGAN_PATH] path to esrgan model. Upscale images after generate, just RealESRGAN_x4plus_anime_6B supported by now.
|
--upscale-model [ESRGAN_PATH] path to esrgan model. Upscale images after generate, just RealESRGAN_x4plus_anime_6B supported by now.
|
||||||
|
--upscale-repeats Run the ESRGAN upscaler this many times (default 1)
|
||||||
--type [TYPE] weight type (f32, f16, q4_0, q4_1, q5_0, q5_1, q8_0)
|
--type [TYPE] weight type (f32, f16, q4_0, q4_1, q5_0, q5_1, q8_0)
|
||||||
If not specified, the default is the type of the weight file.
|
If not specified, the default is the type of the weight file.
|
||||||
--lora-model-dir [DIR] lora model directory
|
--lora-model-dir [DIR] lora model directory
|
||||||
@ -186,6 +187,7 @@ arguments:
|
|||||||
<= 0 represents unspecified, will be 1 for SD1.x, 2 for SD2.x
|
<= 0 represents unspecified, will be 1 for SD1.x, 2 for SD2.x
|
||||||
--vae-tiling process vae in tiles to reduce memory usage
|
--vae-tiling process vae in tiles to reduce memory usage
|
||||||
--control-net-cpu keep controlnet in cpu (for low vram)
|
--control-net-cpu keep controlnet in cpu (for low vram)
|
||||||
|
--canny apply canny preprocessor (edge detection)
|
||||||
-v, --verbose print extra info
|
-v, --verbose print extra info
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -96,6 +96,7 @@ struct SDParams {
|
|||||||
bool vae_tiling = false;
|
bool vae_tiling = false;
|
||||||
bool control_net_cpu = false;
|
bool control_net_cpu = false;
|
||||||
bool canny_preprocess = false;
|
bool canny_preprocess = false;
|
||||||
|
int upscale_repeats = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
void print_params(SDParams params) {
|
void print_params(SDParams params) {
|
||||||
@ -129,6 +130,7 @@ void print_params(SDParams params) {
|
|||||||
printf(" seed: %ld\n", params.seed);
|
printf(" seed: %ld\n", params.seed);
|
||||||
printf(" batch_count: %d\n", params.batch_count);
|
printf(" batch_count: %d\n", params.batch_count);
|
||||||
printf(" vae_tiling: %s\n", params.vae_tiling ? "true" : "false");
|
printf(" vae_tiling: %s\n", params.vae_tiling ? "true" : "false");
|
||||||
|
printf(" upscale_repeats: %d\n", params.upscale_repeats);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_usage(int argc, const char* argv[]) {
|
void print_usage(int argc, const char* argv[]) {
|
||||||
@ -145,6 +147,7 @@ void print_usage(int argc, const char* argv[]) {
|
|||||||
printf(" --control-net [CONTROL_PATH] path to control net model\n");
|
printf(" --control-net [CONTROL_PATH] path to control net model\n");
|
||||||
printf(" --embd-dir [EMBEDDING_PATH] path to embeddings.\n");
|
printf(" --embd-dir [EMBEDDING_PATH] path to embeddings.\n");
|
||||||
printf(" --upscale-model [ESRGAN_PATH] path to esrgan model. Upscale images after generate, just RealESRGAN_x4plus_anime_6B supported by now.\n");
|
printf(" --upscale-model [ESRGAN_PATH] path to esrgan model. Upscale images after generate, just RealESRGAN_x4plus_anime_6B supported by now.\n");
|
||||||
|
printf(" --upscale-repeats Run the ESRGAN upscaler this many times (default 1)\n");
|
||||||
printf(" --type [TYPE] weight type (f32, f16, q4_0, q4_1, q5_0, q5_1, q8_0)\n");
|
printf(" --type [TYPE] weight type (f32, f16, q4_0, q4_1, q5_0, q5_1, q8_0)\n");
|
||||||
printf(" If not specified, the default is the type of the weight file.\n");
|
printf(" If not specified, the default is the type of the weight file.\n");
|
||||||
printf(" --lora-model-dir [DIR] lora model directory\n");
|
printf(" --lora-model-dir [DIR] lora model directory\n");
|
||||||
@ -296,6 +299,16 @@ void parse_args(int argc, const char** argv, SDParams& params) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
params.prompt = argv[i];
|
params.prompt = argv[i];
|
||||||
|
} else if (arg == "--upscale-repeats") {
|
||||||
|
if (++i >= argc) {
|
||||||
|
invalid_arg = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
params.upscale_repeats = std::stoi(argv[i]);
|
||||||
|
if (params.upscale_repeats < 1) {
|
||||||
|
fprintf(stderr, "error: upscale multiplier must be at least 1\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
} else if (arg == "-n" || arg == "--negative-prompt") {
|
} else if (arg == "-n" || arg == "--negative-prompt") {
|
||||||
if (++i >= argc) {
|
if (++i >= argc) {
|
||||||
invalid_arg = true;
|
invalid_arg = true;
|
||||||
@ -700,7 +713,7 @@ int main(int argc, const char* argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int upscale_factor = 4; // unused for RealESRGAN_x4plus_anime_6B.pth
|
int upscale_factor = 4; // unused for RealESRGAN_x4plus_anime_6B.pth
|
||||||
if (params.esrgan_path.size() > 0) {
|
if (params.esrgan_path.size() > 0 && params.upscale_repeats > 0) {
|
||||||
upscaler_ctx_t* upscaler_ctx = new_upscaler_ctx(params.esrgan_path.c_str(),
|
upscaler_ctx_t* upscaler_ctx = new_upscaler_ctx(params.esrgan_path.c_str(),
|
||||||
params.n_threads,
|
params.n_threads,
|
||||||
params.wtype);
|
params.wtype);
|
||||||
@ -712,13 +725,17 @@ int main(int argc, const char* argv[]) {
|
|||||||
if (results[i].data == NULL) {
|
if (results[i].data == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
sd_image_t upscaled_image = upscale(upscaler_ctx, results[i], upscale_factor);
|
sd_image_t current_image = results[i];
|
||||||
if (upscaled_image.data == NULL) {
|
for (int u = 0; u < params.upscale_repeats; ++u) {
|
||||||
printf("upscale failed\n");
|
sd_image_t upscaled_image = upscale(upscaler_ctx, current_image, upscale_factor);
|
||||||
continue;
|
if (upscaled_image.data == NULL) {
|
||||||
|
printf("upscale failed\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
free(current_image.data);
|
||||||
|
current_image = upscaled_image;
|
||||||
}
|
}
|
||||||
free(results[i].data);
|
results[i] = current_image; // Set the final upscaled image as the result
|
||||||
results[i] = upscaled_image;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,10 +173,11 @@ public:
|
|||||||
if (version == VERSION_XL) {
|
if (version == VERSION_XL) {
|
||||||
scale_factor = 0.13025f;
|
scale_factor = 0.13025f;
|
||||||
if (vae_path.size() == 0 && taesd_path.size() == 0) {
|
if (vae_path.size() == 0 && taesd_path.size() == 0) {
|
||||||
LOG_WARN("!!!It looks like you are using SDXL model. "
|
LOG_WARN(
|
||||||
"If you find that the generated images are completely black, "
|
"!!!It looks like you are using SDXL model. "
|
||||||
"try specifying SDXL VAE FP16 Fix with the --vae parameter. "
|
"If you find that the generated images are completely black, "
|
||||||
"You can find it here: https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/blob/main/sdxl_vae.safetensors");
|
"try specifying SDXL VAE FP16 Fix with the --vae parameter. "
|
||||||
|
"You can find it here: https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/blob/main/sdxl_vae.safetensors");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user