elyha7 / yoloface

Yolov5 Face Detection
GNU General Public License v3.0
123 stars 36 forks source link

Train #6

Closed razvan-tanase closed 2 years ago

razvan-tanase commented 2 years ago

Hello,

Is there any support for training / fine-tune weights on personal datasets? Or I should use the train script from the deepcam repository? Thank you in advance.

elyha7 commented 2 years ago

Hey! This repo is designed for model inference purposes. You should use original repo for training you own model and than you can save it as pytorch state dict and inference with my interface.

razvan-tanase commented 2 years ago

Is there any way I can train a pretrained model like 'yolov5s-face.pt'? I would like to conduct an experiment to see if I can improve, even by a small amount, the inference results. I already tried on the original repo, with this command:

python train.py --data .\data\face_train.yaml --weights '.\yolov5s-face.pt'

but I get the following error:

Traceback (most recent call last): File "train.py", line 634, in main(opt) File "train.py", line 529, in main train(opt.hyp, opt, device, callbacks) File "train.py", line 120, in train ckpt = torch.load(weights, map_location='cpu') # load checkpoint to CPU to avoid CUDA memory leak File "C:\Users\rtanase\Anaconda3\lib\site-packages\torch\serialization.py", line 607, in load return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args) File "C:\Users\rtanase\Anaconda3\lib\site-packages\torch\serialization.py", line 882, in _load result = unpickler.load() File "C:\Users\rtanase\Anaconda3\lib\site-packages\torch\serialization.py", line 875, in find_class return super().find_class(mod_name, name) AttributeError: Can't get attribute 'StemBlock' on <module 'models.common' from 'C:\YOLOv5\yolov5\models\common.py'>

I also tried to use the train.py script from the deepcam/yolov5-face repo, but they have 0 guidance on this topic and I keep getting the following errors:

This when there is no label.cache file in the train directory: WARNING: Ignoring corrupted image and/or label C:\YOLOv5\datasets\ICC_set\train\images\0596_00000005.png: labels require 15 columns each Which I assume is because it expects a different format for the annotation files from the standard one from YOLO (yolov5pytorch) .

When there is a label.cache file in the train directory: Traceback (most recent call last): File "train.py", line 512, in train(hyp, opt, device, tb_writer, wandb) File "train.py", line 187, in train dataloader, dataset = create_dataloader(train_path, imgsz, batch_size, gs, opt, File "C:\YOLOv5\yolov5-face\utils\face_datasets.py", line 62, in create_dataloader dataset = LoadFaceImagesAndLabels(path, imgsz, batch_size, File "C:\YOLOv5\yolov5-face\utils\face_datasets.py", line 166, in init labels, shapes = zip(*cache.values()) ValueError: not enough values to unpack (expected 2, got 0)

And this is probably because it cannot extract something useful for what is expecting. Please, if you are kind, help me with this issues, or redirect me to someone or something that can resolve my problems. Thank you very much.

elyha7 commented 2 years ago

I tried deepcam-cn guide for training and it seems to work. 1) You have to download widerface dataset and combine it with annotations they provide https://drive.google.com/file/d/1tU_IjyOwGQfGNUvZGwWWM4SwxKp2PUQ8/view?usp=sharing should look like this изображение изображение 2) You need to go yolov5-face/data and run train2yolo.py and val2yolo.py with a path to dataset from p1. 3) You need to download one of their pretrained models. 4) You can start training with train.py with params, something like this:

python3 train.py --data data/widerface.yaml --cfg models/yolov5n.yaml --weights weights/yolov5n-face.pt

But all in all, i'm not sure you would get better results without adding extra data in dataset or some training tweaks.

razvan-tanase commented 2 years ago

Thank you for your response! Fortunately, I managed to start a training session too, but thanks for the detailed explanation. In order to improve the training results it is normal to add another set of data, which I was planning to do, but before doing so I wanted to test that the script works as they described. The only problem is that the label files along with the directory structure are different from the conventional ones used in the original yolov5 repo. What is most disturbing is that in the case of label files, there is no documentation on how they are constructed or what the values for each image mean, which prevents you from building a dataset for training yourself. If you have related information on this aspect, I would be very grateful if you could share it.