File tree Expand file tree Collapse file tree
examples/arm/image_classification_example_ethos_u/runtime Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- # Copyright 2025 Arm Limited and/or its affiliates.
1+ # Copyright 2025-2026 Arm Limited and/or its affiliates.
22#
33# This source code is licensed under the BSD-style license found in the
44# LICENSE file in the root directory of this source tree.
@@ -37,7 +37,11 @@ def convert_image_to_c_array(
3737 img = resize_and_crop_center (img , image_size )
3838 # NumPy arrays are stored in channels-last format. Convert to channels-first.
3939 img_channels_first = np .transpose (img , (2 , 0 , 1 ))
40- data = np .array (img_channels_first , dtype = np .float32 ) / 255.0
40+ # The PIL Image function returns the image represented in the range [0;255].
41+ # However, the NN was trained on fp32 numbers in the range [-1;1].
42+ # To pass from [0;255] to [-1;1], we divide by 127.5(the middle of the range)
43+ # and subtract 1.
44+ data = np .array (img_channels_first , dtype = np .float32 ) / 127.5 - 1
4145 data = data .flatten ()
4246 # Format as C array
4347 array_lines = []
You can’t perform that action at this time.
0 commit comments