xh-liu/CC-FPSE

Bug fix for `models/pix2pix_model.py`

justin-hpcnt opened this issue · 1 comments

When running ./test_coco.sh, below error occurs.

Traceback (most recent call last):
  File "test.py", line 41, in <module>
    generated = model(data_i, mode='inference')
  File "/home/justin/.virtualenvs/spade/lib/python3.6/site-packages/torch/nn/modules/module.py", line 541, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/justin/project/CC-FPSE/models/pix2pix_model.py", line 35, in forward
    input_semantics, real_image = self.preprocess_input(data)
  File "/home/justin/project/CC-FPSE/models/pix2pix_model.py", line 120, in preprocess_input
    instance_edge_map = self.get_edges(inst_map)
  File "/home/justin/project/CC-FPSE/models/pix2pix_model.py", line 217, in get_edges
    edge[:, :, :, 1:] = edge[:, :, :, 1:] | (t[:, :, :, 1:] != t[:, :, :, :-1])
RuntimeError: Expected object of scalar type Byte but got scalar type Bool for argument #2 'other' in call to _th_or

It can be simply resolved by changing edge = self.ByteTensor(t.size()).zero_() to edge = self.ByteTensor(t.size()).zero_().bool() at https://github.com/xh-liu/CC-FPSE/blob/master/models/pix2pix_model.py#L216

Thanks for pointing out! I found that this might be a problem for PyTorch versions higher than 1.2.0. For PyTorch versions 1.1.0 and lower, the logical operations return ByteTensor. After 1.2.0, BoolTensor is introduced so the logical operations return BoolTensor. In short, use ByteTensor for Pytorch 1.1.0 and lower, and BoolTensor for PyTorch higher than 1.2.0.