Skip to main content

Redirect Ultralytics disk cache files into a local temporary cache root.

Project description

ultralytics-disk-cache-hook

Redirect ultralytics cache="disk" image caches away from the dataset directory and into a local cache root on the training node.

中文说明

Quick Start

from ultralytics_disk_cache_hook import enable
from ultralytics import YOLO

enable()

model = YOLO("yolov8n.pt")
model.train(data="coco128.yaml", cache="disk")

What It Does

When ultralytics runs with cache="disk", it writes *.npy cache files next to the original images by default.

This plugin monkey patches the internal dataset implementation and redirects those cache files into a local temporary cache root instead.

  • Only affects cache="disk"
  • Does not affect cache="ram" or disabled cache
  • Rewrites self.npy_files for detection, segmentation, pose, and other tasks built on BaseDataset
  • Rewrites *.npy paths inside ClassificationDataset.samples for classification tasks
  • Writes cache files into hash buckets instead of mirroring the original dataset directory tree

Cache Root

The cache root is derived from ULTRALYTICS_DISK_CACHE_TMPDIR when set, otherwise from tempfile.gettempdir(), with ultralytics-disk-cache appended to it.

Override it with an environment variable:

export ULTRALYTICS_DISK_CACHE_TMPDIR=/local_nvme/tmp

Example cache path:

/mnt/shared-storage/datasets/coco/images/train2017/000000000001.jpg
-> <cache-root>/d1/3f/d13f474cca61f46ba06ecba11c1b3046.npy

Version Support

This plugin monkey patches non-public ultralytics internals, so it only claims support for versions whose source layout has been checked.

The current code enforces the following validated range:

  • Minimum supported version: 8.4.0
  • Maximum validated version: 8.4.38
  • Allowed range: 8.4.0 <= ultralytics <= 8.4.38

If the installed version is outside that range, enable() raises UnsupportedUltralyticsVersionError.

Why:

  • v8.0.x still uses the old ultralytics/yolo/data/... layout
  • v8.1.x through v8.3.x do not match the internal hook points used by this patch
  • Starting from v8.4.0, the disk cache structure in BaseDataset and ClassificationDataset matches this plugin

This range is based on checked GitHub source files and release/tag history. As of 2026-04-17, the latest verified release I checked is v8.4.38.

Check the installed version with:

python -c "import ultralytics; print(ultralytics.__version__)"

Disk Space

This plugin does not currently validate whether the cache disk has enough free space.

When cache="disk" is enabled, the plugin prints a warning with the cache root and asks the user to manage disk space manually.

If the local cache disk fills up, the error will occur when *.npy files are actually being written.

References

Copyright

Copyright (c) xx025. All rights reserved.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ultralytics_disk_cache_hook-0.1.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ultralytics_disk_cache_hook-0.1.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file ultralytics_disk_cache_hook-0.1.1.tar.gz.

File metadata

File hashes

Hashes for ultralytics_disk_cache_hook-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1a7742e8ce09daedaba16f702c8f8d047eb0cd0cad49cf86c17a314c6b222370
MD5 40473c2ea48882c7b6e3fc2f6fd5e5ba
BLAKE2b-256 67b720a36e157013bc6ffbb5c4c61c57158435b75357a85f7cf48d270d0d1c9b

See more details on using hashes here.

Provenance

The following attestation bundles were made for ultralytics_disk_cache_hook-0.1.1.tar.gz:

Publisher: publish.yml on xx025/ultralytics-disk-cache-hook

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ultralytics_disk_cache_hook-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ultralytics_disk_cache_hook-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 512296572f131c31506343694f09408c78c68ac1f9f80848aa432df59a31c61e
MD5 070b8fce2fd1c1c4d94a0746015d60bf
BLAKE2b-256 38cbfb743e566fe022b0c1c38427d29550b36147f6f4af78aceb55a5c98fb084

See more details on using hashes here.

Provenance

The following attestation bundles were made for ultralytics_disk_cache_hook-0.1.1-py3-none-any.whl:

Publisher: publish.yml on xx025/ultralytics-disk-cache-hook

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page