|
6 | 6 | from c4dynamics import c4d |
7 | 7 | from c4dynamics import pixelpoint |
8 | 8 | from typing import Optional |
| 9 | +import importlib.resources as resources |
9 | 10 |
|
10 | 11 | MODEL_SIZE = (416, 416, 3) |
11 | 12 |
|
@@ -217,18 +218,13 @@ def __init__(self, weights_path: Optional[str] = None) -> None: |
217 | 218 | weights_path = c4d.datasets.nn_model('YOLOv3') |
218 | 219 | errormsg = "Try to clear the cache by 'c4dynamics.datasets.clear_cache()'" |
219 | 220 |
|
220 | | - |
221 | | - |
222 | 221 | if not os.path.exists(weights_path): |
223 | 222 | raise FileNotFoundError(f"The file 'yolov3.weights' does not " |
224 | 223 | f"exist in: '{weights_path}'. {errormsg}") |
225 | 224 |
|
226 | | - |
227 | | - cfg_path = os.path.join(os.path.dirname(__file__), 'yolov3.cfg') |
228 | | - # cfg_path = 'yolov3.cfg' |
229 | | - # coconames = os.path.join(yolodir, 'coco.names') |
230 | | - |
231 | | - self.net = cv2.dnn.readNetFromDarknet(cfg_path, weights_path) |
| 225 | + with resources.path('c4dynamics.detectors', 'yolov3.cfg') as cfgpath: |
| 226 | + self.net = cv2.dnn.readNetFromDarknet(str(cfgpath), weights_path) |
| 227 | + |
232 | 228 | self.net.setPreferableBackend(cv2.dnn.DNN_BACKEND_OPENCV) |
233 | 229 | ln = self.net.getLayerNames() |
234 | 230 | self.ln = [ln[i - 1] for i in self.net.getUnconnectedOutLayers()] |
@@ -661,26 +657,6 @@ def detect(self, frame: np.ndarray) -> list[pixelpoint]: |
661 | 657 |
|
662 | 658 | if __name__ == "__main__": |
663 | 659 |
|
664 | | -# import doctest, contextlib |
665 | | -# from c4dynamics import IgnoreOutputChecker, cprint |
666 | | - |
667 | | -# # Register the custom OutputChecker |
668 | | -# doctest.OutputChecker = IgnoreOutputChecker |
669 | | - |
670 | | -# tofile = False |
671 | | -# optionflags = doctest.FAIL_FAST |
672 | | - |
673 | | -# if tofile: |
674 | | -# with open(os.path.join('tests', '_out', 'output.txt'), 'w') as f: |
675 | | -# with contextlib.redirect_stdout(f), contextlib.redirect_stderr(f): |
676 | | -# result = doctest.testmod(optionflags = optionflags) |
677 | | -# else: |
678 | | -# result = doctest.testmod(optionflags = optionflags) |
679 | | - |
680 | | -# if result.failed == 0: |
681 | | -# cprint(os.path.basename(__file__) + ": all tests passed!", 'g') |
682 | | -# else: |
683 | | -# print(f"{result.failed}") |
684 | 660 | from c4dynamics import rundoctests |
685 | 661 | rundoctests(sys.modules[__name__]) |
686 | 662 |
|
|
0 commit comments