akankshakshurai/cuda-error-resolution-analysis huggingface dataset:
How to use pre-trained model built using Pytorch?

Rohit_Dhamija: <p>I am using a simple perceptron based classifier to generate sentiment analysis in Pytorch, complete code here <a href="https://github.com/joosthub/PyTorchNLPBook/blob/master/chapters/chapter_3/3_5_Classifying_Yelp_Review_Sentiment.ipynb" rel="noopener nofollow ugc">Classifying Yelp Reviews</a>.</p>
<p>The example does sentiment analysis, it outputs if the given input string is positive or negative.</p>
<blockquote>
<p>example: this is a pretty small old great book → positive</p>
</blockquote>
<p>The application stores the final model along with the vectorizer.json.</p>
<p>So my question is: What should be the pre-requisites to build a separate application just to test the model, so that it can be used in web-application later-on?</p>
<p>Below is my current understanding and queries for this:</p>
<p>I assume to test, we need to load the model, load model parameters and evaluate for inference, please confirm</p>

user_123454321: <p>I think this <a href="https://pytorch.org/tutorials/recipes/recipes/saving_and_loading_models_for_inference.html" rel="noopener nofollow ugc">tutorial</a> is pretty straightforward in explaining how to load a pre-trained model for inference. You would need the ‘state-dict’ stored in the disc.</p>
Working on mask rcnn tutorial i get this error while training

thejas_karkera: <p>pos = np.where(masks[i])<br>
TypeError: ‘bool’ object is not subscriptable</p>

user_123454321: <p>This seems like masks is a bool object instead of 2d array. I tried <a href="https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html" rel="noopener nofollow ugc">tutorial</a>  on maskrcnn, which is what I believe you are trying too and I don’t get that error. Have you done any changes in the dataset class?</p>

thejas_karkera: <p>Thankyou for the reply! actually i was using a RGB mask instead of Binary mask, but my results are very poor, the mask values are all zero, when i checked.</p>
How to place permute function into the dataloader?

oguzeraysal: <p>Hello, i have dataloader and permute function given below. I need to get rid of this error :<br>
Given groups=1, weight of size [64, 1, 3, 3], expected input[1, 18, 368, 368] to have 1 channels, but got 18 channels instead<br>
For this reason i need to place permute function into the <strong>getitem</strong>  but when i try to place to into the <strong>getitem</strong> it didn’t work so can you help me ? What can I do ?</p>
<pre><code class="lang-auto">class CustomDataset(Dataset): 
  def __init__(self, image_paths, target_paths, transform, train=True): # initial logic happens like transform
      #self.image_paths = image_paths
      self.target_paths = target_paths 
      self.transforms = transforms.ToTensor()
      

  def __getitem__(self, index):
      #image = Image.open(self.image_paths[index])
      mask = np.load(self.target_paths[index])
      t_image = self.transforms(mask)
          
      return t_image
    
  def __len__(self): # return count of sample we have 
      
      return len(self.target_paths)
</code></pre>
<pre><code class="lang-auto">a=torch.randn(18, 1, 368, 368)
b=a.permute(1, 0, 2, 3)
print(a.shape)
print(b.shape)
</code></pre>

ptrblck: <p>Based on the input shape I assume you are using a <code>batch_size</code> of 1 and the input tensor has 18 channels.<br>
You could add the <code>permute</code> operation after loading the batch, but note that the channels would now be treated as separate samples since they are in the batch dimension.<br>
Also, the permutation would move the batch dimension to the channel dimension. Increasing the batch size would also increase the number of channels.<br>
Could you explain your use case a bit more, as this sounds rather wrong?</p>
CrossEntropyLoss() Error

Eyal: <p>Hello,<br>
I’ve been working on a semantic segmentation task in point clouds, with RandLA-Net.<br>
I’m trying to train the network on the DALES dataset, which is 8 labels semantic segmentation dataset, while doing so, I’ve got the following error:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/5/4/5420f206059eb9992cfd76a7bdbac53c7988c9ec.png" data-download-href="https://discuss.pytorch.org/uploads/default/5420f206059eb9992cfd76a7bdbac53c7988c9ec" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/5/4/5420f206059eb9992cfd76a7bdbac53c7988c9ec.png" alt="image" data-base62-sha1="c0eGWOPvZ3Fq7xyrVD8Zl26OQfG" width="690" height="102" data-dominant-color="451D1B"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1186×177 8.5 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>Now, when I searched online I found that it might be triggered due to the difference between the logarithm distributed scores shape, and the labels shape. when printing the shapes of them I’m getting the following:</p>
<p>code:</p>
<pre><code class="lang-auto"> scores = model(points)

 logp = torch.distributions.utils.probs_to_logits(scores, is_binary=False)
          
 print(logp.shape)

 print(labels.shape)
</code></pre>
<p>and the output is:</p>
<pre><code class="lang-auto">torch.Size([1, 8, 40960])
torch.Size([1, 40960])
</code></pre>
<p>I’ve been struggling to understand if the shapes are incorrect, and how to fix them, will appreciate any help.<br>
Thanks in advance.</p>

Eyal: <p>Anyone? Still struggling to solve this issue. Thanks</p>

ptrblck: <p>Could you rerun the script via:</p>
<pre><code class="lang-auto">CUDA_LAUNCH_BLOCKING=1 python setup.py args
</code></pre>
<p>and post the stack trace here?<br>
Alternatively, run the code on the CPU and post the complete stack trace.</p>
MNIST Normalization numbers

Priyank_Raj_Sharma: <p>HI Team,</p>
<p>Need help with normalization . I was looking at the MNISt example and found transforms.Normalize((0.1307), (0.3081).</p>
<p>I understand how normalization works. But I want to know how come we concluded (0.1307 and 0.3081<br>
Is there a better way of finding it.</p>

ptrblck: <p>These stats (<code>mean</code> and <code>std</code>) are calculated from the training dataset of <code>MNIST</code> offline and passed to <code>transforms.Normalize</code>.</p>
Install past version of pytorch nightly

dickson_neoh: <p>I cant seem to find a command to pip install previous pytorch nightly version. Anyone knows?</p>

ptrblck: <p>You could use <a href="https://pytorch.org/get-started/previous-versions/#linux-and-windows-1">these commands</a> e.g. for <code>1.6.0</code>:</p>
<pre><code class="lang-auto"># CUDA 10.2
pip install torch==1.6.0 torchvision==0.7.0

# CUDA 10.1
pip install torch==1.6.0+cu101 torchvision==0.7.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 9.2
pip install torch==1.6.0+cu92 torchvision==0.7.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html

# CPU only
pip install torch==1.6.0+cpu torchvision==0.7.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
</code></pre>