@@ -287,7 +287,8 @@ std::vector<cv::Mat> ovToCV(const ov::Tensor& tensor, const ov::Shape& shape, co
287
287
" Unsupported layout: " , layout.to_string ());
288
288
289
289
OPENVINO_ASSERT (precision == ov::element::Type_t::u8 || precision == ov::element::Type_t::f32 ||
290
- precision == ov::element::Type_t::f16 || precision == ov::element::Type_t::i32,
290
+ precision == ov::element::Type_t::f16 || precision == ov::element::Type_t::bf16 ||
291
+ precision == ov::element::Type_t::i32,
291
292
" Unsupported precision: " , precision.get_type_name ());
292
293
293
294
int cvType = 0 ;
@@ -302,6 +303,9 @@ std::vector<cv::Mat> ovToCV(const ov::Tensor& tensor, const ov::Shape& shape, co
302
303
} else if (precision == ov::element::Type_t::f16) {
303
304
cvType = CV_16SC1;
304
305
elemSize = sizeof (ov::float16);
306
+ } else if (precision == ov::element::Type_t::bf16) {
307
+ cvType = CV_16SC1;
308
+ elemSize = sizeof (ov::bfloat16);
305
309
} else if (precision == ov::element::Type_t::i32) {
306
310
cvType = CV_32SC1;
307
311
elemSize = sizeof (int32_t );
@@ -392,11 +396,14 @@ void cvToOV(const cv::Mat& cvImg, const ov::Tensor& tensor, const ov::Shape& sha
392
396
cvType = static_cast <int >(CV_32FC (C));
393
397
} else if (precision == ov::element::Type_t::f16) {
394
398
cvType = static_cast <int >(CV_16SC (C));
399
+ } else if (precision == ov::element::Type_t::bf16) {
400
+ cvType = static_cast <int >(CV_16SC (C));
395
401
} else if (precision == ov::element::Type_t::i32) {
396
402
cvType = static_cast <int >(CV_32SC (C));
397
403
} else {
398
404
OPENVINO_ASSERT (precision == ov::element::Type_t::u8 || precision == ov::element::Type_t::f32 ||
399
- precision == ov::element::Type_t::f16 || precision == ov::element::Type_t::i32,
405
+ precision == ov::element::Type_t::f16 || precision == ov::element::Type_t::bf16 ||
406
+ precision == ov::element::Type_t::i32,
400
407
" Unsupported precision " , precision.get_type_name ());
401
408
}
402
409
@@ -437,6 +444,10 @@ void cvToOV(const cv::Mat& cvImg, const ov::Tensor& tensor, const ov::Shape& sha
437
444
const auto inPtr = in.ptr <float >();
438
445
const auto outPtr = out.ptr <ov::float16>();
439
446
convertBufferType (outPtr, inPtr, out.size ().area () * C);
447
+ } else if (precision == ov::element::Type_t::bf16) {
448
+ const auto inPtr = in.ptr <float >();
449
+ const auto outPtr = out.ptr <ov::bfloat16>();
450
+ convertBufferType (outPtr, inPtr, out.size ().area () * C);
440
451
} else if (precision == ov::element::Type_t::i32) {
441
452
in.convertTo (out, CV_32S);
442
453
} else {
@@ -451,7 +462,8 @@ void cvToOV(const cv::Mat& cvImg, const ov::Tensor& tensor, const ov::Shape& sha
451
462
} else if (layout == ov::Layout (" NCHW" )) {
452
463
auto tensorPlanes = ovToCV (tensor, shape, layout, 0 );
453
464
454
- if (precision != ov::element::Type_t::f16) {
465
+ if (!(precision == ov::element::Type_t::f16 ||
466
+ precision == ov::element::Type_t::bf16)) {
455
467
cv::split (in, tensorPlanes);
456
468
} else {
457
469
std::vector<cv::Mat> inPlanes;
@@ -461,8 +473,13 @@ void cvToOV(const cv::Mat& cvImg, const ov::Tensor& tensor, const ov::Shape& sha
461
473
462
474
for (size_t i = 0 ; i < tensorPlanes.size (); ++i) {
463
475
const auto inPtr = inPlanes[i].ptr <float >();
464
- const auto outPtr = tensorPlanes[i].ptr <ov::float16>();
465
- convertBufferType (outPtr, inPtr, inPlanes[i].size ().area ());
476
+ if (precision == ov::element::Type_t::f16) {
477
+ const auto outPtr = tensorPlanes[i].ptr <ov::float16>();
478
+ convertBufferType (outPtr, inPtr, inPlanes[i].size ().area ());
479
+ } else if (precision == ov::element::Type_t::bf16) {
480
+ const auto outPtr = tensorPlanes[i].ptr <ov::bfloat16>();
481
+ convertBufferType (outPtr, inPtr, inPlanes[i].size ().area ());
482
+ }
466
483
}
467
484
}
468
485
@@ -1761,6 +1778,8 @@ static int runSingleImageTest() {
1761
1778
inputBinPrecisionForOneInfer[inferIdx][precisionIdx] = ov::element::f32;
1762
1779
} else if (strEq (precision, " FP16" )) {
1763
1780
inputBinPrecisionForOneInfer[inferIdx][precisionIdx] = ov::element::f16;
1781
+ } else if (strEq (precision, " BF16" )) {
1782
+ inputBinPrecisionForOneInfer[inferIdx][precisionIdx] = ov::element::bf16;
1764
1783
} else if (strEq (precision, " I32" )) {
1765
1784
inputBinPrecisionForOneInfer[inferIdx][precisionIdx] = ov::element::i32;
1766
1785
} else if (strEq (precision, " I64" )) {
@@ -1808,6 +1827,8 @@ static int runSingleImageTest() {
1808
1827
ov::element::Type prc_in = ov::element::u8;
1809
1828
if (FLAGS_ip == " FP16" )
1810
1829
prc_in = ov::element::f16;
1830
+ else if (FLAGS_ip == " BF16" )
1831
+ prc_in = ov::element::bf16;
1811
1832
else if (FLAGS_ip == " FP32" )
1812
1833
prc_in = ov::element::f32;
1813
1834
else if (FLAGS_ip == " I32" )
0 commit comments