-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from cospectrum/dev
remove OpenCV NMS
- Loading branch information
Showing
5 changed files
with
100 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,7 @@ wheels/ | |
.venv | ||
venv | ||
|
||
generated | ||
output.png | ||
|
||
draw.py | ||
boxes.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from microwink import SegModel | ||
from microwink.common import draw_mask, draw_box | ||
|
||
from PIL import Image | ||
from pathlib import Path | ||
from tests.utils import round_box | ||
|
||
MODEL_PATH = "./models/seg_model.onnx" | ||
SAVE_TO = Path("./generated") | ||
|
||
|
||
def main() -> None: | ||
SAVE_TO.mkdir(exist_ok=True) | ||
seg_model = SegModel.from_path(MODEL_PATH) | ||
|
||
for img_path in Path("./assets/data/").iterdir(): | ||
img = Image.open(img_path).convert("RGB") | ||
cards = seg_model.apply(img) | ||
|
||
print(img_path.name) | ||
for card in cards: | ||
img = draw_box(img, card.box) | ||
img = draw_mask(img, card.mask > 0.5) | ||
print(round_box(card.box)) | ||
print() | ||
img.save(SAVE_TO / img_path.name) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from pathlib import Path | ||
|
||
|
||
Script = str | ||
|
||
|
||
def test_readme() -> None: | ||
readme_path = Path("./README.md") | ||
start_tag = "```python" | ||
end_tag = "```" | ||
scripts = parse_readme_code(readme_path, start_tag, end_tag) | ||
for script in scripts: | ||
print("\n# executing the following script") | ||
print(script) | ||
print("\n# stdout...") | ||
exec(script) | ||
|
||
|
||
def parse_readme_code(path: Path, start_tag: str, end_tag) -> list[Script]: | ||
assert path.exists() | ||
text = path.read_text() | ||
_, *sections = text.split(start_tag) | ||
scripts = [] | ||
for section in sections: | ||
script, *_ = section.split(end_tag) | ||
scripts.append(script.strip()) | ||
return scripts |