If you got some errors when tried to build your face mask detection script in your Raspberry Pi (using Python) like this
Traceback (most recent call last): File "detect_mask_webcam.py", line 5, in <module> from tensorflow.keras.applications.mobilenet_v2 import preprocess_input File "/usr/local/lib/python3.7/dist-packages/tensorflow/init.py", line 101, in <module> from tensorflow_core import * File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/init.py", line 40, in <module> from tensorflow.python.tools import module_util as _module_util File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 959, in _find_and_load_unlocked File "/usr/local/lib/python3.7/dist-packages/tensorflow/init.py", line 50, in getattr module = self._load() File "/usr/local/lib/python3.7/dist-packages/tensorflow/init.py", line 44, in _load module = importlib.import_module(self.__name_) File "/usr/lib/python3.7/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/init.py", line 95, in <module> from tensorflow.python import keras File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/keras/init.py", line 27, in <module> from tensorflow.python.keras import models File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/keras/init.py", line 27, in <module> from tensorflow.python.keras import models File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/keras/models.py", line 23, in <module> from tensorflow.python.keras import metrics as metrics_module File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/keras/metrics.py", line 34, in <module> from tensorflow.python.keras.engine import base_layer File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/keras/engine/base_layer.py", line 56, in <module> from tensorflow.python.keras.saving.saved_model import layer_serialization File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/keras/saving/saved_model/layer_serialization.py", line 24, in <module> from tensorflow.python.keras.saving.saved_model import save_impl File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/keras/saving/saved_model/save_impl.py", line 34, in <module> from tensorflow.python.keras.saving import saving_utils File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/keras/saving/saving_utils.py", line 29, in <module> from tensorflow.python.keras.utils.io_utils import ask_to_proceed_with_overwrite File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/keras/utils/io_utils.py", line 31, in <module> import h5py File "/usr/local/lib/python3.7/dist-packages/h5py/init.py", line 25, in <module> from . import _errors File "h5py/_errors.pyx", line 1, in init h5py._errors ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 44 from C header, got 40 from PyObject
you can solve it by updating NumPy package version into the newest. Simply, enter this command on your Raspberry Pi. Firstly, check your NumPy version using ‘pip3 list’ command
pip3 list
Then check your NumPy version. If you got version below 1.20.3 you might to update it using this command
pip3 install -U numpy
Error Message 2: AttributeError: ‘str’ object has no attribute ‘decode’
Probably you encountered this problem while compiling your script
[INFO] loading face detector model... [INFO] loading face mask detector model... Traceback (most recent call last): File "detect_mask_webcam.py", line 98, in <module> maskNet = load_model(args["model"]) File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/keras/saving/save.py", line 146, in load_model return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile) File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/keras/saving/hdf5_format.py", line 166, in load_model_from_hdf5 model_config = json.loads(model_config.decode('utf-8')) AttributeError: 'str' object has no attribute 'decode'
After some little troubleshooting, I’ve found that the problem happened because of the H5Py package in your Raspberry Pi. Someone tells you can uncomment (or delete) script line 166 as mentioned in the error warning above. But I think it’s not safe for next future compiling when you needed. So I found another workaround by downgrading H5Py into an older version. Do a couple of scripts below to uninstall the existing package into the older one
pip3 uninstall h5py pip3 install h5py==2.10.0
You can double check wether the installation succeed or not by typing ‘pip3 list’ command
I hope my ‘little notes’ above able to help someone who get crashed in their scripts and confuse how to to solve it. Cheers …
a Technopreneur – writer – Enthusiastic about learning AI, IoT, Robotics, Raspberry Pi, Arduino, ESP8266, Delphi, Python, Javascript, PHP, etc. Founder of startup Indomaker.com