Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need info regarding yolov3-tiny anchors, dataset creation and loss function. #2193

Closed
1 task done
useruser2023 opened this issue Feb 13, 2024 · 5 comments
Closed
1 task done
Labels
question Further information is requested Stale

Comments

@useruser2023
Copy link

useruser2023 commented Feb 13, 2024

Search before asking

Question

To deploy a custom YOLOv3-tiny model on a device, it must first be quantized using a custom engine to integer values. This requires the dataset and loss function that were used during training. Model was trained on two classes.

model = YOLO("custom_yolov3_tiny.pt")

input = torch.randn(1,3,320,320)
cls_head, det_head = model.model(input)

print(cls_head.shape)
print(det_head[0].shape, det_head[1].shape)

# torch.Size([1, 6, 500])

# (torch.Size([1, 66, 20, 20]), torch.Size([1, 66, 10, 10]))

I consulted your LoadImagesAndLabels data loader class located in utils/dataloaders.py. The output labels_out has a shape of (nl,6), from this how do we get above cls_head and det_head. What are the loss function used for yolov3-tiny training. What are the anchors and number of anchors used in the model? Please explain it in details.

Additional

from ultralytics import YOLO

# Load the model.
model = YOLO('yolov3-tinyu.pt')  # load a pre-trained model
 
# Training.
results = model.train(
   data=yaml.yaml',
   imgsz=320, 
   epochs=2,
   batch=32,
   ) # if you have multiple 

No response

@useruser2023 useruser2023 added the question Further information is requested label Feb 13, 2024
Copy link

👋 Hello @useruser2023, thank you for your interest in YOLOv3 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov3  # clone
cd yolov3
pip install -r requirements.txt  # install

Environments

YOLOv3 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

YOLOv3 CI

If this badge is green, all YOLOv3 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv3 training, validation, inference, export and benchmarks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

Introducing YOLOv8 🚀

We're excited to announce the launch of our latest state-of-the-art (SOTA) object detection model for 2023 - YOLOv8 🚀!

Designed to be fast, accurate, and easy to use, YOLOv8 is an ideal choice for a wide range of object detection, image segmentation and image classification tasks. With YOLOv8, you'll be able to quickly and accurately detect objects in real-time, streamline your workflows, and achieve new levels of accuracy in your projects.

Check out our YOLOv8 Docs for details and get started with:

pip install ultralytics

@glenn-jocher
Copy link
Member

@useruser2023 hello! Thanks for reaching out with your questions. Let's address them one by one:

  1. Anchors for YOLOv3-tiny: YOLOv3-tiny uses a total of 6 anchors, with 3 used for each of the two detection layers. These anchors are predefined in the configuration file and are based on common object sizes in the training dataset. You can also recalculate them for your specific dataset using the k-means clustering method on your dataset's bounding box dimensions.

  2. Dataset Creation: For creating a dataset, you should organize your images and annotations in a way that's compatible with the data loader. Annotations typically include class labels and bounding box coordinates. The Ultralytics Docs provide detailed instructions on how to format your dataset.

  3. Loss Function: YOLOv3-tiny uses a combination of loss functions, including:

    • Bounding Box Loss: For the coordinates of the predicted boxes (MSE loss or IoU-based loss).
    • Objectness Loss: For the confidence score that an object exists within the box (Binary Cross-Entropy loss).
    • Classification Loss: For the class predictions of the detected objects (Cross-Entropy loss).

The cls_head and det_head you're referring to are the outputs from the model's classification and detection heads, respectively. The cls_head output is typically used for class probability predictions, while det_head outputs are used for bounding box predictions.

For the labels_out shape of (nl, 6), this corresponds to the label information for each bounding box in the format [batch_index, class_label, x_center, y_center, width, height].

I hope this helps! If you need more detailed explanations or instructions, please refer to the Ultralytics Docs. Keep up the great work with your custom YOLOv3-tiny model! 😊🚀

@useruser2023
Copy link
Author

@glenn-jocher Thank you for the answer but I have a few more queries.

For the labels_out shape of (nl, 6), this corresponds to the label information for each bounding box in the format [batch_index, class_label, x_center, y_center, width, height].

  1. Like the labels_out info [batch_index, class_label, x_center, y_center, width, height] how are the classification and detection heads infos are organized for these tensors?
# torch.Size([1, 6, 500])
# (torch.Size([1, 66, 20, 20]), torch.Size([1, 66, 10, 10]))
  1. Prediction p in ComputeLoss , is p from classification head or detection head?
  2. Inside ComputeLoss model is accessing different attributes hyp, nc, nl , na . Except nc I cannot access any other attributes model.model.na AttributeError: 'DetectionModel' object has no attribute 'na'. Why is that?

Copy link

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label Mar 16, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 26, 2024
@glenn-jocher
Copy link
Member

@useruser2023 Great questions! Let's dive right in:

  1. Classification and Detection Heads Info: The output tensors of the classification and detection heads include various pieces of information essential for interpreting the predictions:

    • The first tensor (torch.Size([1, 6, 500])) could represent a specific feature map layer, depending on context (not typically YOLO output format). Usually, YOLOv3 outputs have the shape [batch_size, num_anchors * (5 + num_classes), grid_size, grid_size].
    • The two tuples (torch.Size([1, 66, 20, 20]) and torch.Size([1, 66, 10, 10])) likely represent detection layers with 66 channels each. These channels include information for bounding box coordinates, objectness scores, and class probabilities. The grid sizes (20x20 and 10x10) indicate the spatial resolution at which predictions are made.
  2. Prediction p in ComputeLoss: The p in ComputeLoss generally comes from the detection head, and it represents the predictions made by the model which include bounding box coordinates, objectness score, and class probabilities.

  3. Accessing Attributes like hyp, nc, nl, na: In YOLOv3, nc (number of classes), nl (number of layers), and na (number of anchors) are critical for defining the model's architecture and loss computation.

    • nc is accessible because it directly relates to the model's output dimensionality.
    • na (number of anchors per layer), nl (number of detection layers), and other hyperparameters like hyp are defined in the model configuration or training script rather than the model object itself. This is why attempting to access model.model.na might result in an AttributeError: these are not attributes of the model class but are parameters used during model configuration and loss computation.

For accessing such attributes, you'd typically refer to the model's configuration file or the training script where these values are defined and passed to the relevant functions.

I hope this clarifies your questions! Let me know if there's anything else you're curious about. 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

2 participants