Number of dims don't match in permute in birads.py

x = {
        "L-CC": torch.Tensor(datum_l_cc).permute(3, 1).to(device),
        "L-MLO": torch.Tensor(datum_l_mlo).permute(3, 1).to(device),
        "R-CC": torch.Tensor(datum_r_cc).permute(3, 1).to(device),
        "R-MLO": torch.Tensor(datum_r_mlo).permute(3, 1).to(device),
    }
    #print(x)
    transform = transforms.Compose([transforms.Resize(32),
                                      transforms.ToTensor(),
                                      transforms.Normalize(
                                          (.485, .456, .406), (.229, .224, .225))
                                      ])
    # run prediction:
    for (key,value) in x.items():
        print(key)
        torch_img=(x[key]).to(device)
        print(torch_img.size)
        features, prediction_birads = model(torch_img)
        print(prediction_birads)
        #prediction_birads = model(x).cpu().numpy()

File “birads.py”, line 96, in
inference(parameters_)
File “birads.py”, line 57, in inference
“L-CC”: torch.Tensor(datum_l_cc).permute(3, 1).to(device),
RuntimeError: number of dims don’t match in permute

Check the number of dimensions via:

datum_I_cc = torch.tensor(datum_l_cc)
print(datum_I_cc.shape)

and make sure permute uses all dimensions.

Based on the values you are passing I guess the tensor might have 4 dimensions.
If you want to swap dim3 with dim1, you could use .permute(0, 3, 2, 1).

1 Like

Using All dimensions solves this error.