Instructions to use dl1wjd2/Logistics_AX with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ultralytics
How to use dl1wjd2/Logistics_AX with ultralytics:
from huggingface_hub import hf_hub_download from ultralytics import YOLO # pick the weights file from this repo's "Files and versions" tab weights = hf_hub_download("dl1wjd2/Logistics_AX", "<weights>.pt") model = YOLO(weights) source = 'http://images.cocodataset.org/val2017/000000039769.jpg' model.predict(source=source, save=True) - Notebooks
- Google Colab
- Kaggle
File size: 7,371 Bytes
c12ef43 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | # Copyright 2022-present, the HuggingFace Inc. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains utilities to handle paths in Huggingface Hub."""
import os
from collections.abc import Callable, Generator, Iterable
from fnmatch import fnmatchcase
from pathlib import Path
from typing import TypeVar
T = TypeVar("T")
# Always ignore `.git` and `.cache/huggingface` folders in commits
DEFAULT_IGNORE_PATTERNS = [
".git",
".git/*",
"*/.git",
"**/.git/**",
".cache/huggingface",
".cache/huggingface/*",
"*/.cache/huggingface",
"**/.cache/huggingface/**",
]
# Forbidden to commit these folders
FORBIDDEN_FOLDERS = [".git", ".cache"]
def as_extended_path(path: str | Path, max_length: int = 255) -> str:
r"""Return `path` in its Windows extended-length form if it is too long, unchanged otherwise.
Some Windows versions do not allow for paths longer than 255 characters (247 for directories, i.e. MAX_PATH minus
room for an 8.3 file name). In this case, we must specify them as extended paths by using the `\\?\` prefix, which
only works on absolute paths. Network shares take the `\\?\UNC\server\share\...` form: prefixing them verbatim
would produce an invalid `\\?\\\server\...` path.
Args:
path (`str` or `Path`):
The path to convert. Returned unchanged on non-Windows platforms, if it is short enough, or if it is
already an extended path.
max_length (`int`, *optional*):
Length above which the path must be converted. Defaults to 255, the limit for files. Pass 247 for paths
whose parent directories are created by the caller.
"""
path = str(path)
if os.name != "nt":
return path
absolute_path = os.path.abspath(path)
if len(absolute_path) <= max_length or absolute_path.startswith("\\\\?\\"):
return path
if absolute_path.startswith("\\\\"): # UNC share: `\\server\share\...` => `\\?\UNC\server\share\...`
return "\\\\?\\UNC\\" + absolute_path[2:]
return "\\\\?\\" + absolute_path
def filter_repo_objects(
items: Iterable[T],
*,
allow_patterns: list[str] | str | None = None,
ignore_patterns: list[str] | str | None = None,
key: Callable[[T], str] | None = None,
) -> Generator[T, None, None]:
"""Filter repo objects based on an allowlist and a denylist.
Input must be a list of paths (`str` or `Path`) or a list of arbitrary objects.
In the later case, `key` must be provided and specifies a function of one argument
that is used to extract a path from each element in iterable.
Patterns are Standard Wildcards (globbing patterns), NOT regular expressions. The pattern matching is based on
Python's `fnmatch.fnmatchcase`, so it is case-sensitive on every platform. Backslashes are treated as path separators
and normalized to forward slashes in both patterns and paths before matching, so patterns built with `os.path.join`
on Windows work as expected.
Note that it matches `*` across path boundaries, unlike traditional Unix shell globbing. For example, `"data/*.json"`
will match both `data/file.json` and `data/subdir/file.json`.
See https://docs.python.org/3/library/fnmatch.html for more details.
Args:
items (`Iterable`):
List of items to filter.
allow_patterns (`str` or `list[str]`, *optional*):
Patterns constituting the allowlist. If provided, item paths must match at
least one pattern from the allowlist.
ignore_patterns (`str` or `list[str]`, *optional*):
Patterns constituting the denylist. If provided, item paths must not match
any patterns from the denylist.
key (`Callable[[T], str]`, *optional*):
Single-argument function to extract a path from each item. If not provided,
the `items` must already be `str` or `Path`.
Returns:
Filtered list of objects, as a generator.
Raises:
:class:`ValueError`:
If `key` is not provided and items are not `str` or `Path`.
Example usage with paths:
```python
>>> # Filter only PDFs that are not hidden.
>>> list(filter_repo_objects(
... ["aaa.pdf", "bbb.jpg", ".ccc.pdf", ".ddd.png"],
... allow_patterns=["*.pdf"],
... ignore_patterns=[".*"],
... ))
["aaa.pdf"]
```
Example usage with objects:
```python
>>> list(filter_repo_objects(
... [
... CommitOperationAdd(path_or_fileobj="/tmp/aaa.pdf", path_in_repo="aaa.pdf")
... CommitOperationAdd(path_or_fileobj="/tmp/bbb.jpg", path_in_repo="bbb.jpg")
... CommitOperationAdd(path_or_fileobj="/tmp/.ccc.pdf", path_in_repo=".ccc.pdf")
... CommitOperationAdd(path_or_fileobj="/tmp/.ddd.png", path_in_repo=".ddd.png")
... ],
... allow_patterns=["*.pdf"],
... ignore_patterns=[".*"],
... key=lambda x: x.path_in_repo
... ))
[CommitOperationAdd(path_or_fileobj="/tmp/aaa.pdf", path_in_repo="aaa.pdf")]
```
"""
if isinstance(allow_patterns, str):
allow_patterns = [allow_patterns]
if isinstance(ignore_patterns, str):
ignore_patterns = [ignore_patterns]
if allow_patterns is not None:
allow_patterns = [_add_wildcard_to_directories(_normalize_separators(p)) for p in allow_patterns]
if ignore_patterns is not None:
ignore_patterns = [_add_wildcard_to_directories(_normalize_separators(p)) for p in ignore_patterns]
if key is None:
def _identity(item: T) -> str:
if isinstance(item, str):
return item
if isinstance(item, Path):
return str(item)
raise ValueError(f"Please provide `key` argument in `filter_repo_objects`: `{item}` is not a string.")
key = _identity # Items must be `str` or `Path`, otherwise raise ValueError
for item in items:
path = _normalize_separators(key(item))
# Skip if there's an allowlist and path doesn't match any
if allow_patterns is not None and not any(fnmatchcase(path, r) for r in allow_patterns):
continue
# Skip if there's a denylist and path matches any
if ignore_patterns is not None and any(fnmatchcase(path, r) for r in ignore_patterns):
continue
yield item
def _normalize_separators(value: str | Path) -> str:
# Repo paths always use `/` and `\` is not an fnmatch escape character, so treating backslashes as path separators
# (e.g. patterns built with `os.path.join` on Windows) is safe.
# `value` can be a `Path` if a custom `key` returns one; coerce to `str` first.
return str(value).replace("\\", "/")
def _add_wildcard_to_directories(pattern: str) -> str:
if pattern.endswith("/"):
return pattern + "*"
return pattern
|