zudi-lin / pytorch_connectomics

PyTorch Connectomics: segmentation toolbox for EM connectomics
http://connectomics.readthedocs.io/
MIT License
169 stars 77 forks source link

Bug: AttributeError when valid_mask is None #126

Closed chenhang98 closed 1 year ago

chenhang98 commented 1 year ago

When valid_mask=None in VolumeDataset, the following code will throw AttributeError: 'NoneType' object has no attribute 'copy'.

https://github.com/zudi-lin/pytorch_connectomics/blob/fc4dff992702947854ce7c9fd549be1e2cb3711e/connectomics/data/utils/data_weight.py#L23

The following safer codes are suggested.

  if mask is None:
      out[wid] = weight_binary_ratio(target.copy(), None, dilate)
  else:
      out[wid] = weight_binary_ratio(target.copy(), mask.copy(), dilate)
zudi-lin commented 1 year ago

Hi @tinyalpha, thanks for the bug report. Are you interested to submit a PR? My suggestion is to use

out[wid] = weight_binary_ratio(target.copy(), None if mask is None else mask.copy(), dilate)
chenhang98 commented 1 year ago

Hi @zudi-lin, I have created a PR.