mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-16 13:41:30 +08:00
Add detection and segmentation examples for Ascend deployment
This commit is contained in:
@@ -45,30 +45,30 @@ void CpuInfer(const std::string& model_dir, const std::string& image_file) {
|
||||
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
|
||||
}
|
||||
|
||||
void KunlunXinInfer(const std::string& model_dir, const std::string& image_file) {
|
||||
fastdeploy::RuntimeOption option;
|
||||
option.UseKunlunXin();
|
||||
auto model_file = model_dir + sep + "model.pdmodel";
|
||||
auto params_file = model_dir + sep + "model.pdiparams";
|
||||
auto model = fastdeploy::vision::detection::YOLOv6(model_file, params_file, option, fastdeploy::ModelFormat::PADDLE);
|
||||
if (!model.Initialized()) {
|
||||
std::cerr << "Failed to initialize." << std::endl;
|
||||
return;
|
||||
}
|
||||
// void KunlunXinInfer(const std::string& model_dir, const std::string& image_file) {
|
||||
// fastdeploy::RuntimeOption option;
|
||||
// option.UseKunlunXin();
|
||||
// auto model_file = model_dir + sep + "model.pdmodel";
|
||||
// auto params_file = model_dir + sep + "model.pdiparams";
|
||||
// auto model = fastdeploy::vision::detection::YOLOv6(model_file, params_file, option, fastdeploy::ModelFormat::PADDLE);
|
||||
// if (!model.Initialized()) {
|
||||
// std::cerr << "Failed to initialize." << std::endl;
|
||||
// return;
|
||||
// }
|
||||
|
||||
auto im = cv::imread(image_file);
|
||||
// auto im = cv::imread(image_file);
|
||||
|
||||
fastdeploy::vision::DetectionResult res;
|
||||
if (!model.Predict(&im, &res)) {
|
||||
std::cerr << "Failed to predict." << std::endl;
|
||||
return;
|
||||
}
|
||||
std::cout << res.Str() << std::endl;
|
||||
// fastdeploy::vision::DetectionResult res;
|
||||
// if (!model.Predict(&im, &res)) {
|
||||
// std::cerr << "Failed to predict." << std::endl;
|
||||
// return;
|
||||
// }
|
||||
// std::cout << res.Str() << std::endl;
|
||||
|
||||
auto vis_im = fastdeploy::vision::VisDetection(im, res);
|
||||
cv::imwrite("vis_result.jpg", vis_im);
|
||||
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
|
||||
}
|
||||
// auto vis_im = fastdeploy::vision::VisDetection(im, res);
|
||||
// cv::imwrite("vis_result.jpg", vis_im);
|
||||
// std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
|
||||
// }
|
||||
|
||||
void GpuInfer(const std::string& model_dir, const std::string& image_file) {
|
||||
fastdeploy::RuntimeOption option;
|
||||
@@ -96,6 +96,32 @@ void GpuInfer(const std::string& model_dir, const std::string& image_file) {
|
||||
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
|
||||
}
|
||||
|
||||
void AscendInfer(const std::string& model_dir, const std::string& image_file) {
|
||||
auto model_file = model_dir + sep + "model.pdmodel";
|
||||
auto params_file = model_dir + sep + "model.pdiparams";
|
||||
fastdeploy::RuntimeOption option;
|
||||
option.UseAscend();
|
||||
auto model = fastdeploy::vision::detection::YOLOv6(
|
||||
model_file, params_file, option, fastdeploy::ModelFormat::PADDLE);
|
||||
|
||||
if (!model.Initialized()) {
|
||||
std::cerr << "Failed to initialize." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
auto im = cv::imread(image_file);
|
||||
|
||||
fastdeploy::vision::DetectionResult res;
|
||||
if (!model.Predict(&im, &res)) {
|
||||
std::cerr << "Failed to predict." << std::endl;
|
||||
return;
|
||||
}
|
||||
std::cout << res.Str() << std::endl;
|
||||
|
||||
auto vis_im = fastdeploy::vision::VisDetection(im, res);
|
||||
cv::imwrite("vis_result.jpg", vis_im);
|
||||
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc < 4) {
|
||||
@@ -113,7 +139,9 @@ int main(int argc, char* argv[]) {
|
||||
} else if (std::atoi(argv[3]) == 1) {
|
||||
GpuInfer(argv[1], argv[2]);
|
||||
} else if (std::atoi(argv[3]) == 2) {
|
||||
KunlunXinInfer(argv[1], argv[2]);
|
||||
}
|
||||
// KunlunXinInfer(argv[1], argv[2]);
|
||||
} else if (std::atoi(argv[3]) == 3) {
|
||||
AscendInfer(argv[1], argv[2]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user