Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 1 addition & 29 deletions csrcs/fastdeploy/backends/ort/ort_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,6 @@ namespace fastdeploy {
std::vector<OrtCustomOp*> OrtBackend::custom_operators_ =
std::vector<OrtCustomOp*>();

ONNXTensorElementDataType GetOrtDtype(FDDataType fd_dtype) {
if (fd_dtype == FDDataType::FP32) {
return ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT;
} else if (fd_dtype == FDDataType::FP64) {
return ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE;
} else if (fd_dtype == FDDataType::INT32) {
return ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32;
} else if (fd_dtype == FDDataType::INT64) {
return ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64;
}
FDERROR << "Unrecognized fastdeply data type:" << FDDataTypeStr(fd_dtype)
<< "." << std::endl;
return ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED;
}

FDDataType GetFdDtype(ONNXTensorElementDataType ort_dtype) {
if (ort_dtype == ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT) {
return FDDataType::FP32;
} else if (ort_dtype == ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE) {
return FDDataType::FP64;
} else if (ort_dtype == ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32) {
return FDDataType::INT32;
} else if (ort_dtype == ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64) {
return FDDataType::INT64;
}
FDERROR << "Unrecognized ort data type:" << ort_dtype << "." << std::endl;
return FDDataType::FP32;
}

void OrtBackend::BuildOption(const OrtBackendOption& option) {
option_ = option;
if (option.graph_optimization_level >= 0) {
Expand Down Expand Up @@ -263,6 +234,7 @@ bool OrtBackend::Infer(std::vector<FDTensor>& inputs,
(*outputs)[i].name = outputs_desc_[i].name;
CopyToCpu(ort_outputs[i], &((*outputs)[i]));
}

return true;
}

Expand Down
6 changes: 3 additions & 3 deletions csrcs/fastdeploy/backends/ort/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ ONNXTensorElementDataType GetOrtDtype(const FDDataType& fd_dtype) {
} else if (fd_dtype == FDDataType::INT64) {
return ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64;
}
FDERROR << "Unrecognized fastdeply data type:" << FDDataTypeStr(fd_dtype)
<< "." << std::endl;
FDERROR << "Unrecognized fastdeply data type:" << Str(fd_dtype) << "."
<< std::endl;
return ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED;
}

Expand Down Expand Up @@ -64,4 +64,4 @@ Ort::Value CreateOrtValue(FDTensor& tensor, bool is_backend_cuda) {
return ort_value;
}

} // namespace fastdeploy
} // namespace fastdeploy
6 changes: 3 additions & 3 deletions csrcs/fastdeploy/backends/ort/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@
#include <vector>

#include "fastdeploy/backends/backend.h"
#include "onnxruntime_cxx_api.h" // NOLINT
#include "onnxruntime_cxx_api.h" // NOLINT

namespace fastdeploy {

// Convert FDDataType to OrtDataType
ONNXTensorElementDataType GetOrtDtype(const FDDataType& fd_dtype);

// Convert OrtDataType to FDDataType
FDDataType GetFdDtype(const ONNXTensorElementDataType* ort_dtype);
FDDataType GetFdDtype(const ONNXTensorElementDataType& ort_dtype);

// Create Ort::Value
// is_backend_cuda specify if the onnxruntime use CUDAExectionProvider
// While is_backend_cuda = true, and tensor.device = Device::GPU
// Will directly share the cuda data in tensor to OrtValue
Ort::Value CreateOrtValue(FDTensor& tensor, bool is_backend_cuda = false);

} // namespace fastdeploy
} // namespace fastdeploy
6 changes: 3 additions & 3 deletions csrcs/fastdeploy/core/fd_tensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ void FDTensor::PrintInfo(const std::string& prefix) {
for (int i = 0; i < shape.size(); ++i) {
std::cout << shape[i] << " ";
}
std::cout << ", dtype=" << FDDataTypeStr(dtype) << ", mean=" << mean
<< ", max=" << max << ", min=" << min << std::endl;
std::cout << ", dtype=" << Str(dtype) << ", mean=" << mean << ", max=" << max
<< ", min=" << min << std::endl;
}

