Closed ruifenggong closed 2 years ago
There is no error in my experiment. Can you show the error code? It might be because your 'lab' is already a long type, so it can't be cast as a long type. But it's actually not a big problem, as this line aims at converting label data to integer for loss computation. It's fine if you fix the error by doing so.
There is no error in my experiment. Can you show the error code? It might be because your 'lab' is already a long type, so it can't be cast as a long type. But it's actually not a big problem, as this line aims at converting label data to integer for loss computation. It's fine if you fix the error by doing so.
The log is here:
Traceback (most recent call last):
File "/home/xxx/CBIM-Medical-Image-Segmentation/train.py", line 248, in <module>
best_Dice, best_HD, best_ASD = train_net(net, args, ema_net, fold_idx=i)
File "/home/xxx/CBIM-Medical-Image-Segmentation/train.py", line 37, in train_net
trainset = get_dataset(args, mode='train', fold_idx=fold_idx)
File "/home/xxx/CBIM-Medical-Image-Segmentation/training/dataset/utils.py", line 20, in get_dataset
return CMRDataset(args, mode=mode)
File "/home/xxx/CBIM-Medical-Image-Segmentation/training/dataset/dim3/dataset_bileduck.py", line 57, in __init__
img, lab = self.preprocess(itk_img, itk_lab, img_name, lab_name)
File "/home/xxx/CBIM-Medical-Image-Segmentation/training/dataset/dim3/dataset_bileduck.py", line 125, in preprocess
tensor_lab = torch.from_numpy(lab)
TypeError: can't convert np.ndarray of type numpy.uint16. The only supported types are: float64, float32, float16, complex64, complex128, int64, int32, int16, int8, uint8, and bool.
The error code indicates that the data type of 'lab' is np.uint16. torch.from_numpy() doesn't support this data type. You can cast lab to uint8 first: lab = lab.astype(np.uint8)
This error depends on your data, but I'll add a data type check and cast to avoid this error. Thanks!
https://github.com/yhygao/CBIM-Medical-Image-Segmentation/blob/2f4408900378bf6600673bbe10dbcbf60d646e35/training/dataset/dim3/dataset_acdc.py#L112
In dataloading processing, error accurs in
tensor_lab = torch.from_numpy(lab).long()
,But it works when I add a line
lab = lab/1.0
before that.It is a bug here?