56 const std::string &text_encoder_path,
57 const std::string &geometry_encoder_path,
58 const std::string &decoder_path,
59 const std::string &memory_encoder_path,
60 const std::string &memory_attention_path,
61 const std::string &tokenizer_path,
62 const std::filesystem::path &meta_path,
int gpu_id);
72 static std::unique_ptr<TensorRTSam3p1>
73 create(
const std::filesystem::path &model_path);
96 void preprocess(
const TensorRTData &input,
void *stream);
99 bool encode_image(
void *stream);
107 bool decode(
void *stream);
111 void postprocess(InferResult &image_result,
const std::string &label,
112 int label_id,
float confidence_threshold,
void *stream);
122 void append_memory(
float object_score_logits,
void *stream);
130 int pack_memory(
void *stream);
136 bool apply_memory_attention(
void *stream);
142 void build_aggregate_mask(
const InferResult &results,
void *stream);
149 void rearrange_chw_to_hwc(
float *d_src,
float *d_dst,
int c,
int h,
int w,
154 void allocate_memory_once();
157 void set_binding_dim(std::shared_ptr<TensorRT::Engine> &engine,
158 int binding_index,
const std::vector<int> &dims);
162 bool isdynamic_model_ =
true;
163 int input_image_width_ = 1008;
164 int input_image_height_ = 1008;
168 std::pair<int, int> original_image_size_ = {0, 0};
169 int num_queries_ = 200;
170 int mask_height_ = 288;
171 int mask_width_ = 288;
178 int mem_bank_max_ = 7;
179 int mem_tokens_per_frame_ = 0;
184 int multiplex_count_ = 1;
185 int frame_counter_ = 0;
193 bool use_memory_conditioning_ =
false;
196 std::string vision_encoder_path_;
197 std::string text_encoder_path_;
198 std::string geometry_encoder_path_;
199 std::string decoder_path_;
200 std::string memory_encoder_path_;
201 std::string memory_attention_path_;
204 std::shared_ptr<TensorRT::Engine> vision_encoder_trt_;
205 std::shared_ptr<TensorRT::Engine> text_encoder_trt_;
206 std::shared_ptr<TensorRT::Engine> decoder_trt_;
207 std::shared_ptr<TensorRT::Engine> geometry_encoder_trt_;
208 std::shared_ptr<TensorRT::Engine> memory_encoder_trt_;
209 std::shared_ptr<TensorRT::Engine> memory_attention_trt_;
213 std::unordered_map<std::string, std::tuple<std::array<int64_t, 32>,
214 std::array<int64_t, 32>,
int>>
222 std::vector<int> vision_input_shape_;
223 std::vector<int> fpn_feat_0_shape_;
224 std::vector<int> text_ids_shape_;
228 std::shared_ptr<tensor::Memory<uint8_t>> original_image_buf_;
289 std::vector<MemorySlot> mem_slots_;
292 std::deque<int> mem_valid_;
294 int mem_next_slot_ = 0;
298 tensor::Memory<float> current_feat_;
299 tensor::Memory<float> current_pos_;
306 tensor::Memory<float> mem_feat_concat_;
307 tensor::Memory<float> mem_pos_concat_;
308 tensor::Memory<bool> memory_mask_;
312 tensor::Memory<float> pix_feat_with_mem_;
315 std::unique_ptr<tokenizers::Tokenizer> tokenizer_;
TensorRTSam3p1(const std::string &vision_encoder_path, const std::string &text_encoder_path, const std::string &geometry_encoder_path, const std::string &decoder_path, const std::string &memory_encoder_path, const std::string &memory_attention_path, const std::string &tokenizer_path, const std::filesystem::path &meta_path, int gpu_id)