znxlwm / pytorch-generative-model-collections

Collection of generative models in Pytorch version.
2.59k stars 546 forks source link

EBGAN.py give error raise TypeError('iteration over a 0-d tensor') TypeError: iteration over a 0-d tensor #10

Open pankajbadatia opened 6 years ago

pankajbadatia commented 6 years ago

if list(self.margin-D_fake_err.data)[0] > 0: D_loss = D_real_err + (self.margin - D_fake_err) else: D_loss = D_real_err self.train_hist['D_loss'].append(D_loss.data[0])

The error is in the above line no 190 .... Below Code worked for me .. am i Correct ? I removed word list and [0] if (self.margin-D_fake_err.data) > 0: D_loss = D_real_err + (self.margin - D_fake_err) else: D_loss = D_real_err self.train_hist['D_loss'].append(D_loss.data[0])

jmmcd commented 6 years ago

I think this is the same error I saw, due to an update in the pytorch API. The suggested change is to replace .data[0] with .data.item(). My pull request has this fix.