Skip to content

TypeError: Object of type 'Tensor' is not JSON serializable #258

Description

@yt605155624

Hello,I run your train.py with GPU and the newest pytorch >>> torch.version '0.4.0a0+5463a4a',THEN I have this problem ,I haven't use pytorch and visdom before ,so I don't know how to fix it ,Could you please help me with this problem?
Traceback (most recent call last):
File "/home/yt/anaconda3/lib/python3.6/site-packages/visdom/init.py", line 261, in _send
data=json.dumps(msg),
File "/home/yt/anaconda3/lib/python3.6/json/init.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/home/yt/anaconda3/lib/python3.6/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/home/yt/anaconda3/lib/python3.6/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/home/yt/anaconda3/lib/python3.6/json/encoder.py", line 180, in default
o.class.name)
TypeError: Object of type 'Tensor' is not JSON serializable
(epoch: 1, iters: 300, time: 0.278, data: 0.001) D_A: 0.164 G_A: 0.396 cycle_A: 1.978 idt_A: 1.903 D_B: 0.312 G_B: 0.730 cycle_B: 4.014 idt_B: 0.921
Exception in user code:
Traceback (most recent call last):
File "/home/yt/anaconda3/lib/python3.6/site-packages/visdom/init.py", line 261, in _send
data=json.dumps(msg),
File "/home/yt/anaconda3/lib/python3.6/json/init.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/home/yt/anaconda3/lib/python3.6/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/home/yt/anaconda3/lib/python3.6/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/home/yt/anaconda3/lib/python3.6/json/encoder.py", line 180, in default
o.class.name)
TypeError: Object of type 'Tensor' is not JSON serializable
Traceback (most recent call last):
File "train.py", line 35, in
visualizer.display_current_results(model.get_current_visuals(), epoch, save_result)
File "/media/yt/SearchforGraduationDesign/pytorch-CycleGAN-and-pix2pix/util/visualizer.py", line 53, in display_current_results
image_numpy = util.tensor2im(image)
File "/media/yt/SearchforGraduationDesign/pytorch-CycleGAN-and-pix2pix/util/util.py", line 30, in tensor2im
image_numpy = image_tensor[0].cpu().float().numpy()
RuntimeError: Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions