external_test_yolo.py 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. import unittest
  2. from pathlib import Path
  3. import cv2
  4. from examples.yolov3 import Darknet, infer, show_labels
  5. from tinygrad.helpers import fetch
  6. chicken_img = cv2.imread(str(Path(__file__).parent.parent / 'models/efficientnet/Chicken.jpg'))
  7. car_img = cv2.imread(str(Path(__file__).parent.parent / 'models/efficientnet/car.jpg'))
  8. class TestYOLO(unittest.TestCase):
  9. @classmethod
  10. def setUpClass(cls):
  11. cls.model = Darknet(fetch("https://raw.githubusercontent.com/pjreddie/darknet/master/cfg/yolov3.cfg").read_bytes())
  12. print("Loading weights file (237MB). This might take a while…")
  13. cls.model.load_weights("https://pjreddie.com/media/files/yolov3.weights")
  14. @classmethod
  15. def tearDownClass(cls):
  16. del cls.model
  17. def test_chicken(self):
  18. labels = show_labels(infer(self.model, chicken_img), confidence=0.56)
  19. self.assertEqual(labels, ["bird"])
  20. def test_car(self):
  21. labels = show_labels(infer(self.model, car_img))
  22. self.assertEqual(labels, ["car"])
  23. if __name__ == '__main__':
  24. unittest.main()