akankshakshurai/cuda-error-resolution-analysis huggingface dataset:
How to setup a dataset for deeplabv3 training?

justin-larking-pk: <p>I’m attempting to train a custom deeplabv3 model, using custom data. I continually run into this error with my current setup for my training, dataset, loss etc script.</p>
<p>RuntimeError: stack expects each tensor to be equal size, but got [400, 640] at entry 0 and [400, 640, 3] at entry 17</p>
<p>It seems that my dataloader is trying to stack my masks and images together?</p>
<p>This is my dataset class:</p>
<pre><code class="lang-auto">class custom_data(torch.utils.data.Dataset):
    def __init__(self, dataset_dir, transforms=None):
        self.data_dir = dataset_dir
        self.num_classes = 1
        self.paths = os.listdir(dataset_dir+"/images")
        self.masks = os.listdir(dataset_dir+"/masks")

        self.transform = transforms

    def __len__(self):
        return len(self.paths)

    def __getitem__(self, idx):
        img_path = self.paths[idx]
        mask_path = self.masks[idx]
        img = cv2.imread(self.data_dir+"/images/"+img_path)
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        mask = cv2.imread(self.data_dir+"/masks/"+mask_path, cv2.IMREAD_UNCHANGED)
        
        mask = mask.astype(np.float32)

        if self.transform is not None:
            sample = self.transform(image=img, mask=mask)
        else:
            print("Error no transforms applied, tensor conversion is required!")     
        return sample["image"], sample["mask"]
</code></pre>
<p>I load my dataset, and split it into train and val. Then I produce a set of augmentations for train and val sets using albumnetations. I instantiate my dataloaders as follows:</p>
<pre><code class="lang-auto">dataloaders = {"train":torch.utils.data.DataLoader(train_dataset, batch_size=BATCH_SIZE, shuffle=True, drop_last=True, num_workers=10, pin_memory=True), 
                    "val":torch.utils.data.DataLoader(val_dataset, batch_size=BATCH_SIZE, shuffle=True, drop_last=True, num_workers=10, pin_memory=True)}
</code></pre>
<p>What could be causing this error? As far as I can tell my setup is very similar to ones I’ve found online i.e. <a href="https://github.com/albumentations-team/albumentations_examples/blob/master/notebooks/pytorch_semantic_segmentation.ipynb" class="inline-onebox" rel="noopener nofollow ugc">albumentations_examples/pytorch_semantic_segmentation.ipynb at master · albumentations-team/albumentations_examples · GitHub</a></p>

ptrblck: <p>Could you check if any <code>mask</code> has 3 channels by printing its shape in the <code>__getitem__</code>?</p>

justin-larking-pk: <p>Ah you are right, there was one mask that loaded as a 3 channel image instead of single channel. It was jpg not png like the others so I guess opencv just assumed it was colour.</p>
Variable no. of arguments in Custom Op Schema(TorchScript)

access2rohit: <p>I have been following this tutorial to implement Customer Op in C++: <a href="https://pytorch.org/tutorials/advanced/torch_script_custom_ops#codecell38" class="inline-onebox" rel="noopener nofollow ugc">Extending TorchScript with Custom C++ Operators — PyTorch Tutorials 1.12.0+cu102 documentation</a></p>
<p>What i wanted to know is that what should the schema look like for registering a custom Op that can take variable no. of arguments ?</p>
<p>Earlier (upto Pytorch1.9) the following types<br>
<code>myCustomOp (Tensor) -&gt; Tensor[]</code><br>
or<br>
<code>myCustomOp (std::string, Tensor) -&gt; Tensor[]</code><br>
or<br>
<code>myCustomOp (Tensor, Tensor) -&gt; Tensor[]</code></p>
<p>and so on could be registered by single schema</p>
<p><code>myCustomOp(...) -&gt; Tensor</code></p>
<p>but pytorch 1.10 onwards this is not possible.</p>
<p>Please let me know how should I update my code so I can accept arbitrary no. of arguments like before</p>
Aten::cat was not replaced with quantized::cat using FX

Wen_Xiao: <pre><code class="lang-auto">class Net(nn.Module):

    def __init__(self):
        super(Net, self).__init__()

    def forward(self, x0, x1, x2):
        y = torch.cat([x0, x1, x2], 3)
        return y


from torch.quantization import get_default_qconfig
from torch.quantization.quantize_fx import prepare_fx, convert_fx
fp32_input0 = torch.randn(1, 5, 5, 128)
fp32_input1 = torch.randn(1, 5, 5, 64)
fp32_input2 = torch.randn(1, 5, 5, 32)
model = Net()
model.eval()
y = model(fp32_input0, fp32_input1, fp32_input2)

qconfig = get_default_qconfig("qnnpack")
qconfig_dict = {"": qconfig}
model_prepared = prepare_fx(model, qconfig_dict)
model_int8 = convert_fx(model_prepared)
torch.jit.save(torch.jit.trace(model_int8, (fp32_input0, fp32_input1, fp32_input2)), "quantized_model.pt")
</code></pre>
<p>How to make quantized::cat appear in quantized network using FX?</p>

zhaoyang-star: <p>I have the same issue. Looking for someone’s help.</p>
Arm64 macOS _coreML and nn

Jianshu_Zhao: <p>Dear PyTorch team,</p>
<p>I am wondering the newest 1.12.1 for apple m1 devices, to_device(“cuda”) is not working but I say that the torch.backend properties has _coreML and nn specifically for apple neural engine. I am wonder when I want to use it on apple M1 pro/MAX gpu, what should I do.</p>
<p>Thanks,</p>
<p>Jianshu</p>
Using torch.nonzero on multidimensional tensor for faster GPU implementation

burning-man: <p>Hi,<br>
I am trying to get the indices of the non zero elements along a certain dimension in a multidimensional tensor. I tried Implementing torch.nonzero on sliced data along the required dimension and then iterating over the remaining tensor.</p>
<p>This takes quite a long time to execute. Is there a way to do an in-place non-zero index calculation?</p>