Skip to content

Commit df9fb59

Browse files
committed
Version 0.0.1-alpha.0.
1 parent 9313144 commit df9fb59

8 files changed

Lines changed: 35 additions & 7 deletions

File tree

49.7 MB
Binary file not shown.
11.2 MB
Binary file not shown.
21.5 MB
Binary file not shown.

leads_jarvis/network/detection/prototype.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
from abc import ABCMeta as _ABCMeta, abstractmethod as _abstractmethod
22
from typing import Any as _Any
33

4+
from cv2 import rectangle as _rectangle, putText as _put_text, FONT_HERSHEY_COMPLEX_SMALL as _FONT
45
from numpy import ndarray as _ndarray
56

7+
from leads_jarvis.utils import to_opencv
8+
69

710
class Detection(object, metaclass=_ABCMeta):
811
@_abstractmethod
@@ -11,3 +14,18 @@ def detect(self, image: _ndarray) -> list[dict[str, _Any]]:
1114

1215
def __call__(self, image: _ndarray) -> list[dict[str, _Any]]:
1316
return self.detect(image)
17+
18+
def mark(self, image: _ndarray, data: list[dict[str, _Any]] | None = None,
19+
filter_type: tuple[str, ...] | None = None) -> _ndarray:
20+
if data is None:
21+
data = self(image)
22+
image = to_opencv(image)
23+
for item in data:
24+
name = item["name"]
25+
if filter_type is not None and name not in filter_type:
26+
continue
27+
box = item["box"]
28+
x1, y1, x2, y2 = round(box["x1"]), round(box["y1"]), round(box["x2"]), round(box["y2"])
29+
image = _rectangle(image, (x1, y1), (x2, y2), (255, 255, 255))
30+
image = _put_text(image, name, (x1, y1 - 4), _FONT, 1, (255, 255, 255))
31+
return image

leads_jarvis/network/detection/yolo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from ultralytics import YOLO as _YOLO
55

66
from leads_jarvis.network.detection.prototype import Detection
7-
from leads_jarvis.utils import _CHECKPOINTS_PATH
7+
from leads_jarvis.utils import _CHECKPOINTS_PATH, to_opencv
88

99

1010
class PretrainedYOLOWrapper(Detection):
@@ -13,7 +13,7 @@ def __init__(self, yolo: _YOLO) -> None:
1313

1414
@_override
1515
def detect(self, image: _ndarray) -> list[dict[str, _Any]]:
16-
return self._yolo(image.transpose(1, 2, 0))[0].summary()
16+
return self._yolo(to_opencv(image))[0].summary()
1717

1818

1919
class PretrainedYOLO(Detection):

leads_jarvis/network/segmentation/sam.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
SamAutomaticMaskGenerator as _SamAutomaticMaskGenerator
66

77
from leads_jarvis.network.segmentation.prototype import Segmentation
8-
from leads_jarvis.utils import download_checkpoint
8+
from leads_jarvis.utils import download_checkpoint, to_opencv
99

1010

1111
class PretrainedSAMWrapper(Segmentation):
@@ -15,7 +15,7 @@ def __init__(self, mask_generator: _SamAutomaticMaskGenerator) -> None:
1515

1616
@_override
1717
def segment(self, image: _ndarray) -> list[dict[str, _Any]]:
18-
return self._mask_generator.generate(image.transpose(1, 2, 0))
18+
return self._mask_generator.generate(to_opencv(image))
1919

2020

2121
class PretrainedSAM(Segmentation):

leads_jarvis/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
from os.path import abspath as _abspath, exists as _exists
22

33
from leads import L as _L
4+
from numpy import ndarray as _ndarray
45
from requests import head as _head, get as _get
56
from rich.progress import Progress as _Progress
67

78
_CHECKPOINTS_PATH: str = f"{_abspath(__file__)[:-8]}checkpoints"
89

910

11+
def from_opencv(image: _ndarray) -> _ndarray:
12+
return image.transpose(2, 0, 1)
13+
14+
15+
def to_opencv(image: _ndarray) -> _ndarray:
16+
return image.transpose(1, 2, 0)
17+
18+
1019
def download_checkpoint(url: str, to: str, overwrite: bool = False) -> str:
1120
if _exists(to := f"{_CHECKPOINTS_PATH}/{to}") and not overwrite:
1221
return to

setup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="leads-jarvis",
8-
version="0.0.1",
8+
version="0.0.1-alpha.0",
99
python_requires=">=3.12",
1010
author="ProjectNeura",
1111
author_email="central@projectneura.org",
@@ -16,8 +16,9 @@
1616
url="https://github.com/ProjectNeura/LEADS-Jarvis",
1717
packages=find_packages(),
1818
package_data={
19-
"leads_jarvis": ["weights/*"]
19+
"leads_jarvis": ["checkpoints/*"]
2020
},
2121
include_package_data=True,
22-
install_requires=["leads>=0.9.1-alpha.3", "torch", "torchvision", "timm"]
22+
install_requires=["leads>=0.9.1", "torch", "torchvision", "timm", "segment-anything", "requests", "rich",
23+
"ultralytics"]
2324
)

0 commit comments

Comments
 (0)