def train(self): """Enqueue an event to train person group and report train progress""" group = ModelFactory.registered_group() group.cognitive.train() # Keep querying training status every 1 second while True: train_result = group.cognitive.trainingStatus() # Completed training event will have status succeeded or failed if (train_result['status'] == 'succeeded' or train_result['status'] == 'failed'): break time.sleep(1)
def identify(self, register_new): """Identify a person or a group of people captured by camera""" registered_group = ModelFactory.registered_group() faces = self.record(False) recognized_people = registered_group.identify(faces) if len(recognized_people) > 0: for person in recognized_people: print 'Xin chao %s' % person Speaker.speak(person) # If register on premise mode is turn on then register person # in case we cannot identify who he is if register_new is True and len(recognized_people) == 0: self.record(True)
def register(self, data_path): """Register a group of people specified in data folder and train Args: data_path (string): train data folder """ if data_path == 'default': data_path = Utilities.train_data_path() if Utilities.file_exists(data_path): group = ModelFactory.registered_group() group.save() for alias_name in os.listdir(data_path): # Ignore gitkeep file and collect data from all folders if alias_name != '.gitkeep': logger.log('Registering %s...' % alias_name) Person.register(group, alias_name) # After everything is done, call api to train newly created group self.train()