ultralytics / yolov3

YOLOv3 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
10.2k stars 3.45k forks source link

Target classes exceed model classes #678

Closed daddydrac closed 4 years ago

daddydrac commented 4 years ago

Created custom files for training: (4 + 1 + 13) * 3 = 54 13 classes, 54 filters

.names has 13 names in it .cfg was converted properly w 13 for classes, 54 for filters in all 3 yolo blocks

yolov3/utils/utils.py", line 451, in build_targets assert c.max() <= model.nc, 'Target classes exceed model classes' AssertionError: Target classes exceed model classes

daddydrac commented 4 years ago

Good to know ;)

On Tue, Feb 25, 2020 at 3:27 PM Glenn Jocher notifications@github.com wrote:

@joehoeller https://github.com/joehoeller cv2 loads images and videos. From https://docs.opencv.org/4.2.0/d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56

Currently, the following file formats are supported:

Windows bitmaps - .bmp, .dib (always supported) JPEG files - .jpeg, .jpg, .jpe (see the Note section) JPEG 2000 files - .jp2 (see the Note section) Portable Network Graphics - .png (see the Note section) WebP - .webp (see the Note section) Portable image format - .pbm, .pgm, .ppm .pxm, .pnm (always supported) PFM files - .pfm (see the Note section) Sun rasters - .sr, .ras (always supported) TIFF files - .tiff, .tif (see the Note section) OpenEXR Image files - .exr (see the Note section) Radiance HDR - .hdr, *.pic (always supported) Raster and Vector geospatial data supported by GDAL (see the Note section)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ultralytics/yolov3/issues/678?email_source=notifications&email_token=ABHVQHHHYSF3DDRF7X6OO3TREWELBA5CNFSM4JUOPTI2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEM5SCTA#issuecomment-591077708, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHVQHDZJ72QJBFGMI7M2UDREWELBANCNFSM4JUOPTIQ .

joel5638 commented 4 years ago

@joehoeller @glenn-jocher Im using @joehoeller 's thermal object detection repository. He mentioned 18 classes and ive added the n=18. so filters would be (18+1+4)x3 = 69 which is constant. but it doesnt seem to work.

Ive also tried 66 as filters. I'm lost and confused what is going wrong :(

daddydrac commented 4 years ago

Post the error from the command line

On Tue, Feb 25, 2020 at 9:48 PM Joel Prabhod notifications@github.com wrote:

@joehoeller https://github.com/joehoeller @glenn-jocher https://github.com/glenn-jocher Im using @joehoeller https://github.com/joehoeller 's thermal object detection repository. He mentioned 18 classes and ive added the n=18. so filters would be (18+1+4)x3 = 69 which is constant. but it doesnt seem to work.

Ive also tried 66 as filters. I'm lost and confused what is going wrong :(

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ultralytics/yolov3/issues/678?email_source=notifications&email_token=ABHVQHEGLAMEXRCP5FI3VITREXRAFA5CNFSM4JUOPTI2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEM6V5XA#issuecomment-591224540, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHVQHCSLG2JX53YT6MKTQLREXRAFANCNFSM4JUOPTIQ .

joel5638 commented 4 years ago

It is the same error.

RuntimeError: shape '[16, 3, 23, 13, 13]' is invalid for input of size 178464

  1. I have resized the .tiff image size to 160x120 and using them.
  2. Ive updated the classes as 18 and filters as 69 in yolov3-spp-r.cfg
  3. Ive also tried classes as 17 and filters as 66 in yolov3-spp-r.cfg

Nothing seems to work.

daddydrac commented 4 years ago

What does your name and data file look like?

On Tue, Feb 25, 2020 at 10:16 PM Joel Prabhod notifications@github.com wrote:

It is the same error.

RuntimeError: shape '[16, 3, 23, 13, 13]' is invalid for input of size 178464

  1. I have resized the .tiff image size to 160x120 and using them.
  2. Ive updated the classes as 18 and filters as 69 in yolov3-spp-r.cfg
  3. Ive also tried classes as 17 and filters as 66 in yolov3-spp-r.cfg

Nothing seems to work.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ultralytics/yolov3/issues/678?email_source=notifications&email_token=ABHVQHC6C55SKOH6A6HWS73REXULJA5CNFSM4JUOPTI2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEM6XJXQ#issuecomment-591230174, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHVQHFMFGEMO7DGT5PQX63REXULJANCNFSM4JUOPTIQ .

joel5638 commented 4 years ago

my custom.data looks like this : classes=18 train=./data/training_img_paths.txt valid=./data/training_img_paths.txt names=data/custom.names backup=backup/ eval=coco

my custom.names looks like this:

person bicycle car motorcycle airplane bus train truck boat traffic light fire hydrant stop sign parking meter bench bird cat dog horse

my training_img_paths.txt looks like this:

./coco/images/train/FLIR_00211.tiff ./coco/images/train/FLIR_06774.tiff ./coco/images/train/FLIR_00075.tiff ./coco/images/train/FLIR_00070.tiff ./coco/images/train/FLIR_03503.tiff ...... ...... ......

joel5638 commented 4 years ago

@joehoeller I just cloned your repository again and just added paths to the FLIR dataset with jpeg thermal images and the cfg you used for training.

I ran this command : python3 train.py --data data/custom.data --cfg cfg/yolov3-spp-r.cfg --weights weights/yolov3-spp.weights

when I Change the filters to 69 and classes to 18 in the cfg file. This is the error

Error : AssertionError: Model accepts 18 classes labeled from 0-17, however you labelled a class 18

But when I Change the filters to 66 and classes to 18 in the cfg file. This is the error.

Error : RuntimeError: shape '[16, 3, 23, 13, 13]' is invalid for input of size 178464

Looks like nothing seems to work out with the cfg file

daddydrac commented 4 years ago

Just for fun, try the stock spp cfg file, & see if it works: https://github.com/joehoeller/Object-Detection-on-Thermal-Images/blob/master/cfg/yolov3-spp.cfg

glenn-jocher commented 4 years ago

@joehoeller @joel5638 yes you can always use the default yolov3-spp.cfg (with no changes) to train custom datasets with up to 80 classes, like an 18 class dataset. It's not an optimal solution, but it works.

joel5638 commented 4 years ago

@joehoeller @glenn-jocher I just tried with stock cfgand i see the same result.

AssertionError: Model accepts 18 classes labeled from 0-17, however you labelled a class 18. See https://docs.ultralytics.com/yolov5/tutorials/train_custom_data

glenn-jocher commented 4 years ago

@joel5638 if your data is only labeled for classes between 0 and 17 it’s not possible to see that message. I thought you’d already fixed your labels?

joel5638 commented 4 years ago

@joehoeller @glenn-jocher Finally the training has started. I deleted all the 8000 images and their labels and only took 10 images with their labels and tried and it worked out. So, I'm assuming that the images in the train folder need their respective labels to train. Screenshot from 2020-02-27 10-59-44

glenn-jocher commented 4 years ago

Oh good!

The images used for training should not all need label files. We routinely take custom datasets and add COCO images sans labels for backgrounds. All that’s required is that the background images are listed in the *.txt file along with the rest of the (labeled) images.

joel5638 commented 4 years ago

Oh wow. Now I get the picture. Thank you so much @glenn-jocher and @joehoeller
You’ve been a great and great help in educating me. Love your passion. I’m grateful very much. Thank you both.

glenn-jocher commented 11 months ago

@joel5638 you're very welcome! It's a pleasure to assist. Our community is very helpful and supportive, and I'm sure they'll also be pleased to help you out. Keep up the good work!