Home > Net >  Same numpy version [Colab and Raspberry pi]:: BUT 'ImportError: numpy.core.multiarray failed to
Same numpy version [Colab and Raspberry pi]:: BUT 'ImportError: numpy.core.multiarray failed to

Time:09-23

I'm trying to use the trained multiclass classification model (model trained and saved from colab) into Raspberry pi 4.

In colab:

import sys
print(sys.version)

prints 3.7.14 (default, Sep 8 2022, 00:06:44) [GCC 7.5.0]. Similarly,

import tensorflow
import numpy
print('tensorflow_version',tensorflow.__version__)
print('numpy_version',numpy.__version__)

prints

tensorflow_version 2.5.0
numpy_version 1.19.2

On the Raspberry Pi (Python 3.7.0 (default, Sep 20 2022, 15:06:22)[GCC 10.2.1 20210110] on linux), tensorflow.__version__ is '2.5.0' and numpy.__version__ is '1.19.2'.

With the above configuration, I get :

RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd

ImportError: numpy.core.multiarray failed to import

While searching for similar questions in StackOverflow, most of them suggest that the error is due to mismatch in numpy version. However, in my case, I've the same version of numpy.

Does the GCC version have some role in this error? How can I downgrade GCC version in raspberry pi or upgrade its version in colab?

Note that the version of tensorflow is fixed owing to my hardware (armv7l), which mandes to use numpy 1.19.2.

Thank you.

CodePudding user response:

I solved it by saving my classification model into TensorflowLite as follows:

# Convert the model.
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()

# Save the model.
with open('model.tflite', 'wb') as f:
  f.write(tflite_model)
  • Related