mirror of
https://github.com/opencv/opencv.git
synced 2025-06-12 20:42:53 +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
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user