danieltan07 / learning-to-reweight-examples

PyTorch Implementation of the paper Learning to Reweight Examples for Robust Deep Learning
351 stars 60 forks source link

cannot assign 'torch.FloatTensor' as parameter 'weight' (torch.nn.Parameter or None expected) #21

Open LIYIJIANNN opened 2 years ago

LIYIJIANNN commented 2 years ago

![Uploading image.png…]() hello ! danieltan! when i transfer your minist image to my CWRU(1-dimension)data. I meet this problem. i rewrite the LENET model because for the feature encoder is different between image and 1d-data. and i don't use your metamodel class. when i calculate the grad for the first virtual updata . this bug happends. shoud i use your metamodel class? should i write a class of meteconv1d? i can't find the reason of this bug. expect you suggestion

LIYIJIANNN commented 2 years ago

c:\Users\29236\learning-to-reweight-examples\CWRU-L2R.ipynb Cell 21 in <cell line: 5>() 14 val_label = to_var(val_label,requires_grad=False) 17 for k in range(num_repeats): ---> 18 accuracy = train_lre() 20 if prop in accuracy_log: 21 accuracy_log[prop].append(accuracy)

c:\Users\29236\learning-to-reweight-examples\CWRU-L2R.ipynb Cell 21 in train_lre() 42 # Line 6 perform a parameter update 43 grads = torch.autograd.grad(l_f_meta, (meta_net.params()), create_graph=True,allow_unused=True)#计算元模型梯度,但梯度为零 ---> 44 meta_net.update_params(hyperparameters['lr'], source_params=grads)#更新元模型 46 # Line 8 - 10 2nd forward pass and getting the gradients with respect to epsilon 47 y_g_hat = meta_net(val_data)#计算验证集的输出

File c:\Users\29236\learning-to-reweight-examples\model.py:93, in MetaModule.update_params(self, lr_inner, first_order, source_params, detach) 91 grad = to_var(grad.detach().data) 92 tmp = param_t - lr_inner * grad ---> 93 self.set_param(self, name_t, tmp) 94 else: 96 for name, param in self.named_params(self):

File c:\Users\29236\learning-to-reweight-examples\model.py:114, in MetaModule.set_param(self, curr_mod, name, param) 112 for name, mod in curr_mod.named_children(): ... 1230 .format(torch.typename(value), name)) 1231 self.register_parameter(name, value) 1232 else:

TypeError: cannot assign 'torch.FloatTensor' as parameter 'weight' (torch.nn.Parameter or None expected)