Skip to content

Commit

Permalink
ultralytics 8.1.2 scope HUB-SDK imports (ultralytics#7596)
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
  • Loading branch information
2 people authored and hmurari committed Apr 17, 2024
1 parent b5232bd commit 423272c
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 20 deletions.
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ dependencies = [
"thop>=0.1.1", # FLOPs computation
"pandas>=1.1.4",
"seaborn>=0.11.0", # plotting
"hub-sdk>=0.0.2", # Ultralytics HUB
]

# Optional dependencies ------------------------------------------------------------------------------------------------
Expand All @@ -103,13 +102,11 @@ export = [
"tensorflow<=2.13.1", # TF bug https://github.com/ultralytics/ultralytics/issues/5161
"tensorflowjs>=3.9.0", # TF.js export, automatically installs tensorflow
]

explorer = [
"lancedb", # vector search
"duckdb", # SQL queries, supports lancedb tables
"streamlit", # visualizing with GUI
]

# tensorflow>=2.4.1,<=2.13.1 # TF exports (-cpu, -aarch64, -macos)
# tflite-support # for TFLite model metadata
# scikit-learn==0.19.2 # CoreML quantization
Expand All @@ -121,6 +118,7 @@ logging = [
"dvclive>=2.12.0",
]
extra = [
"hub-sdk>=0.0.2", # Ultralytics HUB
"ipython", # interactive notebook
"albumentations>=1.0.3", # training augmentations
"pycocotools>=2.0.6", # COCO mAP
Expand Down
2 changes: 1 addition & 1 deletion ultralytics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license

__version__ = "8.1.1"
__version__ = "8.1.2"

from ultralytics.data.explorer.explorer import Explorer
from ultralytics.models import RTDETR, SAM, YOLO
Expand Down
7 changes: 3 additions & 4 deletions ultralytics/engine/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
from pathlib import Path
from typing import Union

from hub_sdk.config import HUB_WEB_ROOT

from ultralytics.cfg import TASK2DATA, get_cfg, get_save_dir
from ultralytics.nn.tasks import attempt_load_one_weight, guess_model_task, nn, yaml_model_load
from ultralytics.utils import ASSETS, DEFAULT_CFG_DICT, LOGGER, RANK, SETTINGS, callbacks, checks, emojis, yaml_load
from ultralytics.hub.utils import HUB_WEB_ROOT


class Model(nn.Module):
Expand Down Expand Up @@ -123,9 +122,9 @@ def is_hub_model(model):
(
model.startswith(f"{HUB_WEB_ROOT}/models/"), # i.e. https://hub.ultralytics.com/models/MODEL_ID
[len(x) for x in model.split("_")] == [42, 20], # APIKEY_MODELID
len(model) == 20 and not Path(model).exists() and all(x not in model for x in "./\\"),
len(model) == 20 and not Path(model).exists() and all(x not in model for x in "./\\"), # MODELID
)
) # MODELID
)

def _new(self, cfg: str, task=None, model=None, verbose=True):
"""
Expand Down
8 changes: 5 additions & 3 deletions ultralytics/hub/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license

import requests
from hub_sdk import HUB_API_ROOT, HUB_WEB_ROOT, HUBClient

from ultralytics.data.utils import HUBDatasetStats
from ultralytics.hub.auth import Auth
from ultralytics.hub.utils import PREFIX
from ultralytics.utils import LOGGER, SETTINGS
from ultralytics.hub.utils import HUB_API_ROOT, HUB_WEB_ROOT, PREFIX
from ultralytics.utils import LOGGER, SETTINGS, checks


def login(api_key: str = None, save=True) -> bool:
Expand All @@ -21,6 +20,9 @@ def login(api_key: str = None, save=True) -> bool:
Returns:
bool: True if authentication is successful, False otherwise.
"""
checks.check_requirements("hub-sdk>=0.0.2")
from hub_sdk import HUBClient

api_key_url = f"{HUB_WEB_ROOT}/settings?tab=api+keys" # set the redirect URL
saved_key = SETTINGS.get("api_key")
active_key = api_key or saved_key
Expand Down
3 changes: 1 addition & 2 deletions ultralytics/hub/auth.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license

import requests
from hub_sdk import HUB_API_ROOT, HUB_WEB_ROOT

from ultralytics.hub.utils import PREFIX, request_with_credentials
from ultralytics.hub.utils import HUB_API_ROOT, HUB_WEB_ROOT, PREFIX, request_with_credentials
from ultralytics.utils import LOGGER, SETTINGS, emojis, is_colab

API_KEY_URL = f"{HUB_WEB_ROOT}/settings?tab=api+keys"
Expand Down
10 changes: 6 additions & 4 deletions ultralytics/hub/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from pathlib import Path

import requests
from hub_sdk import HUB_WEB_ROOT, HUBClient

from ultralytics.hub.utils import HELP_MSG, PREFIX, TQDM
from ultralytics.hub.utils import HUB_WEB_ROOT, HELP_MSG, PREFIX, TQDM
from ultralytics.utils import LOGGER, SETTINGS, __version__, checks, emojis, is_colab
from ultralytics.utils.errors import HUBModelError

Expand Down Expand Up @@ -44,6 +43,9 @@ def __init__(self, identifier):
ValueError: If the provided model identifier is invalid.
ConnectionError: If connecting with global API key is not supported.
"""
checks.check_requirements("hub-sdk>=0.0.2")
from hub_sdk import HUBClient

self.rate_limits = {
"metrics": 3.0,
"ckpt": 900.0,
Expand All @@ -70,8 +72,8 @@ def __init__(self, identifier):
def load_model(self, model_id):
"""Loads an existing model from Ultralytics HUB using the provided model identifier."""
self.model = self.client.model(model_id)
if not self.model.data: # then model model does not exist
raise ValueError(emojis(f"❌ The specified HUB model does not exist")) # TODO: improve error handling
if not self.model.data: # then model does not exist
raise ValueError(emojis("❌ The specified HUB model does not exist")) # TODO: improve error handling

self.model_url = f"{HUB_WEB_ROOT}/models/{self.model.id}"

Expand Down
4 changes: 4 additions & 0 deletions ultralytics/hub/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license

import os
import platform
import random
import sys
Expand Down Expand Up @@ -27,6 +28,9 @@
)
from ultralytics.utils.downloads import GITHUB_ASSETS_NAMES

HUB_API_ROOT = os.environ.get("ULTRALYTICS_HUB_API", "https://api.ultralytics.com")
HUB_WEB_ROOT = os.environ.get("ULTRALYTICS_HUB_WEB", "https://hub.ultralytics.com")

PREFIX = colorstr("Ultralytics HUB: ")
HELP_MSG = "If this issue persists please visit https://github.com/ultralytics/hub/issues for assistance."

Expand Down
4 changes: 1 addition & 3 deletions ultralytics/utils/callbacks/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import json
from time import time

from hub_sdk.config import HUB_WEB_ROOT

from ultralytics.hub.utils import PREFIX, events
from ultralytics.hub.utils import HUB_WEB_ROOT, PREFIX, events
from ultralytics.utils import LOGGER, SETTINGS


Expand Down

0 comments on commit 423272c

Please sign in to comment.