Skip to content

Receiving a TypeError when executing example.sh #14

Open

Description

@tjiagoM

I was trying to run the file example.sh. The first command runs fine, but it throws an exception on the second one:

$ python -m train --bmname=ENZYMES --assign-ratio=0.1 --hidden-dim=30 --output-dim=30 --cuda=1 --num-classes=6 --method=soft-assign

The output is as follows. Any idea what is going on? Given that I haven't changed anything, maybe the version of packages are different?

CUDA 1
Using node labels
Num training graphs:  540 ; Num validation graphs:  60
Number of graphs:  600
Number of edges:  37282
Max, avg, std of graph size:  125 , 32.46 , 14.87
Method: soft-assign
/location/diffpool/encoders.py:71: UserWarning: nn.init.xavier_uniform is now deprecated in favor of nn.init.xavier_uniform_.
  m.weight.data = init.xavier_uniform(m.weight.data, gain=nn.init.calculate_gain('relu'))
/location/diffpool/encoders.py:73: UserWarning: nn.init.constant is now deprecated in favor of nn.init.constant_.
  m.bias.data = init.constant(m.bias.data, 0.0)
/location/diffpool/encoders.py:293: UserWarning: nn.init.xavier_uniform is now deprecated in favor of nn.init.xavier_uniform_.
  m.weight.data = init.xavier_uniform(m.weight.data, gain=nn.init.calculate_gain('relu'))
/location/diffpool/encoders.py:295: UserWarning: nn.init.constant is now deprecated in favor of nn.init.constant_.
  m.bias.data = init.constant(m.bias.data, 0.0)
Epoch:  0
/location/miniconda/envs/pytorch/lib/python3.6/site-packages/torch/nn/_reduction.py:49: UserWarning: size_average and reduce args will be deprecated, please use reduction='mean' instead.
  warnings.warn(warning.format(ret))
/location/diffpool/train.py:209: UserWarning: torch.nn.utils.clip_grad_norm is now deprecated in favor of torch.nn.utils.clip_grad_norm_.
  nn.utils.clip_grad_norm(model.parameters(), args.clip)
Traceback (most recent call last):
  File "/location/miniconda/envs/pytorch/lib/python3.6/site-packages/PIL/Image.py", line 2515, in fromarray
    mode, rawmode = _fromarray_typemap[typekey]
KeyError: ((1, 1, 1800), '|u1')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/location/miniconda/envs/pytorch/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/location/miniconda/envs/pytorch/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/location/diffpool/train.py", line 640, in <module>
    main()
  File "/location/diffpool/train.py", line 628, in main
    benchmark_task_val(prog_args, writer=writer)
  File "/location/diffpool/train.py", line 511, in benchmark_task_val
    writer=writer)
  File "/location/diffpool/train.py", line 218, in train
    log_assignment(model.assign_tensor, writer, epoch, writer_batch_idx)
  File "/location/diffpool/train.py", line 98, in log_assignment
    writer.add_image('assignment', data, epoch)
  File "/location/miniconda/envs/pytorch/lib/python3.6/site-packages/tensorboardX/writer.py", line 427, in add_image
    image(tag, img_tensor, dataformats=dataformats), global_step, walltime)
  File "/location/miniconda/envs/pytorch/lib/python3.6/site-packages/tensorboardX/summary.py", line 216, in image
    image = make_image(tensor, rescale=rescale)
  File "/location/miniconda/envs/pytorch/lib/python3.6/site-packages/tensorboardX/summary.py", line 254, in make_image
    image = Image.fromarray(tensor)
  File "/location/miniconda/envs/pytorch/lib/python3.6/site-packages/PIL/Image.py", line 2517, in fromarray
    raise TypeError("Cannot handle this data type")
TypeError: Cannot handle this data type

Activity

  1. chithangduong commented on Mar 29, 2019

    @chithangduong

    Try adding this before every writer.add_image()
    data = data.transpose(2,0,1)

    Or else, you can specify the image format based on this https://github.com/lanpa/tensorboardX/blob/master/tensorboardX/writer.py#L355

  2. RexYing commented on Apr 9, 2019

    @RexYing
    Owner

    I think the tensorboardX interface has changed due to updates.
    An alternative is to use the new function:
    img = tensorboardX.utils.figure_to_image(fig)

    It's more convenient than manually convert fig to data.

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