36 using InferResultArray =
37 std::vector<::reusex::vision::common::object::DetectionBoxArray>;
51 const std::string &text_encoder_path,
52 const std::string &geometry_encoder_path,
53 const std::string &decoder_path,
54 const std::string &tokenizer_path,
int gpu_id);
61 static std::unique_ptr<TensorRTSam3>
62 create(
const std::filesystem::path &model_path);
71 std::vector<IDataset::Pair>
72 forward(
const std::span<IDataset::Pair> &input)
override;
89 const cv::Mat &image,
const std::string &label,
90 const std::vector<std::pair<std::string, std::array<float, 4>>> &boxes);
112 void preprocess(
const TensorRTData &input,
int ibatch,
void *stream);
114 bool encode_image(
int batch_size,
void *stream);
118 void gather_vision_features(
const std::vector<PromptMeta> &batch_prompts,
119 int batch_size,
void *stream);
122 bool encode_text(
const std::vector<PromptMeta> &batch_prompts,
int batch_size,
124 bool encode_boxes(
const std::vector<PromptMeta> &batch_prompts,
125 int batch_size,
int max_boxes,
void *stream);
126 bool decode(
int batch_size,
int prompt_len,
void *stream);
129 void postprocess(InferResult &image_result,
int batch_idx,
int image_idx,
130 const std::string &label,
const int label_id,
131 float confidence_threshold,
bool return_mask,
void *stream);
140 void allocate_memory_once();
142 void set_binding_dim(std::shared_ptr<TensorRT::Engine> &engine,
143 int binding_index,
const std::vector<int> &dims);
147 bool isdynamic_model_ =
true;
148 int input_image_width_ = 1008;
149 int input_image_height_ = 1008;
154 const int max_image_batch_ =
157 const int max_prompt_batch_ =
160 const int max_boxes_per_prompt_ =
164 std::vector<std::pair<int, int>>
165 original_image_sizes_;
166 int num_queries_ = 200;
167 int mask_height_ = 288;
168 int mask_width_ = 288;
171 std::string vision_encoder_path_;
172 std::string text_encoder_path_;
173 std::string geometry_encoder_path_;
174 std::string decoder_path_;
177 std::shared_ptr<TensorRT::Engine> vision_encoder_trt_;
178 std::shared_ptr<TensorRT::Engine> text_encoder_trt_;
179 std::shared_ptr<TensorRT::Engine> decoder_trt_;
180 std::shared_ptr<TensorRT::Engine> geometry_encoder_trt_;
188 std::unordered_map<std::string, std::tuple<std::array<int64_t, 32>,
189 std::array<int64_t, 32>,
int>>
196 std::vector<int> vision_input_shape_;
197 std::vector<int> fpn_feat_0_shape_;
198 std::vector<int> text_ids_shape_;
199 std::vector<int> geom_box_shape_;
203 std::vector<std::shared_ptr<tensor::Memory<uint8_t>>> original_images_buf_;
236 std::unordered_map<std::string, std::shared_ptr<tensor::Memory<float>>>
237 geom_features_cache_;
238 std::unordered_map<std::string, std::shared_ptr<tensor::Memory<bool>>>
257 box_affine_matrices_;
260 std::unique_ptr<tokenizers::Tokenizer> tokenizer_;
TensorRTSam3(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 &tokenizer_path, int gpu_id)