コード例 #1
0
ファイル: dish_detection.py プロジェクト: eosurman/physicsc
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--input', '-i', dest='input', required=True)
    parser.add_argument('--output', '-o', dest='output')
    args = parser.parse_args()

    with ImageInference(dish_detection.model()) as inference:
        image = Image.open(args.input)
        draw = ImageDraw.Draw(image)
        dishes = dish_detection.get_dishes(inference.run(image))
        for i, dish in enumerate(dishes):
            print('Dish #%d: %s' % (i, dish))
            x, y, width, height = dish.bounding_box
            draw.rectangle((x, y, x + width, y + height), outline='red')
        if args.output:
            image.save(args.output)
コード例 #2
0
ファイル: dish_detection.py プロジェクト: even00/physicsc
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--input', '-i', dest='input', required=True)
    parser.add_argument('--output', '-o', dest='output')
    args = parser.parse_args()

    with ImageInference(dish_detection.model()) as inference:
        image = Image.open(args.input)
        draw = ImageDraw.Draw(image)
        dishes = dish_detection.get_dishes(inference.run(image))
        for i, dish in enumerate(dishes):
            print('Dish #%d: %s' % (i, dish))
            x, y, width, height = dish.bounding_box
            draw.rectangle((x, y, x + width, y + height), outline='red')
        if args.output:
            image.save(args.output)
コード例 #3
0
    def testHotdog(self):
        with TestImage('hotdog.jpg') as image:
            with ImageInference(dish_detection.model()) as inference:
                dishes = dish_detection.get_dishes(inference.run(image), top_k=3, threshold=0.1)
                self.assertEqual(1, len(dishes))
                dish = dishes[0]

                self.assertEqual((417.0, 51.0, 2438.0, 2388.0), dish.bounding_box)
                self.assertEqual(2, len(dish.sorted_scores))

                label, score = dish.sorted_scores[0]
                self.assertEqual('Hot dog', label)
                self.assertAlmostEqual(0.223, score, delta=0.001)

                label, score = dish.sorted_scores[1]
                self.assertEqual('Bento', label)
                self.assertAlmostEqual(0.152, score, delta=0.001)