class TeachableMachineImprinting(TeachableMachine):
    def __init__(self, model_path, ui, output_path, keep_classes):
        TeachableMachine.__init__(self, model_path, ui)
        self._BATCHSIZE = 1  # batch size for the engine to train for once.
        from imprinting import DemoImprintingEngine
        self._engine = DemoImprintingEngine(model_path, output_path,
                                            keep_classes, self._BATCHSIZE)

    def classify(self, img, svg):
        # Classifty current image and determine
        classification = self._engine.classify(img)
        # Interpret user button presses (if any)
        debounced_buttons = self._ui.getDebouncedButtonState()
        for i, b in enumerate(debounced_buttons):
            if not b: continue
            if i == 0: self._engine.clear()  # Hitting button 0 resets
            else:
                self._engine.addImage(img,
                                      i)  # otherwise the button # is the class
        # Hitting exactly all 4 class buttons simultaneously quits the program.
        if sum(filter(
                lambda x: x,
                debounced_buttons[1:])) == 4 and not debounced_buttons[0]:
            self.clean_shutdown = True
            return True  # return True to shut down pipeline
        return self.visualize(classification, svg)
Beispiel #2
0
 def __init__(self, model_path, ui, output_path, keep_classes):
   TeachableMachine.__init__(self, model_path, ui)
   self._BATCHSIZE = 1 # batch size for the engine to train for once.
   from imprinting import DemoImprintingEngine
   self._engine = DemoImprintingEngine(model_path, output_path, keep_classes, self._BATCHSIZE)