[PYTHON][BENCHMARK_APP] Add BGR covert to Gray function (#12118)

* Fix the JIRA 80700 issue. Add BGR covert to Gray function

* Support NCHW and NHWC

Co-authored-by: Shen, Wanglei <wanglei.shen@intel.com>
This commit is contained in:
RICKIE777
2022-07-14 17:10:02 +08:00
committed by GitHub
parent dc374ca1bf
commit 64c0af3568

View File

@@ -168,7 +168,12 @@ def get_image_tensors(image_paths, info, batch_sizes):
red = np.divide(red, info.scale[2])
image = cv2.merge([blue, green, red])
if str(info.layout) in ['[N,C,H,W]', '[C,H,W]']:
model_channel = int(str(info.channels))
image_channel = image.shape[-1]
if model_channel == 1 and image_channel == 3:
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
if model_channel == image_channel and str(info.layout) in ['[N,C,H,W]', '[C,H,W]']:
image = image.transpose((2, 0, 1))
if process_with_original_shapes: