Comments (3)
@7Vyshak7 hello! π
To use only the classification part of your second YOLOv5 model (model2
) on the crops detected by model1
, you can indeed extract the classification layer from model2
and apply it to the regions of interest (ROIs) detected by model1
. Here's a simplified approach:
-
Detect objects with
model1
:- Continue using
model1
as you have in your script to detect objects and obtain bounding boxes.
- Continue using
-
Crop and classify using
model2
:- For each bounding box from
model1
, crop the image. - Use
model2
to classify these cropped images. Ensure thatmodel2
is set up or modified to function purely as a classifier (you might need to adjust the model architecture slightly for this).
- For each bounding box from
Here's a basic snippet to guide you:
# Assuming model2 is modified to act as a classifier
for box in results.xyxy[0]:
x1, y1, x2, y2 = int(box[0]), int(box[1]), int(box[2]), int(box[3])
crop_img = img[y1:y2, x1:x2]
# Classify using model2
class_results = model2(crop_img)
# Process class_results as needed
Note: You'll need to ensure that model2
is appropriately modified to handle the input size and format of the crops, and that it outputs class predictions.
If you need further customization on the model architecture or additional help, feel free to ask!
from ultralytics.
Thanks @glenn-jocher for the reply, What you said,'Ensure that model2 is set up or modified to function purely as a classifier',
is the only thing I want, the modification of model2's architecture..! Can you help on achieving that customization on the model architecture?
from ultralytics.
Hello @7Vyshak7,
Absolutely, I'd be glad to help guide you through customizing model2
to function purely as a classifier. Hereβs a general approach:
- Load the Model: Continue loading
model2
as you currently do. - Modify the Architecture: You'll need to adjust the model to accept the cropped image dimensions and focus on the classification layers. This typically involves removing or adapting the final layers responsible for bounding box predictions.
Here's a conceptual example using PyTorch, assuming model2
is a YOLOv5 model:
import torch
# Load your model
model = torch.hub.load("ultralytics/yolov5", "custom", path="path_to_model2.pt")
# Assuming you want to use the output from one of the middle layers
class_only_model = torch.nn.Sequential(
*list(model.model.children())[:-1], # Remove the last layer
torch.nn.Flatten(), # Flatten the output
torch.nn.Linear(flatten_size, num_classes), # Add a new classification layer
torch.nn.Softmax(dim=1) # Softmax activation
)
Note: You'll need to adjust flatten_size
and num_classes
based on your specific model and number of classes.
-
Adjust Input Size: Ensure that the input size of the crops matches the input size expected by
model2
. -
Test the Classifier: Before deploying, make sure to test the modified model on a few samples to verify that it classifies correctly.
If you need more specific guidance based on your model's details or further assistance, feel free to share more about your model's current architecture or any particular challenges you're facing!
from ultralytics.
Related Issues (20)
- Error Code 2: Internal Error (Assertion cublasStatus == CUBLAS_STATUS_SUCCESS failed. ) HOT 4
- Yolov10 Can't get attribute 'SCDown' on <module 'ultralytics.nn.modules.block' from 'C:\\Users\\ZHANG\\miniconda3\\lib\\site-packages\\ultralytics\\nn\\modules\\block.py'> HOT 20
- yolov8 -- After the cache is turned on, the memory occupied by reading val data is too large HOT 5
- YOLOv10 Performance Issue: Version 3.12 Fast, But 3.11 and Below Very Slow HOT 8
- yolo8 onnx in opencv HOT 2
- Is OBB available for yolov9 and v10 ? HOT 1
- Clamping in bbox2dist HOT 1
- Question about code of position embedding in rt-detr HOT 5
- Process group init fails when training YOLOv8 after successful tunning [Databricks] [single node GPU] HOT 4
- Train with single gpu HOT 3
- Yolo8-OnnxRuntime-CPP-Inference awful output HOT 6
- confusion matrix single HOT 2
- How to add the bounding box values to the labels text files during prediction with a trained YOLO-V8 instance segmentation model? HOT 4
- Class imabalance dataloader HOT 1
- Replace confidence score for forward pass for. yolov8. Default is 0.25 HOT 5
- The Yolov8 model is wrong in predicting probability HOT 9
- Superfluous line in Model HOT 2
- Re train yolov8n.pt to detect more objects from a custom dataset? HOT 12
- image 1/1 D:\yolov8\ultralytics-main\ultralytics\assets\bus.jpg: 640x480 (no detections), 510.2ms Speed: 15.5ms preprocess, 510.2ms inference, 18.0ms postprocess per image at shape (1, 3, 640, 480) HOT 4
- How to Shut Down Wandb HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ultralytics.