Save snapshots in a python list

I attempt to apply snapshot ensemble following this paper Snapshot Ensembles: Train 1, get M for free what I understand that I save model weights after each cycle. The one cycle contains many epochs. I want to save these weights at the end of each cycle into a list for further using them in test phase.
At beginning I defined snaphots = then @ end of each cycle append models weights to this list : snapshots.append(model.state_dict()). The problem that I found that all snapshot " weights" in the list are the same although they are different during the training

any recommendation to solve this problem?@ ptrblck

Hi,

The problem is that you are referring the same object. When you save it to the list instead of “snapshots.append(model.state_dict())”. Use the following command.

snapshots.append(model.state_dict().copy())

Then only, you can save the values at that point.

One small concern - when you ask question. Please do not mention a specific name. There are lots of people in the forum. Somebody will come and answer your question. If you mention a name, others may not answer.

Thanks

1 Like

thanks for your answer and advice