mirror of
https://github.com/opencv/opencv.git
synced 2025-06-11 11:45:30 +08:00
dnn(onnx): handle unaligned access in ONNX importer
This commit is contained in:
parent
16b13c6e3b
commit
55d54b56bf
@ -147,8 +147,18 @@ Mat getMatFromTensor(opencv_onnx::TensorProto& tensor_proto)
|
||||
}
|
||||
else
|
||||
{
|
||||
char* val = const_cast<char*>(tensor_proto.raw_data().c_str());
|
||||
int64_t* src = reinterpret_cast<int64_t*>(val);
|
||||
const char* val = tensor_proto.raw_data().c_str();
|
||||
// Aligned pointer is required: https://github.com/opencv/opencv/issues/16373
|
||||
// this doesn't work: typedef int64_t CV_DECL_ALIGNED(1) unaligned_int64_t;
|
||||
AutoBuffer<int64_t, 16> aligned_val;
|
||||
if (!isAligned<sizeof(int64_t)>(val))
|
||||
{
|
||||
size_t sz = tensor_proto.raw_data().size();
|
||||
aligned_val.allocate(divUp(sz, sizeof(int64_t)));
|
||||
memcpy(aligned_val.data(), val, sz);
|
||||
val = (const char*)aligned_val.data();
|
||||
}
|
||||
const int64_t* src = reinterpret_cast<const int64_t*>(val);
|
||||
convertInt64ToInt32(src, dst, blob.total());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user