FDTensor::FDTensor(const std::string& tensor_name) { name = tensor_name; }
} // namespace fastdeploy
} // namespace fastdeploy
116 changes: 45 additions & 71 deletions csrcs/fastdeploy/core/fd_type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace fastdeploy {

int FDDataTypeSize(FDDataType data_type) {
int FDDataTypeSize(const FDDataType& data_type) {
FDASSERT(data_type != FDDataType::FP16, "Float16 is not supported.");
if (data_type == FDDataType::BOOL) {
return sizeof(bool);
Expand All @@ -34,89 +34,63 @@ int FDDataTypeSize(FDDataType data_type) {
} else if (data_type == FDDataType::UINT8) {
return sizeof(uint8_t);
} else {
FDASSERT(false, "Unexpected data type: " + FDDataTypeStr(data_type));
FDASSERT(false, "Unexpected data type: " + Str(data_type));
}
return -1;
}

std::string FDDataTypeStr(FDDataType data_type) {
FDASSERT(data_type != FDDataType::FP16, "Float16 is not supported.");
if (data_type == FDDataType::BOOL) {
return "bool";
} else if (data_type == FDDataType::INT16) {
return "int16";
} else if (data_type == FDDataType::INT32) {
return "int32";
} else if (data_type == FDDataType::INT64) {
return "int64";
} else if (data_type == FDDataType::FP16) {
return "float16";
} else if (data_type == FDDataType::FP32) {
return "float32";
} else if (data_type == FDDataType::FP64) {
return "float64";
} else if (data_type == FDDataType::UINT8) {
return "uint8";
} else if (data_type == FDDataType::INT8) {
return "int8";
} else {
FDASSERT(false, "Unexpected data type: " + FDDataTypeStr(data_type));
}
return "UNKNOWN!";
}

std::string Str(Device& d) {
std::string Str(const Device& d) {
std::string out;
switch (d) {
case Device::DEFAULT:
out = "Device::DEFAULT";
break;
case Device::CPU:
out = "Device::CPU";
break;
case Device::GPU:
out = "Device::GPU";
break;
default:
out = "Device::UNKOWN";
case Device::DEFAULT:
out = "Device::DEFAULT";
break;
case Device::CPU:
out = "Device::CPU";
break;
case Device::GPU:
out = "Device::GPU";
break;
default:
out = "Device::UNKOWN";
}
return out;
}

std::string Str(FDDataType& fdt) {
std::string Str(const FDDataType& fdt) {
std::string out;
switch (fdt) {
case FDDataType::BOOL:
out = "FDDataType::BOOL";
break;
case FDDataType::INT16:
out = "FDDataType::INT16";
break;
case FDDataType::INT32:
out = "FDDataType::INT32";
break;
case FDDataType::INT64:
out = "FDDataType::INT64";
break;
case FDDataType::FP32:
out = "FDDataType::FP32";
break;
case FDDataType::FP64:
out = "FDDataType::FP64";
break;
case FDDataType::FP16:
out = "FDDataType::FP16";
break;
case FDDataType::UINT8:
out = "FDDataType::UINT8";
break;
case FDDataType::INT8:
out = "FDDataType::INT8";
break;
default:
out = "FDDataType::UNKNOWN";
case FDDataType::BOOL:
out = "FDDataType::BOOL";
break;
case FDDataType::INT16:
out = "FDDataType::INT16";
break;
case FDDataType::INT32:
out = "FDDataType::INT32";
break;
case FDDataType::INT64:
out = "FDDataType::INT64";
break;
case FDDataType::FP32:
out = "FDDataType::FP32";
break;
case FDDataType::FP64:
out = "FDDataType::FP64";
break;
case FDDataType::FP16:
out = "FDDataType::FP16";
break;
case FDDataType::UINT8:
out = "FDDataType::UINT8";
break;
case FDDataType::INT8:
out = "FDDataType::INT8";
break;
default:
out = "FDDataType::UNKNOWN";
}
return out;
}

} // namespace fastdeploy
} // namespace fastdeploy
8 changes: 3 additions & 5 deletions csrcs/fastdeploy/core/fd_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace fastdeploy {

enum FASTDEPLOY_DECL Device { DEFAULT, CPU, GPU };

FASTDEPLOY_DECL std::string Str(Device& d);
FASTDEPLOY_DECL std::string Str(const Device& d);

enum FASTDEPLOY_DECL FDDataType {
BOOL,
Expand All @@ -51,9 +51,7 @@ enum FASTDEPLOY_DECL FDDataType {
INT8
};

FASTDEPLOY_DECL std::string Str(FDDataType& fdt);
FASTDEPLOY_DECL std::string Str(const FDDataType& fdt);

FASTDEPLOY_DECL int32_t FDDataTypeSize(FDDataType data_dtype);

FASTDEPLOY_DECL std::string FDDataTypeStr(FDDataType data_dtype);
FASTDEPLOY_DECL int32_t FDDataTypeSize(const FDDataType& data_dtype);
} // namespace fastdeploy
1 change: 1 addition & 0 deletions csrcs/fastdeploy/pybind/fastdeploy_runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ void BindRuntime(pybind11::module& m) {
memcpy(inputs[index].data.data(), iter->second.mutable_data(),
iter->second.nbytes());
inputs[index].name = iter->first;
index += 1;
}

std::vector<FDTensor> outputs(self.NumOutputs());
Expand Down
9 changes: 5 additions & 4 deletions csrcs/fastdeploy/pybind/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pybind11::dtype FDDataTypeToNumpyDataType(const FDDataType& fd_dtype) {
dt = pybind11::dtype::of<double>();
} else {
FDASSERT(false, "The function doesn't support data type of " +
FDDataTypeStr(fd_dtype) + ".");
Str(fd_dtype) + ".");
}
return dt;
}
Expand All @@ -47,8 +47,9 @@ FDDataType NumpyDataTypeToFDDataType(const pybind11::dtype& np_dtype) {
} else if (np_dtype.is(pybind11::dtype::of<double>())) {
return FDDataType::FP64;
}
FDASSERT(false, "NumpyDataTypeToFDDataType() only support "
"int32/int64/float32/float64 now.");
FDASSERT(false,
"NumpyDataTypeToFDDataType() only support "
"int32/int64/float32/float64 now.");
return FDDataType::FP32;
}

Expand Down Expand Up @@ -112,4 +113,4 @@ PYBIND11_MODULE(fastdeploy_main, m) {
#endif
}

} // namespace fastdeploy
} // namespace fastdeploy
29 changes: 22 additions & 7 deletions csrcs/fastdeploy/vision/ppdet/ppyoloe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,31 @@ PPYOLOE::PPYOLOE(const std::string& model_file, const std::string& params_file,
initialized = Initialize();
}

