forked from YavorGIvanov/sam.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sam.h
59 lines (48 loc) · 1.43 KB
/
sam.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once
#include <vector>
#include <cstdint>
#include <string>
#include <thread>
#include <memory>
struct sam_point {
float x = 0;
float y = 0;
};
// RGB uint8 image
struct sam_image_u8 {
int nx = 0;
int ny = 0;
std::vector<uint8_t> data;
};
struct sam_params {
int32_t seed = -1; // RNG seed
int32_t n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency());
std::string model = "../checkpoints/ggml-model-f16-b.bin"; // model path
std::string fname_inp = "../img.jpg";
std::string fname_out = "img.out";
};
struct sam_ggml_state;
struct sam_ggml_model;
struct sam_state {
std::unique_ptr<sam_ggml_state> state;
std::unique_ptr<sam_ggml_model> model;
int t_load_ms = 0;
int t_compute_img_ms = 0;
int t_compute_masks_ms = 0;
};
std::shared_ptr<sam_state> sam_load_model(
const sam_params & params);
bool sam_compute_embd_img(
const sam_image_u8 & img,
int n_threads ,
sam_state & state);
// returns masks sorted by the sum of the iou_score and stability_score in descending order
std::vector<sam_image_u8> sam_compute_masks(
const sam_image_u8 & img,
int n_threads,
sam_point pt,
sam_state & state,
int mask_on_val = 255,
int mask_off_val = 0);
void sam_deinit(
sam_state & state);