mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-13 20:34:02 +08:00
[Bug Fix] fix centerpoint malloc bug (#2099)
This commit is contained in:
@@ -24,7 +24,8 @@ CenterpointPreprocessor::CenterpointPreprocessor(
|
|||||||
|
|
||||||
bool CenterpointPreprocessor::ReadPoint(const std::string &file_path,
|
bool CenterpointPreprocessor::ReadPoint(const std::string &file_path,
|
||||||
const int64_t num_point_dim,
|
const int64_t num_point_dim,
|
||||||
void **buffer, int64_t *num_points) {
|
std::vector<float> &data,
|
||||||
|
int64_t *num_points) {
|
||||||
std::ifstream file_in(file_path, std::ios::in | std::ios::binary);
|
std::ifstream file_in(file_path, std::ios::in | std::ios::binary);
|
||||||
if (num_point_dim < 4) {
|
if (num_point_dim < 4) {
|
||||||
FDERROR << "Point dimension must not be less than 4, but received "
|
FDERROR << "Point dimension must not be less than 4, but received "
|
||||||
@@ -41,12 +42,8 @@ bool CenterpointPreprocessor::ReadPoint(const std::string &file_path,
|
|||||||
file_size = file_in.tellg();
|
file_size = file_in.tellg();
|
||||||
file_in.seekg(0, std::ios::beg);
|
file_in.seekg(0, std::ios::beg);
|
||||||
|
|
||||||
*buffer = malloc(file_size);
|
data.resize(file_size / sizeof(float));
|
||||||
if (*buffer == nullptr) {
|
file_in.read(reinterpret_cast<char *>(data.data()), file_size);
|
||||||
FDERROR << "Failed to malloc memory of size: " << file_size << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
file_in.read(reinterpret_cast<char *>(*buffer), file_size);
|
|
||||||
file_in.close();
|
file_in.close();
|
||||||
|
|
||||||
if (file_size / sizeof(float) % num_point_dim != 0) {
|
if (file_size / sizeof(float) % num_point_dim != 0) {
|
||||||
@@ -75,12 +72,12 @@ bool CenterpointPreprocessor::Apply(std::vector<std::string> &points_dir,
|
|||||||
for (int index = 0; index < points_dir.size(); ++index) {
|
for (int index = 0; index < points_dir.size(); ++index) {
|
||||||
std::string file_path = points_dir[index];
|
std::string file_path = points_dir[index];
|
||||||
std::vector<int64_t> points_shape;
|
std::vector<int64_t> points_shape;
|
||||||
void *buffer = nullptr;
|
std::vector<float> data;
|
||||||
int64_t num_points;
|
int64_t num_points;
|
||||||
if (!ReadPoint(file_path, num_point_dim, &buffer, &num_points)) {
|
if (!ReadPoint(file_path, num_point_dim, data, &num_points)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
float *points = static_cast<float *>(buffer);
|
float *points = data.data();
|
||||||
|
|
||||||
if (!with_timelag && num_point_dim == 5 || num_point_dim > 5) {
|
if (!with_timelag && num_point_dim == 5 || num_point_dim > 5) {
|
||||||
InsertTimeToPoints(num_points, num_point_dim, points);
|
InsertTimeToPoints(num_points, num_point_dim, points);
|
||||||
|
@@ -51,7 +51,7 @@ class FASTDEPLOY_DECL CenterpointPreprocessor : public ProcessorManager {
|
|||||||
std::vector<std::shared_ptr<Processor>> processors_;
|
std::vector<std::shared_ptr<Processor>> processors_;
|
||||||
bool ReadPoint(const std::string &file_path,
|
bool ReadPoint(const std::string &file_path,
|
||||||
const int64_t num_point_dim,
|
const int64_t num_point_dim,
|
||||||
void **buffer, int64_t *num_points);
|
std::vector<float> &data, int64_t *num_points);
|
||||||
bool InsertTimeToPoints(const int64_t num_points,
|
bool InsertTimeToPoints(const int64_t num_points,
|
||||||
const int64_t num_point_dim,
|
const int64_t num_point_dim,
|
||||||
float *points);
|
float *points);
|
||||||
|
Reference in New Issue
Block a user