def testHotdog(self):
        with TestImage('hotdog.jpg') as image:
            with ImageInference(dish_classification.model()) as inference:
                classes = dish_classification.get_classes(inference.run(image))
                label, score = classes[0]
                self.assertEqual('Hot dog', label)
                self.assertAlmostEqual(score, 0.744, delta=0.001)

                label, score = classes[1]
                self.assertEqual('Lobster roll', label)
                self.assertAlmostEqual(score, 0.119, delta=0.001)
Esempio n. 2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--input', '-i', dest='input', required=True)
    args = parser.parse_args()

    with ImageInference(dish_classification.model()) as inference:
        image = Image.open(args.input)
        classes = dish_classification.get_classes(
            inference.run(image), top_k=5, threshold=0.1)
        for i, (label, score) in enumerate(classes):
            print('Result %d: %s (prob=%f)' % (i, label, score))
    def testHotdog(self):
        with TestImage('hotdog.jpg') as image:
            with ImageInference(dish_classification.model()) as inference:
                classes = dish_classification.get_classes(inference.run(image))
                label, score = classes[0]
                self.assertEqual('Hot dog', label)
                self.assertAlmostEqual(score, 0.744, delta=0.001)

                label, score = classes[1]
                self.assertEqual('Lobster roll', label)
                self.assertAlmostEqual(score, 0.119, delta=0.001)
Esempio n. 4
0
def run():
    if KeepWatchForSeconds(3):
        print("Going shutdown by GPIO")
        leds.update(Leds.rgb_off())
        os.system("/sbin/shutdown -h now 'Poweroff by GPIO'")

    else:
        print("Beep sound")
        toneplayer.play(*BEEP_SOUND)

        leds.update(Leds.rgb_on(RED))
        print("Taking photo")
        with picamera.PiCamera() as camera:
            camera.resolution = (640, 480)
            camera.start_preview()
            sleep(3.000)
            camera.capture(photo_filename)

        leds.update(Leds.rgb_on(GREEN))
        print("Dish classifier")
        with ImageInference(dish_classification.model()) as inference:
            image = Image.open(photo_filename)
            classes = dish_classification.get_classes(
                inference.run(image),
                max_num_objects=5,
                object_prob_threshold=0.1)
            dish_name = ''
            for i, (label, score) in enumerate(classes):
                dish_name += label + '/'
                print('Result %d: %s (prob=%f)' % (i, label, score))

        leds.update(Leds.rgb_on(BLUE))
        print("Post to slack")
        slack.files.upload(photo_filename,
                           channels='#food_diary',
                           title=dish_name)

        leds.update(Leds.rgb_on(WHITE))
Esempio n. 5
0
 def test_dish_classification(self):
     avg_end_to_end, avg_bonnet = self.benchmarkModel(
         dish_classification.model(), dish_classification.get_classes)
     self.assertLatency(avg_bonnet, 304.0)
     self.assertLatency(avg_end_to_end, 328.0)
 def test_dish_classification(self):
     avg_end_to_end, avg_bonnet = self.benchmarkModel(
         dish_classification.model(), dish_classification.get_classes)
     self.assertLatency(avg_bonnet, 304.0)
     self.assertLatency(avg_end_to_end, 328.0)