MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / encode_image_with_clip

Function encode_image_with_clip

examples/llava/llava.cpp:12–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#include "base64.hpp"
11
12static bool encode_image_with_clip(clip_ctx * ctx_clip, int n_threads, const clip_image_u8 * img, float * image_embd, int * n_img_pos) {
13 clip_image_f32 * img_res = make_clip_image_f32();
14 if (!clip_image_preprocess(ctx_clip, img, img_res, /*pad2square =*/ true)) {
15 fprintf(stderr, "%s: unable to preprocess image\n", __func__);
16 clip_image_f32_free(img_res);
17 return false;
18 }
19
20 *n_img_pos = clip_n_patches(ctx_clip);
21
22 const int64_t t_img_enc_start_us = ggml_time_us();
23 bool encoded = clip_image_encode(ctx_clip, n_threads, img_res, image_embd);
24 clip_image_f32_free(img_res);
25 if (!encoded) {
26 fprintf(stderr, "Unable to encode image\n");
27
28 return false;
29 }
30
31 const int64_t t_img_enc_end_us = ggml_time_us();
32 float t_img_enc_ms = (t_img_enc_end_us - t_img_enc_start_us) / 1000.0;
33
34 printf("\n%s: image encoded in %8.2f ms by CLIP (%8.2f ms per image patch)\n", __func__, t_img_enc_ms, t_img_enc_ms / *n_img_pos);
35
36 return true;
37}
38
39bool llava_validate_embed_size(const llama_context * ctx_llama, const clip_ctx * ctx_clip) {
40 // make sure that the correct mmproj was used, i.e., compare apples to apples

Callers 1

Calls 8

make_clip_image_f32Function · 0.85
fprintfFunction · 0.85
clip_n_patchesFunction · 0.85
printfFunction · 0.85
clip_image_preprocessFunction · 0.70
clip_image_f32_freeFunction · 0.70
clip_image_encodeFunction · 0.70
ggml_time_usFunction · 0.50

Tested by

no test coverage detected