mirror of
				https://github.com/PaddlePaddle/FastDeploy.git
				synced 2025-10-31 03:46:40 +08:00 
			
		
		
		
	 625845c7d6
			
		
	
	625845c7d6
	
	
	
		
			
			* Update ppseg backend support type * Update ppseg preprocess if condition * Update README.md * Update README.md * Update README.md * Update ppseg with eigen functions * Delete old argmax function * Update README.md * Delete apply_softmax in ppseg example demo * Update ppseg code with createFromTensor function * Delete FDTensor2CVMat function * Update README.md * Update README.md * Update README.md * Update README.md * Update ppseg model.cc with transpose&&softmax in place convert * Update segmentation_result.md * Update model.cc * Update README.md * Update README.md Co-authored-by: Jason <jiangjiajun@baidu.com>
		
			
				
	
	
		
			79 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			79 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| // Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
 | |
| //
 | |
| // Licensed under the Apache License, Version 2.0 (the "License");
 | |
| // you may not use this file except in compliance with the License.
 | |
| // You may obtain a copy of the License at
 | |
| //
 | |
| //     http://www.apache.org/licenses/LICENSE-2.0
 | |
| //
 | |
| // Unless required by applicable law or agreed to in writing, software
 | |
| // distributed under the License is distributed on an "AS IS" BASIS,
 | |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | |
| // See the License for the specific language governing permissions and
 | |
| // limitations under the License.
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <set>
 | |
| #include <vector>
 | |
| #include "fastdeploy/core/fd_tensor.h"
 | |
| #include "fastdeploy/utils/utils.h"
 | |
| #include "fastdeploy/vision/common/result.h"
 | |
| 
 | |
| // #include "unsupported/Eigen/CXX11/Tensor"
 | |
| #include "fastdeploy/function/reduce.h"
 | |
| #include "fastdeploy/function/softmax.h"
 | |
| #include "fastdeploy/function/transpose.h"
 | |
| 
 | |
| namespace fastdeploy {
 | |
| namespace vision {
 | |
| namespace utils {
 | |
| // topk sometimes is a very small value
 | |
| // so this implementation is simple but I don't think it will
 | |
| // cost too much time
 | |
| // Also there may be cause problem since we suppose the minimum value is
 | |
| // -99999999
 | |
| // Do not use this function on array which topk contains value less than
 | |
| // -99999999
 | |
| template <typename T>
 | |
| std::vector<int32_t> TopKIndices(const T* array, int array_size, int topk) {
 | |
|   topk = std::min(array_size, topk);
 | |
|   std::vector<int32_t> res(topk);
 | |
|   std::set<int32_t> searched;
 | |
|   for (int32_t i = 0; i < topk; ++i) {
 | |
|     T min = -99999999;
 | |
|     for (int32_t j = 0; j < array_size; ++j) {
 | |
|       if (searched.find(j) != searched.end()) {
 | |
|         continue;
 | |
|       }
 | |
|       if (*(array + j) > min) {
 | |
|         res[i] = j;
 | |
|         min = *(array + j);
 | |
|       }
 | |
|     }
 | |
|     searched.insert(res[i]);
 | |
|   }
 | |
|   return res;
 | |
| }
 | |
| 
 | |
| void NMS(DetectionResult* output, float iou_threshold = 0.5);
 | |
| 
 | |
| void NMS(FaceDetectionResult* result, float iou_threshold = 0.5);
 | |
| 
 | |
| // MergeSort
 | |
| void SortDetectionResult(DetectionResult* output);
 | |
| 
 | |
| void SortDetectionResult(FaceDetectionResult* result);
 | |
| 
 | |
| // L2 Norm / cosine similarity  (for face recognition, ...)
 | |
| FASTDEPLOY_DECL std::vector<float> L2Normalize(
 | |
|     const std::vector<float>& values);
 | |
| 
 | |
| FASTDEPLOY_DECL float CosineSimilarity(const std::vector<float>& a,
 | |
|                                        const std::vector<float>& b,
 | |
|                                        bool normalized = true);
 | |
| 
 | |
| }  // namespace utils
 | |
| }  // namespace vision
 | |
| }  // namespace fastdeploy
 |