Open glenn-jocher opened 4 years ago
Hi @glenn-jocher I have a question: Suppose we train an object detection model separately on two completely separate datasets (datasets A and B) so that the classes are the same in both datasets (for example usask and avarlis in Wheat Head Detection). After training the same model on 2 datasets, we will have 2 different best.pt files. Question: How can we combine (or aggregate) these 2 model weights to have a single .pt file including the aggregated model weights?
Hi @mek651 this can be done straightfowardly by loading each model, getting the state_dict for each model (which is a sequence of arrays or tensors I believe), doing a straightforward average of the two state_dicts, then deep copying one the models and assigning the averaged state_dict and saving it. In yolo this is only going to make sense if the classes are exactly the same though. You might get better results by training one larger model on both datasets at the same time though.
Thanks @michael-mayo. Actually, my goal is to use Federated Learning. the simplest version I am working on is to apply FedAvg model on the output weights (2 or more best.pt). the classes of both datasets are exactly the same.
Do you have any idea about this?
Thanks for the relevant discussion, I am new to YOLOv5 and this platform. I wonder if there is a way to make ensemble training on two different datasets, with one frozen pre-trained model and one from scratch?
Hello,
I did not see the python implementation for detect tasks. Is it same as the predict task?
python detect.py --weights yolov5s.pt yolov5m.pt If not, how can I run the detect task using python implementation?
Thank you.
Regards, Bijay
@glenn-jocher I really need your help for one of my problems. I have a dataset trained on cat, dog and pen, and after training, I have got dataset1.pt best file Now, I trained another model with new data, for example I have taken just images of cow, and got dataset2.pt best file. Both of the trained model can detect the images separately. But I want to make them one model, so that it will detect all the images (cat, dog, pen and cow) using a single weight file. Can I do it using ensemble techniques? will this work?
python detect.py --weights dataset1.pt dataset2.pt --img 640 --source data/images/cat
or how can I do this, is there any way, rather than creating a new dataset will all the images, and trained again. Please reply, thanks
do you solve this?diffrent number of classes will get the error assert all(model[0].nc == m.nc for m in model), f"Models have different class counts: {[m.nc for m in model]}" AssertionError: Models have different class counts: [36, 80]
Actually in the ensembling technique I want to use the majority voting one the in this inference or test what type of aggregration is used and how can we use the majority voting python val.py --weights yolov5x.pt yolov5l6.pt --data coco.yaml --img 640 --half
what kind of specific resembling technique is used when we're doing the ensembling with this
python val.py --weights yolov5x.pt yolov5l6.pt --data coco.yaml --img 640 --half
📚 This guide explains how to use YOLOv5 🚀 model ensembling during testing and inference for improved mAP and Recall. UPDATED 25 September 2022.
From https://www.sciencedirect.com/topics/computer-science/ensemble-modeling:
Before You Start
Clone repo and install requirements.txt in a Python>=3.7.0 environment, including PyTorch>=1.7. Models and datasets download automatically from the latest YOLOv5 release.
Test Normally
Before ensembling we want to establish the baseline performance of a single model. This command tests YOLOv5x on COCO val2017 at image size 640 pixels.
yolov5x.pt
is the largest and most accurate model available. Other options areyolov5s.pt
,yolov5m.pt
andyolov5l.pt
, or you own checkpoint from training a custom dataset./weights/best.pt
. For details on all available models please see our README table.Output:
Ensemble Test
Multiple pretraind models may be ensembled togethor at test and inference time by simply appending extra models to the
--weights
argument in any existing val.py or detect.py command. This example tests an ensemble of 2 models togethor:Output:
Ensemble Inference
Append extra models to the
--weights
argument to run ensemble inference:Output:
Environments
YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
Status
If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on MacOS, Windows, and Ubuntu every 24 hours and on every commit.