ssd anchors calculator add fixed anchors.
PiperOrigin-RevId: 509574814
This commit is contained in:
		
							parent
							
								
									a578a702ec
								
							
						
					
					
						commit
						c66b7e83f0
					
				|  | @ -26,6 +26,7 @@ mediapipe_proto_library( | |||
|     deps = [ | ||||
|         "//mediapipe/framework:calculator_options_proto", | ||||
|         "//mediapipe/framework:calculator_proto", | ||||
|         "//mediapipe/framework/formats/object_detection:anchor_proto", | ||||
|     ], | ||||
| ) | ||||
| 
 | ||||
|  |  | |||
|  | @ -162,6 +162,21 @@ class SsdAnchorsCalculator : public CalculatorBase { | |||
|         cc->Options<SsdAnchorsCalculatorOptions>(); | ||||
| 
 | ||||
|     auto anchors = absl::make_unique<std::vector<Anchor>>(); | ||||
|     if (!options.fixed_anchors().empty()) { | ||||
|       // Check fields for generating anchors are not set.
 | ||||
|       if (options.has_input_size_height() || options.has_input_size_width() || | ||||
|           options.has_min_scale() || options.has_max_scale() || | ||||
|           options.has_num_layers() || options.multiscale_anchor_generation()) { | ||||
|         return absl::InvalidArgumentError( | ||||
|             "Fixed anchors are provided, but fields are set for generating " | ||||
|             "anchors. When fixed anchors are set, fields for generating " | ||||
|             "anchors must not be set."); | ||||
|       } | ||||
|       anchors->assign(options.fixed_anchors().begin(), | ||||
|                       options.fixed_anchors().end()); | ||||
|       cc->OutputSidePackets().Index(0).Set(Adopt(anchors.release())); | ||||
|       return absl::OkStatus(); | ||||
|     } | ||||
|     MP_RETURN_IF_ERROR(GenerateAnchors(anchors.get(), options)); | ||||
|     cc->OutputSidePackets().Index(0).Set(Adopt(anchors.release())); | ||||
|     return absl::OkStatus(); | ||||
|  |  | |||
|  | @ -17,6 +17,7 @@ syntax = "proto2"; | |||
| package mediapipe; | ||||
| 
 | ||||
| import "mediapipe/framework/calculator.proto"; | ||||
| import "mediapipe/framework/formats/object_detection/anchor.proto"; | ||||
| 
 | ||||
| // Options to generate anchors for SSD object detection models. | ||||
| message SsdAnchorsCalculatorOptions { | ||||
|  | @ -24,20 +25,22 @@ message SsdAnchorsCalculatorOptions { | |||
|     optional SsdAnchorsCalculatorOptions ext = 247258239; | ||||
|   } | ||||
|   // Size of input images. | ||||
|   optional int32 input_size_width = 1;   // required | ||||
|   optional int32 input_size_height = 2;  // required | ||||
|   optional int32 input_size_width = 1;   // required for generating anchors. | ||||
|   optional int32 input_size_height = 2;  // required for generating anchros. | ||||
| 
 | ||||
|   // Min and max scales for generating anchor boxes on feature maps. | ||||
|   optional float min_scale = 3;  // required | ||||
|   optional float max_scale = 4;  // required | ||||
|   optional float min_scale = 3;  // required for generating anchors. | ||||
|   optional float max_scale = 4;  // required for generating anchors. | ||||
| 
 | ||||
|   // The offset for the center of anchors. The value is in the scale of stride. | ||||
|   // E.g. 0.5 meaning 0.5 * |current_stride| in pixels. | ||||
|   optional float anchor_offset_x = 5 [default = 0.5];  // required | ||||
|   optional float anchor_offset_y = 6 [default = 0.5];  // required | ||||
|   optional float anchor_offset_x = 5 | ||||
|       [default = 0.5];  // required for generating anchors. | ||||
|   optional float anchor_offset_y = 6 | ||||
|       [default = 0.5];  // required for generating anchors. | ||||
| 
 | ||||
|   // Number of output feature maps to generate the anchors on. | ||||
|   optional int32 num_layers = 7;  // required | ||||
|   optional int32 num_layers = 7;  // required for generating anchors. | ||||
|   // Sizes of output feature maps to create anchors. Either feature_map size or | ||||
|   // stride should be provided. | ||||
|   repeated int32 feature_map_width = 8; | ||||
|  | @ -86,4 +89,8 @@ message SsdAnchorsCalculatorOptions { | |||
|   // Whether to produce anchors in normalized coordinates. | ||||
|   // for multiscale_anchor_generation only! | ||||
|   optional bool normalize_coordinates = 20 [default = true]; | ||||
| 
 | ||||
|   // Fixed list of anchors. If set, all the other options to generate anchors | ||||
|   // are ignored. | ||||
|   repeated Anchor fixed_anchors = 21; | ||||
| } | ||||
|  |  | |||
|  | @ -15,19 +15,13 @@ | |||
| # Description: | ||||
| #   Working with dense optical flow in mediapipe. | ||||
| 
 | ||||
| load("//mediapipe/framework/port:build_config.bzl", "mediapipe_cc_proto_library") | ||||
| load("//mediapipe/framework/port:build_config.bzl", "mediapipe_proto_library") | ||||
| 
 | ||||
| licenses(["notice"]) | ||||
| 
 | ||||
| package(default_visibility = ["//visibility:public"]) | ||||
| 
 | ||||
| proto_library( | ||||
| mediapipe_proto_library( | ||||
|     name = "anchor_proto", | ||||
|     srcs = ["anchor.proto"], | ||||
| ) | ||||
| 
 | ||||
| mediapipe_cc_proto_library( | ||||
|     name = "anchor_cc_proto", | ||||
|     srcs = ["anchor.proto"], | ||||
|     deps = [":anchor_proto"], | ||||
| ) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user