Issue Summary: YOLOv8 Training Cache Problem #14113
Replies: 1 comment
-
@aeromista2a hi Louis, Thank you for providing such a detailed description of your issue and the steps you've taken so far. It sounds like you've been thorough in setting up your dataset and training script. Let's try to address the problem with the cache files not being utilized correctly. Steps to Troubleshoot
Example Code to Recreate Cache FilesHere's a modified version of your script to ensure cache files are created correctly: import os
from ultralytics import YOLO
# Define paths
base_path = 'C:/Users/Louis/Desktop/Bot/dataset'
image_dirs = {
'train': os.path.join(base_path, 'Images/train'),
'val': os.path.join(base_path, 'Images/val'),
'test': os.path.join(base_path, 'Images/test')
}
label_dirs = {
'train': os.path.join(base_path, 'Labels/train'),
'val': os.path.join(base_path, 'Labels/val'),
'test': os.path.join(base_path, 'Labels/test')
}
# Ensure annotations exist
def check_annotations(label_dirs):
for split, dir_path in label_dirs.items():
if not os.listdir(dir_path):
raise ValueError(f'No annotations found in {dir_path}')
check_annotations(label_dirs)
# Create cache files in the correct subdirectories
def create_cache_files(image_dirs, label_dirs):
for split, image_dir in image_dirs.items():
cache_file = os.path.join(image_dir, f'{split}.cache')
if not os.path.exists(cache_file):
with open(cache_file, 'w') as f:
f.write('')
label_dir = label_dirs[split]
cache_file = os.path.join(label_dir, f'{split}.cache')
if not os.path.exists(cache_file):
with open(cache_file, 'w') as f:
f.write('')
create_cache_files(image_dirs, label_dirs)
# Train YOLOv8 model
model = YOLO('yolov8s.pt')
model.train(data=os.path.join(base_path, 'dataset.yaml'), epochs=50, imgsz=640, batch=16, cache=True, name='poker_cards6') Additional ResourcesFor more detailed guidance on dataset formatting and troubleshooting, you can refer to the Ultralytics Dataset Formatting Guide and the Common Issues Guide. If the issue persists, please provide a minimum reproducible example as outlined here. This will help us diagnose the problem more effectively. I hope this helps! Please let us know if you have any further questions or if the issue persists. |
Beta Was this translation helpful? Give feedback.
-
Hello everyone,
I hope you're all doing well. My name is Louis, and I am a French men working on a custom pokercards detection project using YOLOv8. I am reaching out for assistance regarding an issue I am encountering with the cache files during the training process.
Problem:
I am facing issues with training a custom dataset using YOLOv8. Despite following the dataset formatting guidelines, the training process does not correctly utilize the cache files. The .cache files are created in the main directories (Images and Labels), but the model fails to use the cache files in the appropriate subdirectories (train, val, test). As a result, warnings about missing labels appear, and the training does not proceed as expected.
Steps Taken:
Verified that the dataset directory structure is correct.
Created a dataset.yaml file pointing to the correct paths for images and labels.
Ensured annotations exist in the respective directories.
Created cache files in the correct subdirectories.
Configured the training script to reference the correct paths.
Persistent Issue:
Despite these efforts, the YOLOv8 model still fails to recognize the cache files in the subdirectories, resulting in warnings and training issues.
Transferred 349/355 items from pretrained weights⚠️ No labels found in C:\Users\Louis\Desktop\Bot\dataset\Images\train.cache, training may not work correctly. See https://docs.ultralytics.com/datasets for dataset formatting guidance.⚠️ No labels found in C:\Users\Louis\Desktop\Bot\dataset\Images\val.cache, training may not work correctly. See https://docs.ultralytics.com/datasets for dataset formatting guidance.
Freezing layer 'model.22.dfl.conv.weight'
train: Scanning C:\Users\Louis\Desktop\Bot\dataset\Images\train.ca
WARNING
train: Caching images (0.1GB RAM): 100%|██████████| 74/74 [00:00<0
val: Scanning C:\Users\Louis\Desktop\Bot\dataset\Images\val.cache.
WARNING
val: Caching images (0.1GB RAM): 100%|██████████| 74/74 [00:00<00:
Plotting labels to runs\detect\poker_cards618\labels.jpg...
zero-size array to reduction operation maximum which has no identity
optimizer: 'optimizer=auto' found, ignoring 'lr0=0.01' and 'momentum=0.937' and determining best 'optimizer', 'lr0' and 'momentum' automatically...
optimizer: AdamW(lr=0.000476, momentum=0.9) with parameter groups 57 weight(decay=0.0), 64 weight(decay=0.0005), 63 bias(decay=0.0)
Image sizes 640 train, 640 val
Using 0 dataloader workers
Logging results to runs\detect\poker_cards618
Starting training for 50 epochs...
YOLOv8 Directory Structure
C:/Users/Louis/Desktop/Bot/
|-- dataset/
| |-- Images/
| | |-- train/
| | | |-- image_000001.jpg
| | | |-- image_000002.jpg
| | | |-- ...
| | |
-- train.cache | | |-- val/ | | | |-- image_000001.jpg | | | |-- image_000002.jpg | | | |-- ... | | |
-- val.cache| | |-- test/
| | |-- image_000001.jpg
| | |-- image_000002.jpg
| | |-- ...
| |
-- test.cache | |-- Labels/ | |-- train/ | | |-- image_000001.txt | | |-- image_000002.txt | | |-- ... | |
-- train.cache| |-- val/
| | |-- image_000001.txt
| | |-- image_000002.txt
| | |-- ...
| |
-- val.cache | |-- test/ | |-- image_000001.txt | |-- image_000002.txt | |-- ... |
-- test.cache|
|-- dataset.yaml
|-- train_yolov8.py
|-- requirements.txt
|-- venv/
|-- ...
Example dataset.yaml
path: C:/Users/Louis/Desktop/Bot/dataset
train:
images: Images/train
labels: Labels/train
val:
images: Images/val
labels: Labels/val
test:
images: Images/test
labels: Labels/test
nc: 137
names:
0: a_coeur
1: 2_coeur
...
136: tapis j1 table de 8
Example Python Script (train_yolov8.py)
import os
from ultralytics import YOLO
Define paths
base_path = 'C:/Users/Louis/Desktop/Bot/dataset'
image_dirs = {
'train': os.path.join(base_path, "Images/train"),
'val': os.path.join(base_path, "Images/val"),
'test': os.path.join(base_path, "Images/test")
}
label_dirs = {
'train': os.path.join(base_path, "Labels/train"),
'val': os.path.join(base_path, "Labels/val"),
'test': os.path.join(base_path, "Labels/test")
}
Ensure annotations exist
def check_annotations(label_dirs):
for split, dir_path in label_dirs.items():
if not os.listdir(dir_path):
raise ValueError(f"No annotations found in {dir_path}")
check_annotations(label_dirs)
Create cache files in the correct subdirectories
def create_cache_files(image_dirs, label_dirs):
for split, image_dir in image_dirs.items():
cache_file = os.path.join(image_dir, f'{split}.cache')
if not os.path.exists(cache_file):
with open(cache_file, 'w') as f:
f.write('')
create_cache_files(image_dirs, label_dirs)
Train YOLOv8 model
model = YOLO('yolov8s.pt')
model.train(data=os.path.join(base_path, 'dataset.yaml'), epochs=50, imgsz=640, batch=16, cache=True, name='poker_cards6')
PowerShell Command
Navigate to the project directory
cd C:\Users\Louis\Desktop\Bot
Activate the virtual environment
.\venv\Scripts\Activate.ps1
Install dependencies
pip install -r requirements.txt
Execute the training script
python -c "
import os
from ultralytics import YOLO
Define paths
base_path = 'C:/Users/Louis/Desktop/Bot/dataset'
image_dirs = {
'train': os.path.join(base_path, 'Images/train'),
'val': os.path.join(base_path, 'Images/val'),
'test': os.path.join(base_path, 'Images/test')
}
label_dirs = {
'train': os.path.join(base_path, 'Labels/train'),
'val': os.path.join(base_path, 'Labels/val'),
'test': os.path.join(base_path, 'Labels/test')
}
Ensure annotations exist
def check_annotations(label_dirs):
for split, dir_path in label_dirs.items():
if not os.listdir(dir_path):
raise ValueError(f'No annotations found in {dir_path}')
check_annotations(label_dirs)
Create cache files in the correct subdirectories
def create_cache_files(image_dirs, label_dirs):
for split, image_dir in image_dirs.items():
cache_file = os.path.join(image_dir, f'{split}.cache')
if not os.path.exists(cache_file):
with open(cache_file, 'w') as f:
f.write('')
create_cache_files(image_dirs, label_dirs)
Train YOLOv8 model
model = YOLO('yolov8s.pt')
model.train(data=os.path.join(base_path, 'dataset.yaml'), epochs=50, imgsz=640, batch=16, cache=True, name='poker_cards6')
"
Thank you all for taking the time to read through my issue and for any assistance you can provide. Your help is greatly appreciated, and I look forward to resolving this with your expert guidance.
Beta Was this translation helpful? Give feedback.
All reactions