News How to Build a Face Mask Detector with Raspberry Pi

When i run, I got error 🙁

[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'
 
When i run, I got error 🙁

[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'
Hi Andrew,
I too encountered the same error I found out its because of h5py version 3.0.0 , one of the solution I found on git was to remove .decode() from hdf5_format.py . I'll post the git link for your reference.
https://github.com/tensorflow/tensorflow/issues/44467
 
  • Like
Reactions: Andrew_1313
Hi Andrew,
I too encountered the same error I found out its because of h5py version 3.0.0 , one of the solution I found on git was to remove .decode() from hdf5_format.py . I'll post the git link for your reference.
https://github.com/tensorflow/tensorflow/issues/44467
Hi Kart94
Its work now. I correct lines: 166, 180, 651, and 655 :) Thanks

i use comands su and nano to edit hdf5_format.py.
Example change line 166"
model_config = json.loads(model_config)#.decode('utf-8'))
"
 
Last edited:
hi there
i tried this project with my new raspberri pi4 with 4 Gb of ram
the video with mask detection is lagging too much! and it have a lot of delay....
Some one can help me to improve the detection in less time? thanks a lot
Marco
 
  • Like
Reactions: ju34
Hi, I have already removed the ".decode(UTF-8)" from hdf5_format.py, but it's still not working. When I try to run, it displays this:

[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 169, in load_model_from_hdf5
custom_objects=custom_objects)
File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/keras/saving/model_config.py", line 55, in model_from_config
return deserialize(config, custom_objects=custom_objects)
File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/keras/layers/serialization.py", line 98, in deserialize
layer_class_name = config['class_name']
TypeError: 'function' object is not subscriptable
 
you must only delete .decode(UTF-8) from hdf5_format.py in the line: lines: 166, 180, 651, and 655
say me if it works and if the camera is lagging and if it have some delay
 
Hi. Thanks to you, I was able to make a good mask detection program. Thank you.
I want to add one more thing.

If you don't wear a mask, you'll sound a siren.
What additional code should I add if I want to play a video from a file that recommends wearing a mask?
 
When i am running the detect_mask_picam.py i am getting the following error

[INFO] loading face detector model...
[INFO] loading face mask detector model...
Traceback (most recent call last):
File "detect_mask_video.py", line 98, in <module>
maskNet = load_model(args["model"])
File "/home/pi/mask_project/mask-env/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/save.py", line 149, in load_model
loader_impl.parse_saved_model(filepath)
File "/home/pi/mask_project/mask-env/lib/python3.7/site-packages/tensorflow_core/python/saved_model/loader_impl.py", line 83, in parse_saved_model
constants.SAVED_MODEL_FILENAME_PB))
OSError: SavedModel file does not exist at: mask_detector.model/{saved_model.pbtxt|saved_model.pb}


what to do please help
 
Smart facial Recognition systems support changes in a Person's appearance. Such systems can be very slow if you went all winter with a headdress, and then came without.
 
When I am running the detect_mask_picam.py i am getting the following error

[INFO] loading face detector model...
[INFO] loading face mask detector model...
Traceback (most recent call last):
File "detect_mask_video.py", line 98, in <module>
maskNet = load_model(args["model"])
File "/home/pi/mask_project/mask-env/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/save.py", line 149, in load_model
loader_impl.parse_saved_model(filepath)
File "/home/pi/mask_project/mask-env/lib/python3.7/site-packages/tensorflow_core/python/saved_model/loader_impl.py", line 83, in parse_saved_model
constants.SAVED_MODEL_FILENAME_PB))
OSError: SavedModel file does not exist at: mask_detector.model/{saved_model.pbtxt|saved_model.pb}


what to do please help
I got the same error pleas to help me
 
Hi. Thanks to you, I was able to make a good mask detection program. Thank you.
I want to add one more thing.

If you don't wear a mask, you'll sound a siren.
What additional code should I add if I want to play a video from a file that recommends wearing a mask?
I also would be interested if anyone has done this? Any responses or help given?
 
When i run, I got error 🙁

[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'

----

I had the same problem. The problem comes from h5py version 3.0.0+

I installed an older version of h5py by:
pip3 install h5py version==2.10.0

Maybe first uninstall any other h5py version.
 
Wow, I didn't know that there are already such apps... I should try it, just curious how it works 🤔 I am so impressed by all technologies that I read a lot about such stuff. For example, this was the last article I read https://recfaces.com/articles/how-to-catch-shoplifter and it explains how store owners can catch a shoplifter using technologies.
 
Last edited:
New to Raspberry pi
Need Help:



OSError: SavedModel file does not exist at: mask_detector.model/{saved_model.pbtxt|saved_model.pb}



hey guys i found a soution for this remove h5py lib if it is installed by pip
and try this
sudo apt-get install python3-h5py
 
Last edited:
Can someone help me with this!!
Been getting this error every time I run it.

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
 
hey anyone help me with this !
i am running in to this errors

[INFO] saving mask detector model...
Traceback (most recent call last):
File "train_mask_detector.py", line 149, in <module>
plt.plot(np.arange(0, N), H.history["val_loss"], label="val_loss")
KeyError: 'val_loss'
 
plz help me i get this error
its important for my project last year:
pi@raspberrypi:~/face_mask_detection $ python3 train_mask_detector.py --dataset dataset --plot mymodelplot.png --model my_mask_detector.model
Matplotlib is building the font cache; this may take a moment.
[INFO] loading images...
/home/pi/.local/lib/python3.7/site-packages/keras_applications/mobilenet_v2.py:294: UserWarning: input_shape is undefined or non-square, or rows is not in [96, 128, 160, 192, 224]. Weights for input shape (224, 224) will be loaded as the default.
warnings.warn('input_shape is undefined or non-square, '
Downloading data from https://github.com/JonathanCMitchel..._tf_dim_ordering_tf_kernels_1.0_224_no_top.h5
9412608/9406464 [==============================] - 11s 1us/step
Traceback (most recent call last):
File "train_mask_detector.py", line 92, in <module>
input_tensor=Input(shape=(224, 224, 3)))
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/keras/applications/init.py", line 46, in wrapper
return base_fun(args, *kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/keras/applications/mobilenet_v2.py", line 32, in MobileNetV2
return mobilenet_v2.MobileNetV2(args, *kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/keras_applications/mobilenet_v2.py", line 418, in MobileNetV2
model.load_weights(weights_path)
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training.py", line 234, in load_weights
return super(Model, self).load_weights(filepath, by_name, skip_mismatch)
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/network.py", line 1222, in load_weights
hdf5_format.load_weights_from_hdf5_group(f, self.layers)
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/hdf5_format.py", line 651, in load_weights_from_hdf5_group
original_keras_version = f.attrs['keras_version'].decode('utf8')
AttributeError: 'str' object has no attribute 'decode'