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

Error MMM-Facial-Recognition

  • I tried to run MMM-Facial-Recognition, but it was blocked at this point.


    Whoops! There was an uncaught exception...
    { Error: KeyError: '/home/pi/MagicMirror/modules/MMM-Facial-Recognition-Tools/training.xml'
        at PythonShell.parseError (/home/pi/MagicMirror/modules/MMM-Facial-Recognition/node_modules/python-shell/index.js:246:21)
        at terminateIfNeeded (/home/pi/MagicMirror/modules/MMM-Facial-Recognition/node_modules/python-shell/index.js:129:32)
        at ChildProcess. (/home/pi/MagicMirror/modules/MMM-Facial-Recognition/node_modules/python-shell/index.js:121:13)
        at ChildProcess.emit (events.js:182:13)
        at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12)
        ----- Python Traceback -----
        File "modules/MMM-Facial-Recognition/facerecognition/", line 59, in 
        File "/home/pi/MagicMirror/modules/MMM-Facial-Recognition/facerecognition/", line 55, in get
          return CONFIG[key]
       'Traceback (most recent call last):\n  File "modules/MMM-Facial-Recognition/facerecognition/", line 59, in \n"/home/pi/MagicMirror/modules/MMM-Facial-Recognition-Tools/training.xml"))\n  File "/home/pi/MagicMirror/modules/MMM-Facial-Recognition/facerecognition/", line 55, in get\n    return CONFIG[key]\nKeyError: \'/home/pi/MagicMirror/modules/MMM-Facial-Recognition-Tools/training.xml\'\n',
      executable: 'python',
      options: null,
      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:

    my is

    import sys
    import json
    import time
    import face
    import cv2
    import config
    import signal
    def to_node(type, message):
            print(json.dumps({type: message}))
        except Exception:
    to_node("status", "Facerecognition started...")
    current_user = None
    last_match = None
    detection_active = True
    login_timestamp = time.time()
    same_user_detected_in_row = 0
    to_node("status", 'Loading training data...')
    if config.get("recognitionAlgorithm") == 1:
        to_node("status", "ALGORITHM: LBPH")
        model = cv2.face.LBPHFaceRecognizer_create(threshold=config.get("lbphThreshold"))
    elif config.get("recognitionAlgorithm") == 2:
        to_node("status", "ALGORITHM: Fisher")
        model = cv2.createFisherFaceRecognizer(threshold=config.get("fisherThreshold"))
        to_node("status", "ALGORITHM: Eigen")
        model = cv2.createEigenFaceRecognizer(threshold=config.get("eigenThreshold"))
    # Load training file specified in config.js"/home/pi/MagicMirror/modules/MMM-Facial-Recognition-Tools/training.xml"))
    to_node("status", 'Training data loaded!')
    camera = config.get_camera()
    def shutdown(self, signum):
        to_node("status", 'Shutdown: Cleaning up camera...')
    signal.signal(signal.SIGINT, shutdown)
    while True:
        if detection_active is True:
            image =
            image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
            result = face.detect_single(image)
            if result is None:
                if (current_user is not None and time.time() - login_timestamp > config.get("logoutDelay")):
                    to_node("logout", {"user": current_user})
                    same_user_detected_in_row = 0
                    current_user = None
            x, y, w, h = result
            if config.get("recognitionAlgorithm") == 1:
                crop = face.crop(image, x, y, w, h)
                crop = face.resize(face.crop(image, x, y, w, h))
            label, confidence = model.predict(crop)
            if (label != -1 and label != 0):
                login_timestamp = time.time()
                if (label == last_match and same_user_detected_in_row < 2):
                    same_user_detected_in_row += 1
                if label != last_match:
                    same_user_detected_in_row = 0
                if (label != current_user and same_user_detected_in_row > 1):
                    current_user = label
                    to_node("login", {"user": label, "confidence": str(confidence)})
                last_match = label
            elif (current_user != 0 and time.time() - login_timestamp > 5):
                login_timestamp = time.time()
                current_user = 0
                to_node("login", {"user": current_user, "confidence": None})

    #Load training file specified in config.js"/home/pi/MagicMirror/modules/MMM-Facial-Recognition-Tools/training.xml"))

    Is this the cause?
    What should I do about this part?

    my config.js is

    	module: "newsfeed",
    	position: "bottom_bar",
    	classes: 'minsoo',
    	config: {
    		feeds: [
    				title: "New York Times",
    				url: ""
    		showSourceTitle: true,
    		showPublishDate: true
    	module: 'MMM-Facial-Recognition',
    	config: {
    		recognitionAlgorithm: 1,
    		lbphThreshold: 50,
    		fisherThreshold: 250,
    		eigenThreshold: 3000,
    		useUSBCam: true,
    		trainingFile: 'modules/MMM-Facial-Recognition-Tools/training.xml',
    		interval: 2,
    		logoutDelay: 15,
    		users: ['minsoo'],
    		defaultClass: "default",
    		everyoneClass: "everyone",
    		welcomeMessage: true
    /*************** DO NOT EDIT THE LINE BELOW ***************/
    if (typeof module !== "undefined") {module.exports = config;}

    I am anxiously waiting for your help.

  • Same problem to me . Did you find a solution ?

  • the readme says

    To train the needed model use the MMM-Facial-Recognition-Tools.

    wen you follow that link, it says

    This module is no longer supported. When it does work, the facial recognition methods used performed poorly.

    there are a LOT of steps to execute to ‘train the model’

    did u do that? (it creates the missing xml file)

  • to work on a user problem with one of my modules, I installed the module, and it was very complex and time consuming. (I installed in on my linux PC, not my pi)

  • what do you suggest ?

  • @merttcoo i don’t have a recommendation. I don’t use this function

    so you can try the steps to create the model with the one you have partly installed,
    or you can try the other one.

Log in to reply