MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Error MMM-Facial-Recognition

    Scheduled Pinned Locked Moved Unsolved Troubleshooting
    6 Posts 3 Posters 750 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K Offline
      kms4381
      last edited by kms4381

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

      0_1557156588303_error.png

      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.<anonymous> (/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/facerecognition.py", line 59, in <module>
            model.read(config.get("/home/pi/MagicMirror/modules/MMM-Facial-Recognition-Tools/training.xml"))
          File "/home/pi/MagicMirror/modules/MMM-Facial-Recognition/facerecognition/config.py", line 55, in get
            return CONFIG[key]
        traceback:
         'Traceback (most recent call last):\n  File "modules/MMM-Facial-Recognition/facerecognition/facerecognition.py", line 59, in <module>\n    model.read(config.get("/home/pi/MagicMirror/modules/MMM-Facial-Recognition-Tools/training.xml"))\n  File "/home/pi/MagicMirror/modules/MMM-Facial-Recognition/facerecognition/config.py", line 55, in get\n    return CONFIG[key]\nKeyError: \'/home/pi/MagicMirror/modules/MMM-Facial-Recognition-Tools/training.xml\'\n',
        executable: 'python',
        options: null,
        script:
         'modules/MMM-Facial-Recognition/facerecognition/facerecognition.py',
        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: https://github.com/MichMich/MagicMirror/issues
      
      

      my facerecognition.py is

      
      import sys
      import json
      import time
      import face
      import cv2
      import config
      import signal
      
      def to_node(type, message):
          try:
              print(json.dumps({type: message}))
          except Exception:
              pass
          sys.stdout.flush()
      
      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"))
      else:
          to_node("status", "ALGORITHM: Eigen")
          model = cv2.createEigenFaceRecognizer(threshold=config.get("eigenThreshold"))
      
      # Load training file specified in config.js
      model.read(config.get("/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...')
          camera.stop()
          quit()
      
      signal.signal(signal.SIGINT, shutdown)
      
      time.sleep(1)
      
      while True:
          time.sleep(config.get("interval"))
          if detection_active is True:
              image = camera.read()
              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
                  continue
              x, y, w, h = result
              if config.get("recognitionAlgorithm") == 1:
                  crop = face.crop(image, x, y, w, h)
              else:
                  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})
              else:
                  continue
      
      

      #Load training file specified in config.js
      model.read(config.get(“/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: "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml"
      			}
      		],
      		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.

      1 Reply Last reply Reply Quote 0
      • M Offline
        merttcoo
        last edited by

        Same problem to me . Did you find a solution ?

        1 Reply Last reply Reply Quote 0
        • S Do not disturb
          sdetweil
          last edited by

          the readme says

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

          wen you follow that link, it says

          DEPRECIATED
          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)

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          1 Reply Last reply Reply Quote 0
          • S Do not disturb
            sdetweil
            last edited by

            to work on a user problem with one of my modules, I installed the https://github.com/nischi/MMM-Face-Reco-DNN module, and it was very complex and time consuming. (I installed in on my linux PC, not my pi)

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            1 Reply Last reply Reply Quote 0
            • M Offline
              merttcoo
              last edited by

              what do you suggest ?

              S 1 Reply Last reply Reply Quote 0
              • S Do not disturb
                sdetweil @merttcoo
                last edited by

                @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.

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Enjoying MagicMirror? Please consider a donation!
                MagicMirror created by Michael Teeuw.
                Forum managed by Sam, technical setup by Karsten.
                This forum is using NodeBB as its core | Contributors
                Contact | Privacy Policy