Skip to content

Commit 4a81904

Browse files
committed
fix: fix the issue with dynamic linking
1 parent 730585d commit 4a81904

File tree

7 files changed

+38
-12
lines changed

7 files changed

+38
-12
lines changed

clip.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ struct FrozenCLIPEmbedderWithCustomWords : public GGMLModule {
964964

965965
input_ids2 = to_backend(input_ids2);
966966
if (!return_pooled) {
967-
input_ids = to_backend(input_ids);
967+
input_ids = to_backend(input_ids);
968968
}
969969

970970
struct ggml_tensor* embeddings = NULL;

control.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,11 @@ struct ControlNet : public GGMLModule {
388388
struct ggml_tensor* y = NULL) {
389389
struct ggml_cgraph* gf = ggml_new_graph_custom(compute_ctx, CONTROL_NET_GRAPH_SIZE, false);
390390

391-
x = to_backend(x);
391+
x = to_backend(x);
392392
if (guided_hint_cached) {
393393
hint = NULL;
394394
} else {
395-
hint = to_backend(hint);
395+
hint = to_backend(hint);
396396
}
397397
context = to_backend(context);
398398
y = to_backend(y);

examples/cli/main.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,18 @@ void parse_args(int argc, const char** argv, SDParams& params) {
499499
}
500500
}
501501

502+
static std::string sd_basename(const std::string& path) {
503+
size_t pos = path.find_last_of('/');
504+
if (pos != std::string::npos) {
505+
return path.substr(pos + 1);
506+
}
507+
pos = path.find_last_of('\\');
508+
if (pos != std::string::npos) {
509+
return path.substr(pos + 1);
510+
}
511+
return path;
512+
}
513+
502514
std::string get_image_params(SDParams params, int64_t seed) {
503515
std::string parameter_string = params.prompt + "\n";
504516
if (params.negative_prompt.size() != 0) {
@@ -631,7 +643,14 @@ int main(int argc, const char* argv[]) {
631643
input_image_buffer};
632644
if (params.canny_preprocess) { // apply preprocessor
633645
LOG_INFO("Applying canny preprocessor");
634-
control_image->data = preprocess_canny(control_image->data, control_image->width, control_image->height);
646+
control_image->data = preprocess_canny(control_image->data,
647+
control_image->width,
648+
control_image->height,
649+
0.08f,
650+
0.08f,
651+
0.8f,
652+
1.0f,
653+
false);
635654
}
636655
}
637656
results = txt2img(sd_ctx,

preprocessing.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ void non_max_supression(struct ggml_tensor* result, struct ggml_tensor* G, struc
117117
}
118118
}
119119

120-
void threshold_hystersis(struct ggml_tensor* img, float highThreshold, float lowThreshold, float weak, float strong) {
120+
void threshold_hystersis(struct ggml_tensor* img, float high_threshold, float low_threshold, float weak, float strong) {
121121
int n_elements = ggml_nelements(img);
122122
float* imd = (float*)img->data;
123123
float max = -INFINITY;
124124
for (int i = 0; i < n_elements; i++) {
125125
max = imd[i] > max ? imd[i] : max;
126126
}
127-
float ht = max * highThreshold;
128-
float lt = ht * lowThreshold;
127+
float ht = max * high_threshold;
128+
float lt = ht * low_threshold;
129129
for (int i = 0; i < n_elements; i++) {
130130
float img_v = imd[i];
131131
if (img_v >= ht) { // strong pixel
@@ -162,7 +162,7 @@ void threshold_hystersis(struct ggml_tensor* img, float highThreshold, float low
162162
}
163163
}
164164

165-
uint8_t* preprocess_canny(uint8_t* img, int width, int height, float highThreshold = 0.08f, float lowThreshold = 0.08f, float weak = 0.8f, float strong = 1.0f, bool inverse = false) {
165+
uint8_t* preprocess_canny(uint8_t* img, int width, int height, float high_threshold, float low_threshold, float weak, float strong, bool inverse) {
166166
struct ggml_init_params params;
167167
params.mem_size = static_cast<size_t>(10 * 1024 * 1024); // 10
168168
params.mem_buffer = NULL;
@@ -207,7 +207,7 @@ uint8_t* preprocess_canny(uint8_t* img, int width, int height, float highThresho
207207
normalize_tensor(G);
208208
prop_arctan2(iX, iY, tetha);
209209
non_max_supression(image_gray, G, tetha);
210-
threshold_hystersis(image_gray, highThreshold, lowThreshold, weak, strong);
210+
threshold_hystersis(image_gray, high_threshold, low_threshold, weak, strong);
211211
// to RGB channels
212212
for (int iy = 0; iy < height; iy++) {
213213
for (int ix = 0; ix < width; ix++) {

stable-diffusion.h

+9
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,15 @@ SD_API sd_image_t upscale(upscaler_ctx_t* upscaler_ctx, sd_image_t input_image,
177177

178178
SD_API bool convert(const char* input_path, const char* vae_path, const char* output_path, sd_type_t output_type);
179179

180+
SD_API uint8_t* preprocess_canny(uint8_t* img,
181+
int width,
182+
int height,
183+
float high_threshold,
184+
float low_threshold,
185+
float weak,
186+
float strong,
187+
bool inverse);
188+
180189
#ifdef __cplusplus
181190
}
182191
#endif

util.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ std::u32string unicode_value_to_utf32(int unicode_value) {
175175
return utf32_string;
176176
}
177177

178-
std::string sd_basename(const std::string& path) {
178+
static std::string sd_basename(const std::string& path) {
179179
size_t pos = path.find_last_of('/');
180180
if (pos != std::string::npos) {
181181
return path.substr(pos + 1);

util.h

-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ std::u32string utf8_to_utf32(const std::string& utf8_str);
2121
std::string utf32_to_utf8(const std::u32string& utf32_str);
2222
std::u32string unicode_value_to_utf32(int unicode_value);
2323

24-
std::string sd_basename(const std::string& path);
25-
2624
typedef struct {
2725
uint32_t width;
2826
uint32_t height;

0 commit comments

Comments
 (0)