Skip to content

Commit

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

* updates

* fix typo in readme

* fix

* update version
  • Loading branch information
fcakyon authored Jan 21, 2023
1 parent 880ac1e commit 9b6a0cb
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ scores = result.probs # for classification models
masks = result.masks # for segmentation models

# show results on image
render = render_result(result)
render = render_result(model=model, image=image, result=result)
render.show()
```
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
huggingface_hub
fire
ultralytics>=8.0.7,<8.0.9
ultralytics>=8.0.12,<8.0.14
sahi>=0.11.11,<0.12.0
pandas
13 changes: 0 additions & 13 deletions tests/test_hf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
)

hub_id = "ultralyticsplus/yolov8s"
hub_id_generic = "kadirnar/yolov8n-v8.0"


def test_load_from_hub():
Expand Down Expand Up @@ -57,15 +56,3 @@ def test_classification_inference():
results = model(image, imgsz=640)
name_to_probs = postprocess_classify_output(model=model, result=results[0])
name_to_probs


def test_inference_generic():
model = YOLO(hub_id_generic)

# set image
image = "https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg"

# perform inference
results = model.predict(image, imgsz=640)
render = render_result(model=model, image=image, result=results[0])
render.show()
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.14"
__version__ = "0.0.15"
5 changes: 2 additions & 3 deletions ultralyticsplus/hf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
from pathlib import Path

import pandas as pd
from PIL import Image
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 @@ -26,6 +24,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 @@ -136,7 +135,7 @@ def generate_model_usage_markdown(
- Install [ultralyticsplus](https://github.com/fcakyon/ultralyticsplus):
```bash
pip install -U ultralyticsplus
pip install ultralyticsplus=={ultralyticsplus_version}
```
- Load model and perform prediction:
Expand Down
12 changes: 5 additions & 7 deletions ultralyticsplus/ultralytics_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@
class YOLO(YOLOBase):
def __init__(self, model="yolov8n.yaml", type="v8", hf_token=None) -> None:
"""
> Initializes the YOLO object.
Initializes the YOLO object.
Args:
model (str, Path): model to load or create
type (str): Type/version of models to use. Defaults to "v8".
hf_token (str): huggingface token
"""
self.type = type
self.ModelClass = None # model class
self.TrainerClass = None # trainer class
self.ValidatorClass = None # validator class
self.PredictorClass = None # predictor class
self.predictor = None # reuse predictor
self.model = None # model object
self.trainer = None # trainer object
self.task = None # task type
Expand Down Expand Up @@ -64,12 +66,8 @@ def _load_from_hf_hub(self, weights: str, hf_token=None):
self.task = self.model.args["task"]
self.overrides = self.model.args
self._reset_ckpt_args(self.overrides)
(
self.ModelClass,
self.TrainerClass,
self.ValidatorClass,
self.PredictorClass,
) = self._guess_ops_from_task(self.task)
self.ModelClass, self.TrainerClass, self.ValidatorClass, self.PredictorClass = \
self._guess_ops_from_task(self.task)


def render_model_output_legacy(image, model: YOLO, model_output: dict) -> Image.Image:
Expand Down

0 comments on commit 9b6a0cb

Please sign in to comment.