forked from PaddlePaddle/FastDeploy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Sync][Internal] sync some internal paddle3d codes (PaddlePaddle#2108)
- Loading branch information
Showing
30 changed files
with
2,517 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (c) 2023 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. | ||
|
||
#include "flags.h" | ||
#include "macros.h" | ||
#include "option.h" | ||
|
||
namespace vision = fastdeploy::vision; | ||
namespace benchmark = fastdeploy::benchmark; | ||
|
||
int main(int argc, char* argv[]) { | ||
#if defined(ENABLE_BENCHMARK) && defined(ENABLE_VISION) | ||
// Initialization | ||
auto option = fastdeploy::RuntimeOption(); | ||
if (!CreateRuntimeOption(&option, argc, argv, true)) { | ||
return -1; | ||
} | ||
auto im = cv::imread(FLAGS_image); | ||
std::unordered_map<std::string, std::string> config_info; | ||
benchmark::ResultManager::LoadBenchmarkConfig(FLAGS_config_path, | ||
&config_info); | ||
std::string model_name, params_name, config_name; | ||
auto model_format = fastdeploy::ModelFormat::PADDLE; | ||
if (!UpdateModelResourceName(&model_name, ¶ms_name, &config_name, | ||
&model_format, config_info, false)) { | ||
return -1; | ||
} | ||
auto model_file = FLAGS_model + sep + model_name; | ||
auto params_file = FLAGS_model + sep + params_name; | ||
std::vector<float> cam_data{7.183351e+02, 0.000000e+00, 6.003891e+02, | ||
4.450382e+01, 0.000000e+00, 7.183351e+02, | ||
1.815122e+02, -5.951107e-01, 0.000000e+00, | ||
0.000000e+00, 1.000000e+00, 2.616315e-03}; | ||
std::vector<float> lidar_data = { | ||
0.0048523, -0.9999298, -0.01081266, -0.00711321, | ||
-0.00302069, 0.01079808, -0.99993706, -0.06176636, | ||
0.99998367, 0.00488465, -0.00296808, -0.26739058, | ||
0., 0., 0., 1.}; | ||
if (config_info["backend"] == "paddle_trt") { | ||
option.paddle_infer_option.collect_trt_shape = true; | ||
option.paddle_infer_option.collect_trt_shape_by_device = true; | ||
option.paddle_infer_option.trt_min_subgraph_size = 12; | ||
option.paddle_infer_option.DisableTrtOps({"squeeze2"}); | ||
option.trt_option.max_batch_size = 1; | ||
} | ||
if (config_info["backend"] == "paddle_trt" || | ||
config_info["backend"] == "trt") { | ||
// use custom data to perform collect shapes. | ||
option.trt_option.SetShape("images", {1, 3, 375, 1242}, | ||
{1, 3, 375, 1242}, {1, 3, 375, 1242}); | ||
option.trt_option.SetShape("trans_lidar_to_cam", {1, 4, 4}, | ||
{1, 4, 4}, {1, 4, 4}); | ||
option.trt_option.SetShape("trans_cam_to_img", {1, 3, 4}, | ||
{1, 3, 4}, {1, 3, 4}); | ||
std::vector<float> image_data; | ||
image_data.assign(im.data, im.data + 1*3*375*1242); | ||
option.trt_option.SetInputData("trans_lidar_to_cam", lidar_data); | ||
option.trt_option.SetInputData("trans_cam_to_img", cam_data); | ||
option.trt_option.SetInputData("images", image_data); | ||
} | ||
auto model_cadnn = vision::perception::Caddn( | ||
model_file, params_file, "", option, model_format); | ||
vision::PerceptionResult res; | ||
// Run profiling | ||
BENCHMARK_MODEL(model_cadnn, model_cadnn.Predict(im, cam_data, lidar_data, &res)) | ||
std::cout << res.Str() << std::endl; | ||
#endif | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// 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. | ||
|
||
#if defined(WITH_GPU) | ||
|
||
#include "grid_sample_3d.h" | ||
|
||
#include <vector> | ||
|
||
#if defined(PADDLEINFERENCE_API_COMPAT_2_4_x) | ||
#include "paddle/include/experimental/ext_all.h" | ||
#elif defined(PADDLEINFERENCE_API_COMPAT_2_5_x) | ||
#include "paddle/include/paddle/extension.h" | ||
#else | ||
#include "paddle/extension.h" | ||
#endif | ||
|
||
namespace fastdeploy { | ||
namespace paddle_custom_ops { | ||
|
||
std::vector<paddle::Tensor> GridSample3DCUDAForward( | ||
const paddle::Tensor& x, const paddle::Tensor& grid, | ||
const std::string& mode, const std::string& padding_mode, | ||
bool align_corners); | ||
|
||
std::vector<paddle::Tensor> GridSample3DForward(const paddle::Tensor& x, | ||
const paddle::Tensor& grid, | ||
const std::string& mode, | ||
const std::string& padding_mode, | ||
bool align_corners) { | ||
return GridSample3DCUDAForward(x, grid, mode, padding_mode, align_corners); | ||
} | ||
|
||
std::vector<paddle::Tensor> GridSample3DCUDABackward( | ||
const paddle::Tensor& x, const paddle::Tensor& grid, | ||
const paddle::Tensor& grad_out, const std::string& mode, | ||
const std::string& padding_mode, bool align_corners); | ||
|
||
std::vector<paddle::Tensor> GridSample3DBackward( | ||
const paddle::Tensor& x, const paddle::Tensor& grid, | ||
const paddle::Tensor& grad_out, const std::string& mode, | ||
const std::string& padding_mode, bool align_corners) { | ||
return GridSample3DCUDABackward(x, grid, grad_out, mode, padding_mode, | ||
align_corners); | ||
} | ||
|
||
std::vector<std::vector<int64_t>> GridSample3DInferShape( | ||
std::vector<int64_t> x_shape, std::vector<int64_t> grid_shape) { | ||
return { | ||
{x_shape[0], x_shape[1], grid_shape[1], grid_shape[2], grid_shape[3]}}; | ||
} | ||
|
||
std::vector<std::vector<int64_t>> GridSample3DInferBackShape( | ||
std::vector<int64_t> x_shape, std::vector<int64_t> grid_shape) { | ||
return {x_shape}; | ||
} | ||
|
||
std::vector<paddle::DataType> GridSample3DInferDtype( | ||
paddle::DataType x_dtype, paddle::DataType grid_dtype) { | ||
return {x_dtype}; | ||
} | ||
|
||
} // namespace fastdeploy | ||
} // namespace paddle_custom_ops | ||
|
||
PD_BUILD_OP(grid_sample_3d) | ||
.Inputs({"x", "grid"}) | ||
.Attrs({"mode: std::string", "padding_mode: std::string", | ||
"align_corners: bool"}) | ||
.Outputs({"out"}) | ||
.SetKernelFn(PD_KERNEL(fastdeploy::paddle_custom_ops::GridSample3DForward)) | ||
.SetInferShapeFn(PD_INFER_SHAPE(fastdeploy::paddle_custom_ops::GridSample3DInferShape)) | ||
.SetInferDtypeFn(PD_INFER_DTYPE(fastdeploy::paddle_custom_ops::GridSample3DInferDtype)); | ||
|
||
PD_BUILD_GRAD_OP(grid_sample_3d) | ||
.Inputs({"x", "grid", paddle::Grad("out")}) | ||
.Attrs({"mode: std::string", "padding_mode: std::string", | ||
"align_corners: bool"}) | ||
.Outputs({paddle::Grad("x")}) | ||
.SetKernelFn(PD_KERNEL(fastdeploy::paddle_custom_ops::GridSample3DBackward)) | ||
.SetInferShapeFn(PD_INFER_SHAPE(fastdeploy::paddle_custom_ops::GridSample3DInferBackShape)); | ||
|
||
#endif |
Oops, something went wrong.