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

Yolo is not able to load pre-trained weights file #234

Open
alexander-hamme opened this issue Apr 10, 2018 · 6 comments
Open

Yolo is not able to load pre-trained weights file #234

alexander-hamme opened this issue Apr 10, 2018 · 6 comments

Comments

@alexander-hamme
Copy link

alexander-hamme commented Apr 10, 2018

Hello, I'm trying to train yolo on my own dataset for tadpole detection, but it can't seem to load the weights that I specify in the config.json file.

I tried using the "Full Yolo" architecture paired with the full_yolo_backend.h5 file, and now also tried "Tiny Yolo" with the tiny_yolo_backend.h5 file, neither worked.

The error I get is always some variation of:

ValueError: You are trying to load a weight file containing 16 layers into a model with 2 layers.


('Loading pre-trained weights in', u'/home/ah2166/Documents/sproj/keras-yolo2/tiny_yolo_backend.h5')

Traceback (most recent call last):
  File "train.py", line 104, in <module>
    _main_(args)
  File "train.py", line 81, in _main_
    yolo.load_weights(config['train']['pretrained_weights'])
  File "/home/ah2166/Documents/sproj/keras-yolo2/frontend.py", line 243, in load_weights
    self.model.load_weights(weight_path)
  File "/home/ah2166/.virtualenvs/opencv/local/lib/python2.7/site-packages/keras/engine/topology.py", line 2656, in load_weights
    f, self.layers, reshape=reshape)
  File "/home/ah2166/.virtualenvs/opencv/local/lib/python2.7/site-packages/keras/engine/topology.py", line 3354, in load_weights_from_hdf5_group
    str(len(filtered_layers)) + ' layers.')

ValueError: You are trying to load a weight file containing 16 layers into a model with 2 layers.

The weights file is in the keras-yolo2 root directory. This is my config.json:

{
    "model" : {
        "backend":              "Tiny Yolo",
        "input_size":           416,
        "anchors":              [1.01,1.08, 5.88,6.20, 7.65,9.83, 9.43,7.18, 10.47,10.08],
        "max_box_per_image":    10,
        "labels":               ["tadpole"]
    },

    "train": {
        "train_image_folder":   "/home/ah2166/Documents/sproj/tadpole_dataset/images/",
        "train_annot_folder":   "/home/ah2166/Documents/sproj/tadpole_dataset/annots/",

        "train_times":          20,
        "pretrained_weights":   "/home/ah2166/Documents/sproj/keras-yolo2/tiny_yolo_backend.h5",
        "batch_size":           8,
        "learning_rate":        1e-4,
        "nb_epochs":            30,
        "warmup_epochs":        3,

        "object_scale":         5.0 ,
        "no_object_scale":      1.0,
        "coord_scale":          1.0,
        "class_scale":          1.0,

        "saved_weights_name":   "tiny_yolo_tadpole.h5",
        "debug":                true
    },

    "valid": {
        "valid_image_folder":   "",
        "valid_annot_folder":   "",

        "valid_times":          1
    }
}

Any advice on how I might resolve this and get it to load the weights file? Thanks!

@RichardSieg
Copy link

Hey,

so there's a difference in the models used and the pretrained weights.

On the one hand, you have the weights for the backend that is used (e.g. full yolo or tiny yolo). The path to their weight file is hard coded into backend.py. In order to load these weights you need to download them (read the README) and put them into your yolo folder, so the backend script can find it.

On the other hand, you have weights for the whole model used, i.e., the backend plus some additional conv layers for the box detection (the backend is a classifier). In your config, you can specify a path to weights for that whole model. This is useful if you did some epochs of warmup training and want to load the weights from this warmup training as a start for your proper training.

@alexander-hamme
Copy link
Author

alexander-hamme commented Apr 10, 2018

As far as I can tell, what I currently have in the yolo root folder for backend.py to find are the backend files, which I downloaded from the link in the README.

So are you suggesting that I download the full weights files, instead of just the backend weights?

If so, I'm assuming I should get the weights from this link in the README, which is the link right after this:

The link to the pretrained weights for the whole model (both frontend and backend) of the raccoon detector can be downloaded at:

Because I was under the impression that these would already be trained for Raccoons, but I guess if they're going to be retrained for my dataset anyway that would make sense, this is transfer learning after all.

@RichardSieg
Copy link

Well it depends on what you would like to train. If it looks similar to raccoons (and has only a single label!) you might can use these weights. Otherwise I would suggest you just leave this field blank or you do some epochs of warmup training, save the weights (with the saved_weights_name field) into some file like blabla_warm.h5 and load it (with the pretrained_weights field) for your proper training.

@alexander-hamme
Copy link
Author

alexander-hamme commented Apr 12, 2018

Thanks, doing that made it train successfully.

The issue now is that it doesn't detect anything, but I'm guessing that is either an indication that my dataset is not robust enough or I need to mess around with the network configurations...

@awesomeaku
Copy link

As far as I can tell, what I currently have in the yolo root folder for backend.py to find are the backend files, which I downloaded from the link in the README.

So are you suggesting that I download the full weights files, instead of just the backend weights?

If so, I'm assuming I should get the weights from this link in the README, which is the link right after this:

The link to the pretrained weights for the whole model (both frontend and backend) of the raccoon detector can be downloaded at:

Because I was under the impression that these would already be trained for Raccoons, but I guess if they're going to be retrained for my dataset anyway that would make sense, this is transfer learning after all.

can anyone please share the frontend and backend pretained weights as it is not available now in the link mentioned above

@rodrigo2019
Copy link

https://github.com/rodrigo2019/keras_yolo2/releases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants