mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-11-11 11:26:34 +00:00
added a WIN32 get_files_from_dir; turn off Photomakder if receiving no input images
This commit is contained in:
1 parent
70c3397b60
commit
16c9da0cca
3 files changed
+83
-39
No files matched your search
@@ -706,9 +706,9 @@ int main(int argc, const char* argv[]) {
|
|||||||
}
|
}
|
||||||
sd_image_t* input_image = NULL;
|
sd_image_t* input_image = NULL;
|
||||||
input_image = new sd_image_t{(uint32_t)width,
|
input_image = new sd_image_t{(uint32_t)width,
|
||||||
(uint32_t)height,
|
(uint32_t)height,
|
||||||
3,
|
3,
|
||||||
input_image_buffer};
|
input_image_buffer};
|
||||||
input_image = preprocess_id_image(input_image);
|
input_image = preprocess_id_image(input_image);
|
||||||
if(input_image == NULL){
|
if(input_image == NULL){
|
||||||
LOG_ERROR("preprocess input id image from '%s' failed", img_file.c_str());
|
LOG_ERROR("preprocess input id image from '%s' failed", img_file.c_str());
|
||||||
|
|||||||
+41
-36
@@ -1679,47 +1679,52 @@ sd_image_t* txt2img(sd_ctx_t* sd_ctx,
|
|||||||
// ggml_tensor* class_tokens_mask = NULL;
|
// ggml_tensor* class_tokens_mask = NULL;
|
||||||
std::vector<bool> class_tokens_mask;
|
std::vector<bool> class_tokens_mask;
|
||||||
if(sd_ctx->sd->stacked_id){
|
if(sd_ctx->sd->stacked_id){
|
||||||
sd_ctx->sd->pmid_model->style_strength = style_ratio;
|
if(input_id_images.size() > 0){
|
||||||
int32_t w = input_id_images[0]->width;
|
sd_ctx->sd->pmid_model->style_strength = style_ratio;
|
||||||
int32_t h = input_id_images[0]->height;
|
int32_t w = input_id_images[0]->width;
|
||||||
int32_t channels = input_id_images[0]->channel;
|
int32_t h = input_id_images[0]->height;
|
||||||
int32_t num_input_images = input_id_images.size();
|
int32_t channels = input_id_images[0]->channel;
|
||||||
init_img = ggml_new_tensor_4d(work_ctx, GGML_TYPE_F32, w, h, channels, num_input_images);
|
int32_t num_input_images = input_id_images.size();
|
||||||
// TODO: move these to somewhere else and be user settable
|
init_img = ggml_new_tensor_4d(work_ctx, GGML_TYPE_F32, w, h, channels, num_input_images);
|
||||||
float mean[] = {0.48145466, 0.4578275, 0.40821073};
|
// TODO: move these to somewhere else and be user settable
|
||||||
float std[] = {0.26862954, 0.26130258, 0.27577711};
|
float mean[] = {0.48145466, 0.4578275, 0.40821073};
|
||||||
for(int i = 0; i < num_input_images; i++) {
|
float std[] = {0.26862954, 0.26130258, 0.27577711};
|
||||||
sd_image_t* init_image = input_id_images[i];
|
for(int i = 0; i < num_input_images; i++) {
|
||||||
if(normalize_input)
|
sd_image_t* init_image = input_id_images[i];
|
||||||
sd_mul_images_to_tensor(init_image->data, init_img, i, mean, std);
|
if(normalize_input)
|
||||||
else
|
sd_mul_images_to_tensor(init_image->data, init_img, i, mean, std);
|
||||||
sd_mul_images_to_tensor(init_image->data, init_img, i, NULL, NULL);
|
else
|
||||||
}
|
sd_mul_images_to_tensor(init_image->data, init_img, i, NULL, NULL);
|
||||||
t0 = ggml_time_ms();
|
}
|
||||||
auto cond_tup = sd_ctx->sd->get_learned_condition_with_trigger(work_ctx, prompt,
|
t0 = ggml_time_ms();
|
||||||
clip_skip, width, height, num_input_images );
|
auto cond_tup = sd_ctx->sd->get_learned_condition_with_trigger(work_ctx, prompt,
|
||||||
prompts_embeds = std::get<0>(cond_tup);
|
clip_skip, width, height, num_input_images );
|
||||||
pooled_prompts_embeds = std::get<1>(cond_tup); // [adm_in_channels, ]
|
prompts_embeds = std::get<0>(cond_tup);
|
||||||
class_tokens_mask = std::get<2>(cond_tup); //
|
pooled_prompts_embeds = std::get<1>(cond_tup); // [adm_in_channels, ]
|
||||||
|
class_tokens_mask = std::get<2>(cond_tup); //
|
||||||
|
|
||||||
prompts_embeds = sd_ctx->sd->id_encoder(work_ctx, init_img, prompts_embeds, class_tokens_mask);
|
prompts_embeds = sd_ctx->sd->id_encoder(work_ctx, init_img, prompts_embeds, class_tokens_mask);
|
||||||
t1 = ggml_time_ms();
|
t1 = ggml_time_ms();
|
||||||
LOG_INFO("Photomaker ID Stacking, taking %" PRId64 " ms", t1 - t0);
|
LOG_INFO("Photomaker ID Stacking, taking %" PRId64 " ms", t1 - t0);
|
||||||
if (sd_ctx->sd->free_params_immediately) {
|
if (sd_ctx->sd->free_params_immediately) {
|
||||||
sd_ctx->sd->pmid_model->free_params_buffer();
|
sd_ctx->sd->pmid_model->free_params_buffer();
|
||||||
}
|
}
|
||||||
// Encode input prompt without the trigger word for delayed conditioning
|
// Encode input prompt without the trigger word for delayed conditioning
|
||||||
prompt_text_only = sd_ctx->sd->remove_trigger_from_prompt(work_ctx, prompt);
|
prompt_text_only = sd_ctx->sd->remove_trigger_from_prompt(work_ctx, prompt);
|
||||||
// printf("%s || %s \n", prompt.c_str(), prompt_text_only.c_str());
|
// printf("%s || %s \n", prompt.c_str(), prompt_text_only.c_str());
|
||||||
prompt = prompt_text_only; //
|
prompt = prompt_text_only; //
|
||||||
if(sample_steps < 50){
|
if(sample_steps < 50){
|
||||||
LOG_INFO("sampling steps increases from %d to 50 for PHOTOMAKER", sample_steps);
|
LOG_INFO("sampling steps increases from %d to 50 for PHOTOMAKER", sample_steps);
|
||||||
sample_steps = 50;
|
sample_steps = 50;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
LOG_WARN("Provided PhotoMaker model file, but NO input ID images");
|
||||||
|
LOG_WARN("Turn off PhotoMaker");
|
||||||
|
sd_ctx->sd->stacked_id = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
t0 = ggml_time_ms();
|
t0 = ggml_time_ms();
|
||||||
auto cond_pair = sd_ctx->sd->get_learned_condition(work_ctx, prompt, clip_skip, width, height);
|
auto cond_pair = sd_ctx->sd->get_learned_condition(work_ctx, prompt, clip_skip, width, height);
|
||||||
ggml_tensor* c = cond_pair.first;
|
ggml_tensor* c = cond_pair.first;
|
||||||
|
|||||||
@@ -91,6 +91,45 @@ std::string get_full_path(const std::string& dir, const std::string& filename) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> get_files_from_dir(const std::string& dir) {
|
||||||
|
|
||||||
|
std::vector<std::string> files;
|
||||||
|
|
||||||
|
WIN32_FIND_DATA findFileData;
|
||||||
|
HANDLE hFind;
|
||||||
|
|
||||||
|
char currentDirectory[MAX_PATH];
|
||||||
|
GetCurrentDirectory(MAX_PATH, currentDirectory);
|
||||||
|
|
||||||
|
char directoryPath[MAX_PATH]; // this is absolute path
|
||||||
|
sprintf(directoryPath, "%s\\%s\\*", currentDirectory, dir.c_str());
|
||||||
|
|
||||||
|
// Find the first file in the directory
|
||||||
|
hFind = FindFirstFile(directoryPath, &findFileData);
|
||||||
|
|
||||||
|
// Check if the directory was found
|
||||||
|
if (hFind == INVALID_HANDLE_VALUE) {
|
||||||
|
printf("Unable to find directory.\n");
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through all files in the directory
|
||||||
|
do {
|
||||||
|
// Check if the found file is a regular file (not a directory)
|
||||||
|
if (!(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
|
||||||
|
files.push_back(std::string(currentDirectory) + "\\" + dir + "\\" + std::string(findFileData.cFileName));
|
||||||
|
}
|
||||||
|
} while (FindNextFile(hFind, &findFileData) != 0);
|
||||||
|
|
||||||
|
// Close the handle
|
||||||
|
FindClose(hFind);
|
||||||
|
|
||||||
|
|
||||||
|
sort(files.begin(), files.end());
|
||||||
|
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
#else // Unix
|
#else // Unix
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|||||||
Reference in new issue
Block a user