taipingeric / yolo-v4-tf.keras

A simple tf.keras implementation of YOLO v4
MIT License
141 stars 78 forks source link

Unable to access weights #8

Closed nrgrady closed 3 years ago

nrgrady commented 3 years ago

The code finished training on a set of custom data with custom classes, and had a print statement saying I should have weights in the "Y4.weights/assets" folder. While the folder was created, there is nothing there. In the Y4.weights folder there is a saved_model.pb and a variables folder with files in them, but no *.weights to be found.

The execution of the code is also littered with depreciation warnings. Is it possible to add some proper documentation to this repo that includes the intended versions of tensorflow and keras? I'm using 2.2 for both, but these warnings make me think I should be using older versions.

Most common warning is "arguments object has no attribute posonlyargs", and a change that makes layer updates automatic.


Edits: grammar, and more detail/context added

gajdosech2 commented 3 years ago

What code for training are you using exactly? If you just call model.fit as shown in https://github.com/taipingeric/yolo-v4-tf.keras/blob/master/notebook/train.ipynb than I believe that does not do any saving of the weights, it just recalls the fit method on the training_model itself (https://github.com/taipingeric/yolo-v4-tf.keras/blob/master/models.py#L100). Therefore I do not understand where did that print regarding weights in Y4.weights folder came from, I do not see that anywhere.

I personally just use the model.save_model method after training, which exports it to a folder that can be loaded with model.load_model when needed for inference, works for me.

Regarding the intended version of TF and Keras I am not sure. Author mentioned here he uses 2.2 and 2.3 https://github.com/taipingeric/yolo-v4-tf.keras/issues/3 . I personally use Keras 2,4,3 and TF 2.3.1. It works but I do get warning you mentioned too, but it works regardless. I might look into this more in future and figure out more / resolve those warnings in my fork...

nrgrady commented 3 years ago

I followed the notebook example from this repo, and the Y4.weights was the argument specified to model.save_model after the model has been trained.

Perhaps there is something wonky with the tf/keras install then.

gajdosech2 commented 3 years ago

Oh I see what you mean now, well I specify a different path as the argument, namely I call model.save_model('model') and when I look into the created folder model, the assets subdirectory is empty for me aswell (did not look into it up until now, just treated the whole folder model as a serialized version of the network and did not dig in its content). Therefore when I want to infer using the trained network I call model.load_model('model') on an instance of Yolov4 and it loads and works just fine, so maybe it will work for you too? I suppose the trained parameters are inside variables/variables.data-00000-of-00001 (almost 250mb file in my case). You can see my inference script here: https://github.com/gajdosech2/yolo-v4-tf.keras/blob/master/inference.py. Hope it makes sense and will help you.

nrgrady commented 3 years ago

That did it! I've used a few Yolov3's that produced their own .weights files upon training, and made the bad assumption this one would to. I suppose this is a good way of preventing someone from overwriting the source weights on accident. Thank you for your help.