| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | //
 | 
					
						
							|  |  |  | //  ShapeNonMaxSuppressionV2.cpp
 | 
					
						
							|  |  |  | //  MNN
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  Created by MNN on 2019/01/10.
 | 
					
						
							|  |  |  | //  Copyright © 2018, Alibaba Group Holding Limited
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-05 16:41:56 +08:00
										 |  |  | #include "shape/SizeComputer.hpp"
 | 
					
						
							| 
									
										
										
										
											2019-12-27 22:16:57 +08:00
										 |  |  | #include "core/Macro.h"
 | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace MNN { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class NonMaxSuppressionV2Computer : public SizeComputer { | 
					
						
							|  |  |  |     virtual bool onComputeSize(const MNN::Op* op, const std::vector<Tensor*>& inputs, | 
					
						
							|  |  |  |                                const std::vector<Tensor*>& outputs) const override { | 
					
						
							|  |  |  |         // boxes: [num_boxes, 4]
 | 
					
						
							|  |  |  |         const Tensor* boxes = inputs[0]; | 
					
						
							|  |  |  |         // scores: [num_boxes]
 | 
					
						
							|  |  |  |         const Tensor* scores = inputs[1]; | 
					
						
							|  |  |  |         // iou_threshold: scalar
 | 
					
						
							| 
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 |  |  |         if (inputs.size() > 3 && inputs[3]->host<float>() != nullptr) { | 
					
						
							|  |  |  |             auto iou_threshold_val = inputs[3]->host<float>()[0]; | 
					
						
							|  |  |  |             MNN_ASSERT(iou_threshold_val >= 0 && iou_threshold_val <= 1); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  |         int num_boxes = 0; | 
					
						
							|  |  |  |         MNN_ASSERT(boxes->buffer().dimensions == 2); | 
					
						
							|  |  |  |         num_boxes = boxes->buffer().dim[0].extent; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         MNN_ASSERT(boxes->buffer().dimensions == 2 && scores->buffer().dim[0].extent == num_boxes && | 
					
						
							|  |  |  |                    boxes->buffer().dim[1].extent == 4 && scores->buffer().dimensions == 1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-04 10:50:40 +08:00
										 |  |  |         int output_size = num_boxes; | 
					
						
							|  |  |  |         if (inputs.size() > 2 && inputs[2]->host<int32_t>() != nullptr) { | 
					
						
							|  |  |  |             output_size = std::min(inputs[2]->host<int32_t>()[0], num_boxes); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // TODO ramdom output shape only for fast rcnn
 | 
					
						
							|  |  |  |         outputs[0]->buffer().dimensions = 1; | 
					
						
							|  |  |  |         outputs[0]->setType(MNN::DataType_DT_INT32); | 
					
						
							|  |  |  |         outputs[0]->buffer().dim[0].extent = output_size; | 
					
						
							| 
									
										
										
										
											2019-08-22 20:13:46 +08:00
										 |  |  |         TensorUtils::getDescribe(outputs[0])->dimensionFormat = TensorUtils::getDescribe(inputs[0])->dimensionFormat; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-22 20:13:46 +08:00
										 |  |  | REGISTER_SHAPE_INPUTS(NonMaxSuppressionV2Computer, OpType_NonMaxSuppressionV2, (std::vector<int>{2, 3})); | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | } // namespace MNN
 |