clip.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef CLIP_H
  2. #define CLIP_H
  3. #include <stddef.h>
  4. #include <stdint.h>
  5. #ifdef LLAMA_SHARED
  6. # if defined(_WIN32) && !defined(__MINGW32__)
  7. # ifdef LLAMA_BUILD
  8. # define CLIP_API __declspec(dllexport)
  9. # else
  10. # define CLIP_API __declspec(dllimport)
  11. # endif
  12. # else
  13. # define CLIP_API __attribute__ ((visibility ("default")))
  14. # endif
  15. #else
  16. # define CLIP_API
  17. #endif
  18. struct clip_ctx;
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. struct clip_vision_hparams {
  23. int32_t image_size;
  24. int32_t patch_size;
  25. int32_t hidden_size;
  26. int32_t n_intermediate;
  27. int32_t projection_dim;
  28. int32_t n_head;
  29. int32_t n_layer;
  30. float eps;
  31. };
  32. CLIP_API struct clip_ctx * clip_model_load(const char * fname, int verbosity);
  33. CLIP_API void clip_free(struct clip_ctx * ctx);
  34. CLIP_API size_t clip_embd_nbytes(const struct clip_ctx * ctx);
  35. CLIP_API int clip_n_patches (const struct clip_ctx * ctx);
  36. CLIP_API int clip_n_mmproj_embd(const struct clip_ctx * ctx);
  37. struct clip_image_u8_batch {
  38. struct clip_image_u8 * data;
  39. size_t size;
  40. };
  41. struct clip_image_f32_batch {
  42. struct clip_image_f32 * data;
  43. size_t size;
  44. };
  45. CLIP_API struct clip_image_u8 * clip_image_u8_init ();
  46. CLIP_API struct clip_image_f32 * clip_image_f32_init();
  47. CLIP_API void clip_image_u8_free (struct clip_image_u8 * img);
  48. CLIP_API void clip_image_f32_free(struct clip_image_f32 * img);
  49. CLIP_API bool clip_image_load_from_file(const char * fname, struct clip_image_u8 * img);
  50. /** interpret bytes as an image file with length bytes_length, and use the result to populate img */
  51. CLIP_API bool clip_image_load_from_bytes(const unsigned char * bytes, size_t bytes_length, struct clip_image_u8 * img);
  52. CLIP_API bool clip_image_preprocess (struct clip_ctx * ctx, const struct clip_image_u8 * img, struct clip_image_f32 * res, bool pad2square);
  53. CLIP_API bool clip_image_encode (struct clip_ctx * ctx, int n_threads, struct clip_image_f32 * img, float * vec);
  54. CLIP_API bool clip_image_batch_encode(struct clip_ctx * ctx, int n_threads, const struct clip_image_f32_batch * imgs, float * vec);
  55. CLIP_API bool clip_model_quantize(const char * fname_inp, const char * fname_out, int itype);
  56. #ifdef __cplusplus
  57. }
  58. #endif
  59. #endif // CLIP_H