mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-25 09:31:38 +08:00
Update ppseg with eigen functions (#238)
* 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>
This commit is contained in:
@@ -116,5 +116,56 @@ FDDataType Mat::Type() {
|
||||
}
|
||||
}
|
||||
|
||||
Mat CreateFromTensor(const FDTensor& tensor) {
|
||||
int type = tensor.dtype;
|
||||
cv::Mat temp_mat;
|
||||
FDASSERT(tensor.shape.size() == 3,
|
||||
"When create FD Mat from tensor, tensor shape should be 3-Dim, HWC "
|
||||
"layout");
|
||||
int64_t height = tensor.shape[0];
|
||||
int64_t width = tensor.shape[1];
|
||||
int64_t channel = tensor.shape[2];
|
||||
switch (type) {
|
||||
case FDDataType::UINT8:
|
||||
temp_mat = cv::Mat(height, width, CV_8UC(channel),
|
||||
const_cast<void*>(tensor.Data()));
|
||||
break;
|
||||
|
||||
case FDDataType::INT8:
|
||||
temp_mat = cv::Mat(height, width, CV_8SC(channel),
|
||||
const_cast<void*>(tensor.Data()));
|
||||
break;
|
||||
|
||||
case FDDataType::INT16:
|
||||
temp_mat = cv::Mat(height, width, CV_16SC(channel),
|
||||
const_cast<void*>(tensor.Data()));
|
||||
break;
|
||||
|
||||
case FDDataType::INT32:
|
||||
temp_mat = cv::Mat(height, width, CV_32SC(channel),
|
||||
const_cast<void*>(tensor.Data()));
|
||||
break;
|
||||
|
||||
case FDDataType::FP32:
|
||||
temp_mat = cv::Mat(height, width, CV_32FC(channel),
|
||||
const_cast<void*>(tensor.Data()));
|
||||
break;
|
||||
|
||||
case FDDataType::FP64:
|
||||
temp_mat = cv::Mat(height, width, CV_64FC(channel),
|
||||
const_cast<void*>(tensor.Data()));
|
||||
break;
|
||||
|
||||
default:
|
||||
FDASSERT(
|
||||
false,
|
||||
"Tensor type %d is not supported While calling CreateFromTensor.",
|
||||
type);
|
||||
break;
|
||||
}
|
||||
Mat mat = Mat(temp_mat);
|
||||
return mat;
|
||||
}
|
||||
|
||||
} // namespace vision
|
||||
} // namespace fastdeploy
|
||||
|
||||
@@ -76,5 +76,7 @@ struct FASTDEPLOY_DECL Mat {
|
||||
Device device = Device::CPU;
|
||||
};
|
||||
|
||||
Mat CreateFromTensor(const FDTensor& tensor);
|
||||
|
||||
} // namespace vision
|
||||
} // namespace fastdeploy
|
||||
|
||||
Reference in New Issue
Block a user