PyTorch-Encoding
PyTorch-Encoding copied to clipboard
operands could not be broadcast together with shapes (8,256) (4,256,256)
hello,When I run,:python train.py --dataset pcontext --model deeplab --aux --backbone resnest200
I found the following error:
File "/dahuafs/userdata/229288/00_deeplearning/01_pytorch/segEncoding/experiments/segmentation/train.py", line 238, in validation
correct, labeled, inter, union = eval_batch(self.model, image, target)
File "/dahuafs/userdata/229288/00_deeplearning/01_pytorch/segEncoding/experiments/segmentation/train.py", line 229, in eval_batch
inter, union = utils.batch_intersection_union(pred.data, target, self.nclass)
File "/dahuafs/userdata/229288/00_deeplearning/anaconda3/envs/scseg/lib/python3.7/site-packages/torch_encoding-1.2.2b20201023-py3.7-linux-x86_64.egg/encoding/utils/metrics.py", line 122, in batch_intersection_union
predict = predict * (target > 0).astype(predict.dtype)
ValueError: operands could not be broadcast together with shapes (8,256) (4,256,256)
def eval_batch(model, image, target):
outputs = model(image)
outputs = gather(outputs, 0, dim=0)
pred = outputs[0]
target = target.cuda()
correct, labeled = utils.batch_pix_accuracy(pred.data, target)
inter, union = utils.batch_intersection_union(pred.data, target, self.nclass)
return correct, labeled, inter, union
Is there something wrong with this code?
Hello, I am also facing this problem with dataset ade20k
, backbone resnet50
and model encnet
.
Cell In[64], line 121, in Trainer.validation(self, epoch)
119 for i, (image, target) in enumerate(tbar):
120 with torch.no_grad():
--> 121 correct, labeled, inter, union = eval_batch(self.model, image, target)
123 total_correct += correct
124 total_label += labeled
Cell In[64], line 112, in Trainer.validation.<locals>.eval_batch(model, image, target)
110 print(f"target.shape = {target.shape}")
111 correct, labeled = batch_pix_accuracy(pred.data, target)
--> 112 inter, union = batch_intersection_union(pred.data, target, self.nclass)
113 return correct, labeled, inter, union
Cell In[59], line 104, in batch_intersection_union(output, target, nclass)
101 predict = predict.cpu().numpy().astype('int64') + 1
102 target = target.cpu().numpy().astype('int64') + 1
--> 104 predict = predict * (target > 0).astype(predict.dtype)
105 intersection = predict * (predict == target)
106 # areas of intersection and union
ValueError: operands could not be broadcast together with shapes (150,240) (16,240,240)
How to solve them?
This is a really old and unmaintained repo. Please use more recent projects, e.g. mmsegmentation