summaryrefslogtreecommitdiff
path: root/scripts/py
diff options
context:
space:
mode:
authorIsabella Gottardi <isabella.gottardi@arm.com>2021-10-20 15:52:32 +0100
committerIsabella Gottardi <isabella.gottardi@arm.com>2021-10-25 08:51:10 +0000
commit79d4154ee071d0e7ef2d1eecdde149d488bb9d8b (patch)
tree21c8c0a2bd187a925f28045d4a57e9e4ef05be82 /scripts/py
parent14ab8d447c5f12df2ac7fd4217fc0d2005b02dca (diff)
downloadml-embedded-evaluation-kit-79d4154ee071d0e7ef2d1eecdde149d488bb9d8b.tar.gz
MLECO-2458 and MLECO-2476 [Fix] VWW IFM quant step
* Changed image->cc conversion to be similar with preprocessing of img_class and vww models: images are scaled maintaing the aspect ration and then the centre crop of the correct size is taken. * VWW applies input quantization info to the int8 image (prior converted to [0,1] float range). * Changed adult_blur to a image without person. * Fix menu print when selecting a specific ifm to run (Select message was displayed after typing something) Change-Id: Ie6cde7ab4835ea842667b87397458a5d32131df3
Diffstat (limited to 'scripts/py')
-rw-r--r--scripts/py/gen_rgb_cpp.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/scripts/py/gen_rgb_cpp.py b/scripts/py/gen_rgb_cpp.py
index 957d2d0..c53fbd7 100644
--- a/scripts/py/gen_rgb_cpp.py
+++ b/scripts/py/gen_rgb_cpp.py
@@ -70,12 +70,23 @@ def write_individual_img_cc_file(image_filename, cc_filename, header_template_fi
gen_time=datetime.datetime.now(),
file_name=os.path.basename(image_filename),
year=datetime.datetime.now().year)
-
- original_image.thumbnail(image_size)
- delta_w = abs(image_size[0] - original_image.size[0])
- delta_h = abs(image_size[1] - original_image.size[1])
- resized_image = Image.new('RGB', args.image_size, (255, 255, 255, 0))
- resized_image.paste(original_image, (int(delta_w / 2), int(delta_h / 2)))
+ # IFM size
+ ifm_width = image_size[0]
+ ifm_height = image_size[1]
+
+ # Aspect ratio resize
+ scale_ratio = (float)(max(ifm_width, ifm_height)) / (float)(min(original_image.size[0], original_image.size[1]))
+ resized_width = (int)(original_image.size[0] * scale_ratio)
+ resized_height = (int)(original_image.size[1] * scale_ratio)
+ resized_image = original_image.resize([resized_width,resized_height], Image.BILINEAR)
+
+ # Crop the center of the image
+ resized_image = resized_image.crop((
+ (resized_width - ifm_width) / 2, # left
+ (resized_height - ifm_height) / 2, # top
+ (resized_width + ifm_width) / 2, # right
+ (resized_height + ifm_height) / 2 # bottom
+ ))
# Convert the image and write it to the cc file
rgb_data = np.array(resized_image, dtype=np.uint8).flatten()