BoyuanJiang / matching-networks-pytorch

Matching Networks for one shot learning
228 stars 67 forks source link

TypeError: iteration over a 0-d tensor #10

Open jack657166 opened 1 year ago

Rilliant7 commented 1 year ago

Have you solved this problem

handsomekerwin commented 1 year ago

You need to change code: line 133 def repackage_hidden(self,h): """Wraps hidden states in new Variables, to detach them from their history.""" if type(h) == Variable: return Variable(h.data) else: return tuple(self.repackage_hidden(v) for v in h) to def repackage_hidden(self, h): """Wraps hidden states in new Variables, to detach them from their history.""" if isinstance(h, torch.Tensor): return h.detach() else: return tuple(self.repackage_hidden(v) for v in h) and all acc.data[0], loss.data[0] should be changed to acc.item(),loss.item().

then you can run the code with newest pytorch.