bool PPYOLOE::Initialize() {
#ifdef ENABLE_PADDLE_FRONTEND
// remove multiclass_nms3 now
// this is a trick operation for ppyoloe while inference on trt
void PPYOLOE::GetNmsInfo() {
if (runtime_option.model_format == Frontend::PADDLE) {
std::string contents;
if (!ReadBinaryFromFile(runtime_option.model_file, &contents)) {
return false;
return;
}
auto reader = paddle2onnx::PaddleReader(contents.c_str(), contents.size());
if (reader.has_nms) {
has_nms_ = true;
background_label = reader.nms_params.background_label;
keep_top_k = reader.nms_params.keep_top_k;
nms_eta = reader.nms_params.nms_eta;
nms_threshold = reader.nms_params.nms_threshold;
score_threshold = reader.nms_params.score_threshold;
nms_top_k = reader.nms_params.nms_top_k;
normalized = reader.nms_params.normalized;
}
}
}

bool PPYOLOE::Initialize() {
#ifdef ENABLE_PADDLE_FRONTEND
// remove multiclass_nms3 now
// this is a trick operation for ppyoloe while inference on trt
GetNmsInfo();
runtime_option.remove_multiclass_nms_ = true;
runtime_option.custom_op_info_["multiclass_nms3"] = "MultiClassNMS";
#endif
Expand All @@ -52,8 +63,12 @@ bool PPYOLOE::Initialize() {

if (has_nms_ && runtime_option.backend == Backend::TRT) {
FDINFO << "Detected operator multiclass_nms3 in your model, will replace "
"it with fastdeploy::backend::MultiClassNMS replace it."
<< std::endl;
"it with fastdeploy::backend::MultiClassNMS(background_label="
<< background_label << ", keep_top_k=" << keep_top_k
<< ", nms_eta=" << nms_eta << ", nms_threshold=" << nms_threshold
<< ", score_threshold=" << score_threshold
<< ", nms_top_k=" << nms_top_k << ", normalized=" << normalized
<< ")." << std::endl;
has_nms_ = false;
}
return true;
Expand Down
4 changes: 4 additions & 0 deletions csrcs/fastdeploy/vision/ppdet/ppyoloe.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class FASTDEPLOY_DECL PPYOLOE : public FastDeployModel {
int64_t nms_top_k = 10000;
bool normalized = true;
bool has_nms_ = false;

// This function will used to check if this model contains multiclass_nms
// and get parameters from the operator
void GetNmsInfo();
};
} // namespace ppdet
} // namespace vision
Expand Down
2 changes: 1 addition & 1 deletion external/paddle2onnx.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ else()
endif(WIN32)

set(PADDLE2ONNX_URL_BASE "https://bj.bcebos.com/paddle2onnx/libs/")
set(PADDLE2ONNX_VERSION "1.0.0rc2")
set(PADDLE2ONNX_VERSION "1.0.0rc3")
if(WIN32)
set(PADDLE2ONNX_FILE "paddle2onnx-win-x64-${PADDLE2ONNX_VERSION}.zip")
if(NOT CMAKE_CL_64)
Expand Down
Loading