MagicMirror² v2.13.0 is available! For more information about this release, check out this topic.

Magic mirror using hdf5

  • Hello!
    I am making emotion detection module but some error message appears.

    Traceback (most recent call last):
      File "modules/MMM-Test/", line 11, in 
        emotion_classifier = load_model(os.getcwd()+'/files/emotion_model.hdf5', compile=False)
      File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/", line 140, in load_model
      File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/saved_model/", line 83, in parse_saved_model
    OSError: SavedModel file does not exist at: /home/pi/MagicMirror/files/emotion_model.hdf5/{saved_model.pbtxt|saved_model.pb}
        at PythonShell.parseError (/home/pi/MagicMirror/modules/MMM-Test/node_modules/python-shell/index.js:268:21)
        at terminateIfNeeded (/home/pi/MagicMirror/modules/MMM-Test/node_modules/python-shell/index.js:139:32)
        at ChildProcess. (/home/pi/MagicMirror/modules/MMM-Test/node_modules/python-shell/index.js:131:13)
        at ChildProcess.emit (events.js:182:13)
        at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12)
      executable: 'python3',
      options: null,
      script: 'modules/MMM-Test/',
      args: null,
      exitCode: 1 }
    MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?
    If you think this really is an issue, please open an issue on GitHub:
    Shutting down server...

    And finally I found that this error message appears when
    there is no “emotion_model.hdf5” in file/home/pi/MagicMirror/files/.
    When I run it with python3 it works well, and if I intentionally change the name of hdf5 file as “happy_model.hdf5” and run it with python3, same error appears.
    So I realized that this error means that there is no hdf5 file in the directory.
    Even though I can run it with python3, when I try to run it with magicmirror, because of that error message I couldn’t run it with magic mirror.

    I even eliminate everything except the line that means loading hdf5 file as follows.

    import cv2
    import numpy as np   
    from tensorflow.keras.preprocessing.image import img_to_array
    from tensorflow.keras.models import load_model
    import os
    import json
    import sys
    import time
    # Face detection XML load and trained model loading
    face_detection = cv2.CascadeClassifier(os.getcwd()+'/files/haarcascade_frontalface_default.xml')
    emotion_classifier = load_model(os.getcwd()+'/files/emotion_model.hdf5', compile=False)

    But same error message appears.
    Is there anyone who have ever experienced this problem or who can give me advice?
    Thank you.

  • I finally found that if I start magic mirror using “npm start”
    even if python code is not in ~/Magicmirror folder, os.getcwd() return ~/Magicmirror folder.
    I thought that it will return the location of the python code.

  • @16KYJ said in Magic mirror using hdf5:


    it returns the current working directory… (result of cd)

    you would have to modify the script to find where IT is located


Log in to reply