Skip to content

Commit bb7c550

Browse files
authored
Create mask only for img2img
This will save memory for txt2img.
1 parent 30b3ac8 commit bb7c550

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

examples/cli/main.cpp

+12-13
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,6 @@ int main(int argc, const char* argv[]) {
825825
bool vae_decode_only = true;
826826
uint8_t* input_image_buffer = NULL;
827827
uint8_t* control_image_buffer = NULL;
828-
uint8_t* mask_image_buffer = NULL;
829828

830829
if (params.mode == IMG2IMG || params.mode == IMG2VID) {
831830
vae_decode_only = false;
@@ -931,18 +930,6 @@ int main(int argc, const char* argv[]) {
931930
}
932931
}
933932

934-
std::vector<uint8_t> default_mask_image_vec(params.width * params.height, 255);
935-
if (params.mask_path != "") {
936-
int c = 0;
937-
mask_image_buffer = stbi_load(params.mask_path.c_str(), &params.width, &params.height, &c, 1);
938-
} else {
939-
mask_image_buffer = default_mask_image_vec.data();
940-
}
941-
sd_image_t mask_image = {(uint32_t)params.width,
942-
(uint32_t)params.height,
943-
1,
944-
mask_image_buffer};
945-
946933
sd_image_t* results;
947934
if (params.mode == TXT2IMG) {
948935
results = txt2img(sd_ctx,
@@ -1011,6 +998,18 @@ int main(int argc, const char* argv[]) {
1011998
free_sd_ctx(sd_ctx);
1012999
return 0;
10131000
} else {
1001+
uint8_t* mask_image_buffer;
1002+
std::vector<uint8_t> default_mask_image_vec(params.width * params.height, 255);
1003+
if (params.mask_path != "") {
1004+
int c = 0;
1005+
mask_image_buffer = stbi_load(params.mask_path.c_str(), &params.width, &params.height, &c, 1);
1006+
} else {
1007+
mask_image_buffer = default_mask_image_vec.data();
1008+
}
1009+
const sd_image_t mask_image = {(uint32_t)params.width,
1010+
(uint32_t)params.height,
1011+
1,
1012+
mask_image_buffer};
10141013
results = img2img(sd_ctx,
10151014
input_image,
10161015
mask_image,

0 commit comments

Comments
 (0)