Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load weights from URL

I have URL for weight file (.h5) of a CNN model. I want to load that weight directly to Python file and compile a keras model. How can this be done.?

Is there a direct approach or should I download the weight file and load it from disk.?

like image 485
Sreeram TP Avatar asked Dec 03 '25 07:12

Sreeram TP


1 Answers

There is a function to download weights from URL and stock it in ~/.keras/

It's the function get_file

from keras.utils.data_utils import get_file

Example :

from keras.utils.data_utils import get_file
weights_path = get_file(
            'the name under the model will be saved',
            'YOUR URL')
model.load_weights(weights_path)

It returns the path where the weights have been saved. Then you can use load_weight. But in all the case, the weights will be saved on your computer.

like image 191
Pusheen_the_dev Avatar answered Dec 07 '25 01:12

Pusheen_the_dev