26 template <
typename PixelType,
typename ColorType>
32 const PixelType x_input_units_per_pixel,
33 const PixelType y_input_units_per_pixel,
34 const float max_color_value,
35 const int64_t tile_boundary_halo_pixels,
38 const float min_confidence_threshold,
39 const float iou_threshold,
41 const int64_t device_num,
49 std::shared_ptr<CpuTimer> timer =
50 std::make_shared<CpuTimer>(
"tf_torch_raster_obj_detect");
52 timer->start_event_timer(
"get_model_info_from_file");
53 const std::string model_path_str(model_path.
getString());
54 std::string model_metadata_path_str(model_metadata_path.
getString());
55 if (model_metadata_path_str.empty()) {
56 model_metadata_path_str = model_path_str;
59 if (!model_info.is_valid) {
60 return mgr.ERROR_MESSAGE(
"Could not get model info from file.");
62 if (model_info.class_labels.empty()) {
63 return mgr.ERROR_MESSAGE(
"Could not get class labels from file.");
65 const auto class_idx_to_label_vec =
67 model_info.class_labels);
68 const int64_t num_class_labels =
static_cast<int64_t
>(class_idx_to_label_vec.size());
70 constexpr int64_t target_batch_size_multiple{8};
73 RasterFormat_Namespace::format_raster_data<PixelType, ColorType, float>(
77 x_input_units_per_pixel,
78 y_input_units_per_pixel,
80 model_info.raster_tile_width,
81 model_info.raster_tile_height,
82 tile_boundary_halo_pixels,
83 target_batch_size_multiple,
84 timer->start_nested_event_timer(
"format_raster_data"));
94 min_confidence_threshold,
96 timer->start_nested_event_timer(
"detect_objects_in_tiled_raster"));
97 timer->start_event_timer(
"Write results");
98 const int64_t num_detections = processed_detections.size();
102 for (int64_t detection_idx = 0; detection_idx < num_detections; ++detection_idx) {
103 const auto class_idx = processed_detections[detection_idx].class_idx;
104 detected_class_id[detection_idx] =
class_idx;
105 if (class_idx < 0 || class_idx >= num_class_labels) {
106 detected_class_label.
setNull(detection_idx);
108 detected_class_label[detection_idx] = class_idx_to_label_vec[
class_idx];
110 detected_centroid_x[detection_idx] = processed_detections[detection_idx].centroid_x;
111 detected_centroid_y[detection_idx] = processed_detections[detection_idx].centroid_y;
112 detected_width[detection_idx] = processed_detections[detection_idx].width;
113 detected_height[detection_idx] = processed_detections[detection_idx].height;
114 detected_confidence[detection_idx] = processed_detections[detection_idx].confidence;
116 return num_detections;
117 }
catch (
const std::runtime_error& e) {
118 return mgr.ERROR_MESSAGE(e.what());
128 const float x_input_units_per_pixel,
129 const float y_input_units_per_pixel,
130 const float max_color_value,
131 const int64_t tile_boundary_halo_pixels,
134 const float min_confidence_threshold,
135 const float iou_threshold,
137 const int64_t device_num,
151 const float x_input_units_per_pixel,
152 const float y_input_units_per_pixel,
153 const float max_color_value,
154 const int64_t tile_boundary_halo_pixels,
157 const float min_confidence_threshold,
158 const float iou_threshold,
160 const int64_t device_num,
174 const double x_input_units_per_pixel,
175 const double y_input_units_per_pixel,
176 const float max_color_value,
177 const int64_t tile_boundary_halo_pixels,
180 const float min_confidence_threshold,
181 const float iou_threshold,
183 const int64_t device_num,
197 const double x_input_units_per_pixel,
198 const double y_input_units_per_pixel,
199 const float max_color_value,
200 const int64_t tile_boundary_halo_pixels,
203 const float min_confidence_threshold,
204 const float iou_threshold,
206 const int64_t device_num,
void set_output_row_size(int64_t num_rows)
ModelInfo get_model_info_from_file(const std::string &filename)
std::string getString() const
std::vector< Detection > detect_objects_in_tiled_raster(const std::string &model_path, const ModelInfo &model_info, const bool use_gpu, const int64_t device_num, std::vector< float > &raster_data, const RasterFormat_Namespace::RasterInfo &raster_info, const float min_confidence_threshold, const float iou_threshold, std::shared_ptr< CpuTimer > timer)
DEVICE void setNull(int64_t index)
StringDictionaryProxy * string_dict_proxy_
TEMPLATE_NOINLINE int32_t tf_torch_raster_obj_detect__cpu_template(TableFunctionManager &mgr, const Column< PixelType > &input_x, const Column< PixelType > &input_y, const ColumnList< ColorType > &input_channels, const PixelType x_input_units_per_pixel, const PixelType y_input_units_per_pixel, const float max_color_value, const int64_t tile_boundary_halo_pixels, const TextEncodingNone &model_path, const TextEncodingNone &model_metadata_path, const float min_confidence_threshold, const float iou_threshold, const bool use_gpu, const int64_t device_num, Column< TextEncodingDict > &detected_class_label, Column< int32_t > &detected_class_id, Column< double > &detected_centroid_x, Column< double > &detected_centroid_y, Column< double > &detected_width, Column< double > &detected_height, Column< float > &detected_confidence)
std::vector< int32_t > getOrAddTransientBulk(const std::vector< std::string > &strings)
#define TEMPLATE_NOINLINE