99#include < iostream>
1010#include < onnxruntime_cxx_api.h>
1111#include < opencv2/imgcodecs.hpp>
12-
12+ # include " 3rdParty/ONNX/OnnxToolsPA.h "
1313#include " SegmentAnythingModel.h"
1414
1515namespace PokemonAutomation {
@@ -52,14 +52,14 @@ template<typename T, class Buffer, class Shape> Ort::Value create_tensor(const O
5252
5353
5454SAMEmbedderSession::SAMEmbedderSession (const std::string& model_path)
55- : session_options(create_session_option())
56- , session{env, model_path.c_str (), session_options}
57- , memory_info{Ort::MemoryInfo::CreateCpu (OrtDeviceAllocator, OrtMemTypeCPU)}
58- , input_names{session.GetInputNames ()}
59- , output_names{session.GetOutputNames ()}
60- , input_shape{1 , SAM_EMBEDDER_INPUT_IMAGE_HEIGHT, SAM_EMBEDDER_INPUT_IMAGE_WIDTH, 3 }
61- , output_shape{1 , SAM_EMBEDDER_OUTPUT_N_CHANNELS, SAM_EMBEDDER_OUTPUT_IMAGE_SIZE, SAM_EMBEDDER_OUTPUT_IMAGE_SIZE}
62- , model_input(SAM_EMBEDDER_INPUT_SIZE)
55+ : session_options(create_session_option())
56+ , session{env, str_to_onnx_str ( model_path) .c_str (), session_options}
57+ , memory_info{Ort::MemoryInfo::CreateCpu (OrtDeviceAllocator, OrtMemTypeCPU)}
58+ , input_names{session.GetInputNames ()}
59+ , output_names{session.GetOutputNames ()}
60+ , input_shape{1 , SAM_EMBEDDER_INPUT_IMAGE_HEIGHT, SAM_EMBEDDER_INPUT_IMAGE_WIDTH, 3 }
61+ , output_shape{1 , SAM_EMBEDDER_OUTPUT_N_CHANNELS, SAM_EMBEDDER_OUTPUT_IMAGE_SIZE, SAM_EMBEDDER_OUTPUT_IMAGE_SIZE}
62+ , model_input(SAM_EMBEDDER_INPUT_SIZE)
6363{
6464 std::cout << " Built SAM embedder session" << std::endl;
6565}
@@ -92,17 +92,17 @@ void SAMEmbedderSession::run(cv::Mat& input_image, std::vector<float>& model_out
9292
9393
9494SAMSession::SAMSession (const std::string& model_path)
95- : session_options(create_session_option())
96- , session{env, model_path.c_str (), session_options}
97- , memory_info{Ort::MemoryInfo::CreateCpu (OrtDeviceAllocator, OrtMemTypeCPU)}
98- , input_names{session.GetInputNames ()}
99- , output_names{session.GetOutputNames ()}
100- , input_image_embedding_shape{1 , SAM_EMBEDDER_OUTPUT_N_CHANNELS,
101- SAM_EMBEDDER_OUTPUT_IMAGE_SIZE, SAM_EMBEDDER_OUTPUT_IMAGE_SIZE}
102- , input_mask_shape{1 , 1 , SAM_LOW_RES_MASK_SIZE, SAM_LOW_RES_MASK_SIZE}
103- , output_low_res_mask_shape{1 , 1 , SAM_LOW_RES_MASK_SIZE, SAM_LOW_RES_MASK_SIZE}
104- , input_mask_buffer(SAM_LOW_RES_MASK_SIZE * SAM_LOW_RES_MASK_SIZE, 0.0 )
105- , output_low_res_mask_buffer(SAM_LOW_RES_MASK_SIZE * SAM_LOW_RES_MASK_SIZE, 0.0 )
95+ : session_options(create_session_option())
96+ , session{env, str_to_onnx_str ( model_path) .c_str (), session_options}
97+ , memory_info{Ort::MemoryInfo::CreateCpu (OrtDeviceAllocator, OrtMemTypeCPU)}
98+ , input_names{session.GetInputNames ()}
99+ , output_names{session.GetOutputNames ()}
100+ , input_image_embedding_shape{1 , SAM_EMBEDDER_OUTPUT_N_CHANNELS,
101+ SAM_EMBEDDER_OUTPUT_IMAGE_SIZE, SAM_EMBEDDER_OUTPUT_IMAGE_SIZE}
102+ , input_mask_shape{1 , 1 , SAM_LOW_RES_MASK_SIZE, SAM_LOW_RES_MASK_SIZE}
103+ , output_low_res_mask_shape{1 , 1 , SAM_LOW_RES_MASK_SIZE, SAM_LOW_RES_MASK_SIZE}
104+ , input_mask_buffer(SAM_LOW_RES_MASK_SIZE * SAM_LOW_RES_MASK_SIZE, 0.0 )
105+ , output_low_res_mask_buffer(SAM_LOW_RES_MASK_SIZE * SAM_LOW_RES_MASK_SIZE, 0.0 )
106106{
107107 std::cout << " Built SAM session" << std::endl;
108108}
@@ -121,7 +121,7 @@ void SAMSession::run(
121121 assert (input_box.size () == 0 || input_box.size () == 4 ); // 4 is x_min, y_min, x_max, y_max
122122 assert (input_points.size () > 0 || input_box.size () > 0 );
123123
124- int num_points = input_points.size () / 2 ;
124+ size_t num_points = input_points.size () / 2 ;
125125 if (input_box.size () > 0 ){
126126 num_points += 2 ; // add the bounding box two corners
127127 }
@@ -247,4 +247,4 @@ bool load_image_embedding(const std::string& image_filepath, std::vector<float>&
247247
248248
249249}
250- }
250+ }
0 commit comments