Commit 55d54b56 authored by Alexander Alekhin's avatar Alexander Alekhin

dnn(onnx): handle unaligned access in ONNX importer

parent 16b13c6e
...@@ -147,8 +147,18 @@ Mat getMatFromTensor(opencv_onnx::TensorProto& tensor_proto) ...@@ -147,8 +147,18 @@ Mat getMatFromTensor(opencv_onnx::TensorProto& tensor_proto)
} }
else else
{ {
char* val = const_cast<char*>(tensor_proto.raw_data().c_str()); const char* val = tensor_proto.raw_data().c_str();
int64_t* src = reinterpret_cast<int64_t*>(val); // 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()); convertInt64ToInt32(src, dst, blob.total());
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment