HUBDatasetStats
Class for generating HUB dataset JSON and -hub
dataset directory
Arguments path: Path to data.yaml or data.zip (with data.yaml inside data.zip) task: Dataset task. Options are 'detect', 'segment', 'pose', 'classify'. autodownload: Attempt to download dataset if not found locally
Usage from ultralytics.yolo.data.utils import HUBDatasetStats stats = HUBDatasetStats('/Users/glennjocher/Downloads/coco8.zip', task='detect') # detect dataset stats = HUBDatasetStats('/Users/glennjocher/Downloads/coco8-seg.zip', task='segment') # segment dataset stats = HUBDatasetStats('/Users/glennjocher/Downloads/coco8-pose.zip', task='pose') # pose dataset stats.get_json(save=False) stats.process_images()
Source code in ultralytics/yolo/data/utils.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 |
|
__init__(path='coco128.yaml', task='detect', autodownload=False)
Initialize class.
Source code in ultralytics/yolo/data/utils.py
get_json(save=False, verbose=False)
Return dataset JSON for Ultralytics HUB.
Source code in ultralytics/yolo/data/utils.py
process_images()
Compress images for Ultralytics HUB.
Source code in ultralytics/yolo/data/utils.py
img2label_paths
get_hash
Returns a single hash value of a list of paths (files or dirs).
Source code in ultralytics/yolo/data/utils.py
exif_size
verify_image_label
Verify one image-label pair.
Source code in ultralytics/yolo/data/utils.py
polygon2mask
Parameters:
Name | Type | Description | Default |
---|---|---|---|
imgsz |
tuple
|
The image size. |
required |
polygons |
np.ndarray
|
[N, M], N is the number of polygons, M is the number of points(Be divided by 2). |
required |
color |
int
|
color |
1
|
downsample_ratio |
int
|
downsample ratio |
1
|
Source code in ultralytics/yolo/data/utils.py
polygons2masks
Parameters:
Name | Type | Description | Default |
---|---|---|---|
imgsz |
tuple
|
The image size. |
required |
polygons |
list[np.ndarray]
|
each polygon is [N, M], N is number of polygons, M is number of points (M % 2 = 0) |
required |
color |
int
|
color |
required |
downsample_ratio |
int
|
downsample ratio |
1
|
Source code in ultralytics/yolo/data/utils.py
polygons2masks_overlap
Return a (640, 640) overlap mask.
Source code in ultralytics/yolo/data/utils.py
check_det_dataset
Download, check and/or unzip dataset if not found locally.
Source code in ultralytics/yolo/data/utils.py
check_cls_dataset
Check a classification dataset such as Imagenet.
This function takes a dataset
name as input and returns a dictionary containing information about the dataset.
If the dataset is not found, it attempts to download the dataset from the internet and save it locally.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset |
str
|
Name of the dataset. |
required |
split |
str
|
Dataset split, either 'val', 'test', or ''. Defaults to ''. |
''
|
Returns:
Name | Type | Description |
---|---|---|
data |
dict
|
A dictionary containing the following keys and values: 'train': Path object for the directory containing the training set of the dataset 'val': Path object for the directory containing the validation set of the dataset 'test': Path object for the directory containing the test set of the dataset 'nc': Number of classes in the dataset 'names': List of class names in the dataset |
Source code in ultralytics/yolo/data/utils.py
compress_one_image
Compresses a single image file to reduced size while preserving its aspect ratio and quality using either the Python Imaging Library (PIL) or OpenCV library. If the input image is smaller than the maximum dimension, it will not be resized.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
str
|
The path to the input image file. |
required |
f_new |
str
|
The path to the output image file. If not specified, the input file will be overwritten. |
None
|
max_dim |
int
|
The maximum dimension (width or height) of the output image. Default is 1920 pixels. |
1920
|
quality |
int
|
The image compression quality as a percentage. Default is 50%. |
50
|
Usage
from pathlib import Path from ultralytics.yolo.data.utils import compress_one_image for f in Path('/Users/glennjocher/Downloads/dataset').rglob('*.jpg'): compress_one_image(f)
Source code in ultralytics/yolo/data/utils.py
delete_dsstore
Deletes all ".DS_store" files under a specified directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The directory path where the ".DS_store" files should be deleted. |
required |
Usage
from ultralytics.yolo.data.utils import delete_dsstore delete_dsstore('/Users/glennjocher/Downloads/dataset')
Note
".DS_store" files are created by the Apple operating system and contain metadata about folders and files. They are hidden system files and can cause issues when transferring files between different operating systems.
Source code in ultralytics/yolo/data/utils.py
zip_directory
Zips a directory and saves the archive to the specified output path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dir |
str
|
The path to the directory to be zipped. |
required |
use_zipfile_library |
bool
|
Whether to use zipfile library or shutil for zipping. |
True
|
Usage
from ultralytics.yolo.data.utils import zip_directory zip_directory('/Users/glennjocher/Downloads/playground')
zip -r coco8-pose.zip coco8-pose
Source code in ultralytics/yolo/data/utils.py
Created 2023-04-16, Updated 2023-05-17
Authors: Glenn Jocher (3)