What's new with YOLOv8? #397
Replies: 6 comments 14 replies
-
@taliabender |
Beta Was this translation helpful? Give feedback.
-
Is it possible to clone YOLOv8 unto a desktop and run without "!pip install ultralytics" command? |
Beta Was this translation helpful? Give feedback.
-
Can we use pre-trained YOLOv8 classification model for Cross validation (KFold)? |
Beta Was this translation helpful? Give feedback.
-
Since I have images as a main folder say 'Infection' inside which I have my
train, test and validation folders. For each of these three folders there
are sub folders of my 4 classes which include their respective images. How
can I transform them into the form you have mentioned in the example code
as data and labels??
*Folder structure: *
*Infection -> Train -> GNC,GPC,GNB,GPB (4 classes)*
* Test -> GNC,GPC,GNB,GPB *
* Validation -.> GNC,GPC,GNB,GPB*
…On Fri, Jun 21, 2024 at 10:19 PM Paula Derrenger ***@***.***> wrote:
@shivam55sit <https://github.com/shivam55sit> absolutely! You can use
pre-trained YOLOv8 classification models for cross-validation, including
K-Fold cross-validation. This approach is beneficial for evaluating the
model's performance across different subsets of your dataset, ensuring
robustness and generalizability.
Here’s a concise example of how you might implement K-Fold
cross-validation with a YOLOv8 classification model using Python:
from sklearn.model_selection import KFoldfrom ultralytics import YOLOimport numpy as np
# Load your pre-trained YOLOv8 classification modelmodel = YOLO('yolov8n-cls.pt')
# Example datasetdata = np.array([...]) # Your datasetlabels = np.array([...]) # Corresponding labels
# K-Fold Cross-Validationkf = KFold(n_splits=5)for train_index, val_index in kf.split(data):
train_data, val_data = data[train_index], data[val_index]
train_labels, val_labels = labels[train_index], labels[val_index]
# Train the model on the training data
model.train(data={'train': train_data, 'val': val_data, 'labels': train_labels}, epochs=10)
# Validate the model on the validation data
results = model.val(data={'val': val_data, 'labels': val_labels})
print(f'Validation results: {results}')
Ensure you have the latest versions of torch and ultralytics installed to
avoid any compatibility issues. If you encounter any bugs, please provide a
minimum reproducible example as outlined in our documentation
<https://docs.ultralytics.com/help/minimum_reproducible_example> so we
can assist you effectively.
Feel free to reach out if you have any more questions or run into issues.
Happy coding! 😊
—
Reply to this email directly, view it on GitHub
<#397 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMS63IKML54VYTM4NQ4DEULZIRKQXAVCNFSM6AAAAAAT4PVTH6VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TQNBRHE4DK>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
This is great, thank you so much!
…On Sat, Jun 22, 2024 at 6:20 AM Glenn Jocher ***@***.***> wrote:
@shivam55sit <https://github.com/shivam55sit> hi Paula,
Thank you for your question! To transform your dataset into the format
required for YOLO, you'll need to organize your images and labels
accordingly. Here's a step-by-step guide to help you restructure your
dataset:
1. *Directory Structure*: YOLO expects a specific directory structure.
You should have separate folders for images and labels, with corresponding
filenames. Here’s how you can organize it:
Infection/
├── images/
│ ├── train/
│ │ ├── GNC/
│ │ ├── GPC/
│ │ ├── GNB/
│ │ ├── GPB/
│ ├── val/
│ │ ├── GNC/
│ │ ├── GPC/
│ │ ├── GNB/
│ │ ├── GPB/
│ ├── test/
│ ├── GNC/
│ ├── GPC/
│ ├── GNB/
│ ├── GPB/
├── labels/
│ ├── train/
│ ├── val/
│ ├── test/
2.
*Convert Class Folders to YOLO Format*: You need to move all images
from the class subfolders into the train, val, and test folders
directly, and create corresponding label files in the labels
directory. Each label file should have the same name as its corresponding
image file but with a .txt extension.
3.
*Generate Labels*: For each image, create a label file in YOLO format.
Each line in the label file should contain:
- Class ID (integer)
- Center x (normalized)
- Center y (normalized)
- Width (normalized)
- Height (normalized)
Here’s a Python script to help you convert your dataset:
import osimport shutilfrom pathlib import Path
# Define pathsbase_path = Path('Infection')image_dir = base_path / 'images'label_dir = base_path / 'labels'
# Create directoriesfor split in ['train', 'val', 'test']:
(image_dir / split).mkdir(parents=True, exist_ok=True)
(label_dir / split).mkdir(parents=True, exist_ok=True)
# Move images and create empty label filesfor split in ['train', 'val', 'test']:
for class_name in ['GNC', 'GPC', 'GNB', 'GPB']:
class_path = base_path / split / class_name
for image_file in class_path.glob('*'):
# Move image
dest_image_path = image_dir / split / image_file.name
shutil.move(str(image_file), str(dest_image_path))
# Create empty label file
label_file = label_dir / split / (image_file.stem + '.txt')
label_file.touch()
print("Dataset restructuring complete.")
4. *Update YAML File*: Create a data.yaml file to specify the paths to
your dataset splits and class names. Here’s an example:
train: Infection/images/trainval: Infection/images/valtest: Infection/images/test
names:
0: GNC
1: GPC
2: GNB
3: GPB
5. *Training with YOLO*: Now you can train your YOLO model using the
data.yaml file:
from ultralytics import YOLO
# Load the modelmodel = YOLO('yolov8n.pt')
# Train the modelmodel.train(data='path/to/data.yaml', epochs=100, imgsz=640)
If you encounter any issues, please ensure you have the latest versions of
torch and ultralytics installed. If the problem persists, provide a
minimum reproducible example as outlined in our documentation
<https://docs.ultralytics.com/help/minimum_reproducible_example> so we
can assist you effectively.
Feel free to reach out if you have any more questions. Happy coding! 😊
—
Reply to this email directly, view it on GitHub
<#397 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMS63ILSAPZOPHMJNELWWXDZITC4TAVCNFSM6AAAAAAT4PVTH6VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TQNBUGU4TK>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
The code for generating images and their respective labels does not
contains these values for the images :
- Class ID (integer)
- Center x (normalized)
- Center y (normalized)
- Width (normalized)
- Height (normalized)
Could you please specify in the code or suggest so that I generate these in
the labels.
On Sat, Jun 22, 2024 at 8:38 AM Shivam Prajapati <
***@***.***> wrote:
… This is great, thank you so much!
On Sat, Jun 22, 2024 at 6:20 AM Glenn Jocher ***@***.***>
wrote:
> @shivam55sit <https://github.com/shivam55sit> hi Paula,
>
> Thank you for your question! To transform your dataset into the format
> required for YOLO, you'll need to organize your images and labels
> accordingly. Here's a step-by-step guide to help you restructure your
> dataset:
>
> 1. *Directory Structure*: YOLO expects a specific directory
> structure. You should have separate folders for images and labels, with
> corresponding filenames. Here’s how you can organize it:
>
> Infection/
> ├── images/
> │ ├── train/
> │ │ ├── GNC/
> │ │ ├── GPC/
> │ │ ├── GNB/
> │ │ ├── GPB/
> │ ├── val/
> │ │ ├── GNC/
> │ │ ├── GPC/
> │ │ ├── GNB/
> │ │ ├── GPB/
> │ ├── test/
> │ ├── GNC/
> │ ├── GPC/
> │ ├── GNB/
> │ ├── GPB/
> ├── labels/
> │ ├── train/
> │ ├── val/
> │ ├── test/
>
>
> 2.
>
> *Convert Class Folders to YOLO Format*: You need to move all images
> from the class subfolders into the train, val, and test folders
> directly, and create corresponding label files in the labels
> directory. Each label file should have the same name as its corresponding
> image file but with a .txt extension.
> 3.
>
> *Generate Labels*: For each image, create a label file in YOLO
> format. Each line in the label file should contain:
> - Class ID (integer)
> - Center x (normalized)
> - Center y (normalized)
> - Width (normalized)
> - Height (normalized)
>
> Here’s a Python script to help you convert your dataset:
>
> import osimport shutilfrom pathlib import Path
> # Define pathsbase_path = Path('Infection')image_dir = base_path / 'images'label_dir = base_path / 'labels'
> # Create directoriesfor split in ['train', 'val', 'test']:
> (image_dir / split).mkdir(parents=True, exist_ok=True)
> (label_dir / split).mkdir(parents=True, exist_ok=True)
> # Move images and create empty label filesfor split in ['train', 'val', 'test']:
> for class_name in ['GNC', 'GPC', 'GNB', 'GPB']:
> class_path = base_path / split / class_name
> for image_file in class_path.glob('*'):
> # Move image
> dest_image_path = image_dir / split / image_file.name
> shutil.move(str(image_file), str(dest_image_path))
>
> # Create empty label file
> label_file = label_dir / split / (image_file.stem + '.txt')
> label_file.touch()
> print("Dataset restructuring complete.")
>
>
> 4. *Update YAML File*: Create a data.yaml file to specify the paths
> to your dataset splits and class names. Here’s an example:
>
> train: Infection/images/trainval: Infection/images/valtest: Infection/images/test
> names:
> 0: GNC
> 1: GPC
> 2: GNB
> 3: GPB
>
>
> 5. *Training with YOLO*: Now you can train your YOLO model using the
> data.yaml file:
>
> from ultralytics import YOLO
> # Load the modelmodel = YOLO('yolov8n.pt')
> # Train the modelmodel.train(data='path/to/data.yaml', epochs=100, imgsz=640)
>
> If you encounter any issues, please ensure you have the latest versions
> of torch and ultralytics installed. If the problem persists, provide a
> minimum reproducible example as outlined in our documentation
> <https://docs.ultralytics.com/help/minimum_reproducible_example> so we
> can assist you effectively.
>
> Feel free to reach out if you have any more questions. Happy coding! 😊
>
> —
> Reply to this email directly, view it on GitHub
> <#397 (reply in thread)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AMS63ILSAPZOPHMJNELWWXDZITC4TAVCNFSM6AAAAAAT4PVTH6VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TQNBUGU4TK>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***
> com>
>
|
Beta Was this translation helpful? Give feedback.
-
Welcome to the brand new Ultralytics YOLOv8 repo! After 2 years of continuous research and development, its our pleasure to bring you the latest installment of the YOLO family of architectures. Building on the success of countless experiments and previous architectures, we've created models that are the best in the world at what they do: real-time object detection, classification, and segmentation. 🚀
What can you expect with YOLOv8? ⭐️
☑️ Well-documented workflows, prioritizing clarity and thoroughness.
☑️ Spotless code, written from the ground up.
☑️ Simple usage of the easiest YOLO models ever to train and deploy.
☑️ Flexible solutions via support for all YOLO versions.
For more information check out our blog and YOLOv8 Youtube channel 🔥
Beta Was this translation helpful? Give feedback.
All reactions