简体   繁体   中英

Training with pre-trained weights

I want to use a set of pre-trained weights to train my model for MNIST classification. More specifically, I train my model on one dataset. I want to use the final weights as the starting weights to train the model on a different dataset. To do this, I use

intial_weights = model1.get_weights()
model2 = create_model()
model2.set_weights(initial_weights)
model2.fit(x=x_train59,y=y_train59, epochs=20,callbacks = [cp_callback2])

My question is that whether model.fit() will ignore the initial weights set using model2.set_weights() or not. And if it does ignore, is there a way to make sure that model2.fit() uses the weights obtained previously. Also, is there a way to visualize the starting weights before model.fit() starts training. Thanks much in advance!

When you do model2.set_weights , you changed the weights of model2 . That's all.

You can see the weights the same way: w2 = model2.get_weights() . Then print w2 in a convenient way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM