-
-
Save ShawnHymel/79237fe6aee5a3653c497d879f746c0c to your computer and use it in GitHub Desktop.
Sorry for flooding but something strange is happening here:
I am on windows using the spyder and python 3.8.3 - everytime I try to make the conversion I get this error " hex_str = format(val, '#04x') - ValueError: Unknown format code 'x' for object of type 'str".
However the code works perfectly in colab.
I must say I am no expert and I am using this project as a way to understand how to deploy a ML model into esp32. I don't mind having to go to colab just to make the conversion but I would like to understand why I get this unknown format error.
Can somebody help me?
btw, great example @ShawnHymel !!
@ericobropinto it looks like format(val, '#04x')
only works when val
is an integer. In my original code, the tflite model file was a collection (list, I think) of integers that could be iterated over and converted to hex strings (i.e. using format()
). That may have changed in recent versions of TensorFlow Lite (as this example is over 2 years old). I'm not sure what format the tflite models are using now.
What alternative board would be used to implement this example instead of NUCLEO-32 STM32L432KC EVAL BRD since this board is not available online. please suggest
@abhi-84 Almost any STM32 ARM Cortex-M3 or M4 should work (setting it up in CubeMX might be a little different, depending on the particular MCU or board). Some Cortex-M0 or M0+ MCUs might work...I just haven't tried them yet.
@suman346 @ericobropinto @ShawnHymel Some possible solutions for Unknown format code 'x' for object of type 'str".
I have met this problem but solved it by changing it slightly. So be careful about the file and directory.
From
file.write(hex_to_c_array('./modellite.tflite', c_model_name))
to
file.write(hex_to_c_array(tflite_model, c_model_name))
Then it works.
Create header guard
c_str += '#ifndef ' + var_name.upper() + '_H\n'
c_str += '#define ' + var_name.upper() + '_H\n\n'
-- Here I am facing error
"AttributeError: 'Interpreter' object has no attribute 'upper''
@soumengoroi Check the value of var_name being passed into that function. It should be a string (and set by c_model_name as the argument)
There is a typo in the 3rd code cell. Change versionS to version.
!python --version
I am also getting a error here.
hex_str = format(val, '04x')
ValueError: Unknown format code 'x' for object of type 'str'
were you able to solve?