Questions tagged [state-dict]
15 questions
4
votes
1 answer
RuntimeError: Error(s) in loading state_dict for Generator: Missing key(s) in state_dict
I was trying to train a DCGAN model using MNIST datasets, but I can't load the gen.state_dict() after I finished training.
import torch
import torch.nn as nn
import torchvision.datasets as datasets
import torchvision.transforms as transforms
from…

Jacky Lin
- 57
- 1
- 6
2
votes
1 answer
UserWarning: positional arguments and argument "destination" are deprecated - Pytorch nn.modules.module.state_dict()
I am trying to manage the checkpoints of my Pytorch model through torch.save():
Pytorch 1.12.0 and Python 3.7
torch.save({
'epoch': epoch,
'model_state_dict': model.state_dict(),
'optimizer_state_dict':…

Francesco Di Salvo
- 21
- 2
2
votes
0 answers
How to find back the architecture of a pytorch model having only the weight dictionnary?
I wanted to use the multilingual-codesearch model but first the code doesn't work and outputs the following error which suggest that it cannot load with only weights:
from transformers import AutoTokenizer, AutoModel
tokenizer =…

AtonKamanda
- 21
- 3
1
vote
2 answers
Pytorch error loading state dict of model: Expected state_dict to be dict-like
I am trying to save and load a model, but there is always an error.
I save the model with:
torch.save(model.state_dict(),'01.Code/models/SNNNotEncoded.pth' )
and I try to load the model…

tridentifer
- 29
- 1
- 4
0
votes
0 answers
Pytorch model drop in performance after saving/loading
I'm finding that after I save and later load my pytorch model the performance decreases substantially on both train and test sets. I'm currently training my model on CIFAR10. Below is the code I run to save and then load the model.
Save:
if…

new2java
- 39
- 5
0
votes
1 answer
Transferring Tensorflow weights to an equivalent Pytorch model
I had an old implementation of Unet in Tensorflow that has been trained on custom data. I have saved the weights in .hdf5 file format. Now, I want to convert my codes to Pytorch and I already implemented an equivalent model in Pytorch. However, I…

farzaneh
- 11
- 4
0
votes
2 answers
mmdet - WARNING - The model and loaded state dict do not match exactly. unexpected key in source state_dict:
I'm currently trying to run a deep learning tool software that was previously created by someone else a few years ago. While trying to load a class called Evaluator which wraps all of the important mmdetection functions, I keep getting the following…

jjacob
- 1
- 2
0
votes
1 answer
RuntimeError: Error(s) in loading state_dict for DynamicUnet: Missing key(s) in state_dict: "layers.0.4.0.conv3.weight" | size mismatch for layers
Goal:
Pickled model and exported weights come from a separate training environment. Here, I aim to load the model and weights to run inference with new…

DanielBell99
- 896
- 5
- 25
- 57
0
votes
1 answer
Which is the difference between "model_zoo.load_url" and "state_dict"
model_urls = {
'resnet18': 'https://download.pytorch.org/models/resnet18-5c106cde.pth',
'resnet34': 'https://download.pytorch.org/models/resnet34-333f7ec4.pth',
'resnet50': 'https://download.pytorch.org/models/resnet50-19c8e357.pth',
…

Joey
- 13
- 3
0
votes
0 answers
Pytorch model.state_dict contains extra layers not present in initial epochs
I am using this repo as my reference.
After running till 78th epochs, I saved the model as in utils.py.
However, when perform the following code:
CHECKPOINT_GEN = "output/vanilla/checkpoints/gen-78.pth.tar"
gen = Generator(in_channels=3,…

jayant98
- 135
- 6
0
votes
0 answers
RuntimeError: Error(s) in loading state_dict for Generator3D: Unexpected key(s) in state_dict: "conv_resize_0.weight", "conv_resize_0.bias"
RuntimeError: Error(s) in loading state_dict for Generator3D:
Unexpected key(s) in state_dict: "conv_resize_0.weight", "conv_resize_0.bias", "bn_resize_0.weight", "bn_resize_0.bias", "bn_resize_0.running_mean", "bn_resize_0.running_var",…
0
votes
1 answer
About saving state_dict/checkpoint in a function(PyTorch)
I am trying to implement the following function to save the model_state checkpoints:
def train_epoch(self):
for epoch in tqdm.trange(self.epoch, self.max_epoch, desc='Train Epoch', ncols=100):
self.epoch = epoch # increments the epoch of…

banikr
- 63
- 1
- 9
0
votes
2 answers
RuntimeError: Error(s) in loading state_dict for DataParallel: Unexpected key(s) in state_dict: “module.scibert_layer.embeddings.position_ids”
I am getting the following error while trying to load a saved model checkpoint (.pth file).
RuntimeError: Error(s) in loading state_dict for DataParallel: Unexpected key(s) in state_dict: "module.scibert_layer.embeddings.position_ids"
I trained my…

PinkBanter
- 1,686
- 5
- 17
- 38
0
votes
1 answer
Save Pytorch model state_dict with datetime in filename
I've been trying to save the state_dict of a Pytorch model with
torch.save(agent.qnetwork_local.state_dict(), filename) where filename = datetime.now().strftime('%d-%m-%y-%H:%M_dqnweights.pth')
type(filename) returns str which shouldn't be a…

EdisonMaxwell
- 121
- 1
- 6
0
votes
0 answers
How to load multi-task model but only predict one of the tasks?
Here is the Model structure. I combined almost everything together to for the convenience of hyper-parameters tuning.
'''
class MultiTaskDNN(nn.Module):
def __init__(self, n_tasks,
input_dim=1024,
output_dim=1,
…

user7725010
- 90
- 8