clip.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef CLIP_H
  2. #define CLIP_H
  3. #include "ggml.h"
  4. struct clip_ctx;
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. struct clip_vision_hparams {
  9. int32_t image_size;
  10. int32_t patch_size;
  11. int32_t hidden_size;
  12. int32_t n_intermediate;
  13. int32_t projection_dim;
  14. int32_t n_head;
  15. int32_t n_layer;
  16. float eps;
  17. };
  18. struct clip_ctx * clip_model_load(const char * fname, const int verbosity);
  19. void clip_free(struct clip_ctx * ctx);
  20. size_t clip_embd_nbytes(struct clip_ctx * ctx);
  21. int clip_n_patches(struct clip_ctx * ctx);
  22. int clip_n_mmproj_embd(struct clip_ctx * ctx);
  23. // RGB uint8 image
  24. struct clip_image_u8 {
  25. int nx;
  26. int ny;
  27. uint8_t * data;
  28. size_t size;
  29. };
  30. // RGB float32 image (NHWC)
  31. // Memory layout: RGBRGBRGB...
  32. struct clip_image_f32 {
  33. int nx;
  34. int ny;
  35. float * data;
  36. size_t size;
  37. };
  38. struct clip_image_u8_batch {
  39. struct clip_image_u8 * data;
  40. size_t size;
  41. };
  42. struct clip_image_f32_batch {
  43. struct clip_image_f32 * data;
  44. size_t size;
  45. };
  46. struct clip_image_u8 * make_clip_image_u8();
  47. struct clip_image_f32 * make_clip_image_f32();
  48. bool clip_image_load_from_file(const char * fname, struct clip_image_u8 * img);
  49. bool clip_image_preprocess(const struct clip_ctx * ctx, const struct clip_image_u8 * img, struct clip_image_f32 * res, const bool pad2square);
  50. bool clip_image_encode(const struct clip_ctx * ctx, const int n_threads, struct clip_image_f32 * img, float * vec);
  51. bool clip_image_batch_encode(const struct clip_ctx * ctx, const int n_threads, const struct clip_image_f32_batch * imgs,
  52. float * vec);
  53. bool clip_model_quantize(const char * fname_inp, const char * fname_out, const int itype);
  54. #ifdef __cplusplus
  55. }
  56. #endif
  57. #endif // CLIP_H