Skip to content

Commit

Permalink
update ultralytics (#46)
Browse files Browse the repository at this point in the history
* update ultralytics

* add return_dict to push_to_hfhub

* Update __init__.py
  • Loading branch information
fcakyon authored Jan 27, 2023
1 parent 4ec078b commit 1f5ddf0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
huggingface_hub>=0.12.0
fire
ultralytics>=8.0.20,<8.0.21
ultralytics>=8.0.21,<8.0.22
sahi>=0.11.11,<0.12.0
pandas
2 changes: 1 addition & 1 deletion ultralyticsplus/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .hf_utils import download_from_hub, push_to_hfhub
from .ultralytics_utils import YOLO, postprocess_classify_output, render_result

__version__ = "0.0.22"
__version__ = "0.0.23"
15 changes: 15 additions & 0 deletions ultralyticsplus/hf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pandas as pd
from sahi.utils.cv import read_image_as_pil

from ultralyticsplus.other_utils import add_text_to_image

LOGLEVEL = os.environ.get("LOGLEVEL", "INFO").upper()
Expand All @@ -24,6 +25,7 @@ def generate_model_usage_markdown(
custom_tags=None,
):
from ultralytics import __version__ as ultralytics_version

from ultralyticsplus import __version__ as ultralyticsplus_version

hf_task = "image-segmentation" if task == "instance-segmentation" else task
Expand Down Expand Up @@ -472,6 +474,7 @@ def push_to_hfhub(
hf_dataset_id=None,
thumbnail_text=None,
custom_tags=None,
return_dict=False,
):
"""
Pushes a ultralytics model to huggingface hub
Expand All @@ -484,6 +487,7 @@ def push_to_hfhub(
hf_dataset_id (str): huggingface dataset id to be used for model card
thumbnail_text (str): text to be used in thumbnail
custom_tags (list): list of custom tags to be used for model card
return_dict (bool): whether to return a dictionary of results or not
"""
from ultralytics import YOLO

Expand Down Expand Up @@ -534,6 +538,17 @@ def push_to_hfhub(
custom_tags=custom_tags
)

if return_dict:
return {
'score_map50': score_map50,
'score_map50_mask': score_map50_mask,
'score_top1_acc': score_top1_acc,
'score_top5_acc': score_top5_acc,
'task': task,
'model_type': model.type,
'thumbnail_url': f"https://huggingface.co/{hf_model_id}/resolve/main/thumbnail.jpg"
}


def download_from_hub(hf_model_id, hf_token=None):
"""
Expand Down

0 comments on commit 1f5ddf0

Please sign in to comment.