akankshakshurai/cuda-error-resolution-analysis huggingface dataset:
Repeating a tensor in intercalated form

username: Dhorka
cooked: <p>I have this tensor:</p>
<pre><code class="lang-auto">tensor([[425.0000, 625.0000],
        [550.0000, 566.6667],
        [700.0000, 600.0000]])
</code></pre>
<p>and I want to obtain something like this:</p>
<pre><code class="lang-auto">tensor([[425.0000, 425.0000, 625.0000, 625.0000],
        [550.0000, 550.0000, 566.6667, 566.6667],
        [700.0000, 700.0000, 600.0000, 600.0000]
</code></pre>
<p>Is there anyway to do this efficiently?</p>

username: ptrblck
cooked: <p>Maybe not the most elegant way, but this should work:</p>
<pre><code class="lang-python">x.unsqueeze(1).permute(0, 2, 1).repeat(1, 1, 2).view(3, 4)
</code></pre>

username: Dhorka
cooked: <p>Thanks!! I would like to ask what is the difference between reshape, view and why sometimes view needs to be followed by the contiguous() method.</p>

username: ptrblck
cooked: <p><code>.reshape</code> returns a view of the tensor it possible and a copy if necessary (<a href="https://pytorch.org/docs/stable/torch.html#torch.reshape" rel="nofollow noopener">docs</a>).<br>
Some operations need contiguous tensors to use e.g. the strides of the tensor internally.<br>
If your tensor is non-contiguous, you’ll get an error, to avoid wrong computations and other side effects.</p>
P value in Geometric and geometric_ have opposite meanings

username: kindlychung
cooked: <p>Here is a demo:</p>
<pre><code class="lang-auto">x = torch.ones(10).geometric_(.03)
print(x)
geo = Geometric(.03)
print(geo.sample([10]))
</code></pre>
<p>Result:</p>
<pre><code class="lang-auto">&gt;&gt;&gt; x = torch.ones(10).geometric_(.03)
&gt;&gt;&gt; print(x)
tensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])
&gt;&gt;&gt; geo = Geometric(.03)
&gt;&gt;&gt; print(geo.sample([10]))
tensor([  2.,  51.,  30.,   9.,  10.,  58.,  14.,  26., 108.,  75.])
</code></pre>
<p>Not a huge problem, but it’s counter-intuitive and inconsistent.</p>
Load a model in pytorch, previously saved in pytorch c++

username: ivan_rodriguez
cooked: <p>Hello,</p>
<p>I have a question regarding how to load a model in pytorch, previously saved in pytorch c++.</p>
<p>This is the model in C++:</p>
<p>struct Net : torch::nn::Module<br>
{<br>
Net(int inputSize, int hiddenSize, int numClasses):<br>
fc1(register_module(“fc1”, torch::nn::Linear(inputSize, hiddenSize))),<br>
fc2(register_module(“fc2”, torch::nn::Linear(hiddenSize, numClasses))) {};</p>
<pre><code>torch::nn::Linear fc1;
torch::nn::Linear fc2;


torch::Tensor forward(torch::Tensor input) 
{
    auto out = fc1(input);
    out = torch::relu(out);
    out = fc2(out);

    
    return out;    

}
</code></pre>
<p>};</p>
<p>and I saved it like this:</p>
<pre><code>std::string modelPath = "model.pt";
torch::serialize::OutputArchive outputArchive;
model.save(outputArchive);
outputArchive.save_to(modelPath);
</code></pre>
<p>On the Python side this is my model:</p>
<p>class NeuralNet(nn.Module):</p>
<pre><code>def __init__(self, input_size, hidden_size, num_classes):
    super(NeuralNet, self).__init__()
    self.fc1 = nn.Linear(input_size, hidden_size) 
    self.fc2 = nn.Linear(hidden_size, num_classes)  

def forward(self, x):
    out = self.fc1(x)
    out = nn.Relu(out)
    out = self.fc2(out)
    return out
</code></pre>
<p>but I don’t know how to create a model object from the “model.pt” file  …</p>
<p>Thanks for any help!</p>
<p>Best,</p>
<p>Ivan</p>
Gated matmul implementation

username: march1905
cooked: <p>I want to implement a gated matrix multiplication. In this version of the matrix multiplication, when the gate’s value is 0 it skips the matrix multiplication. So far I try to implement it in python but it throws Cuda out of memory when the dimensions are higher than 2:</p>
<pre><code class="lang-auto">import torch

x = torch.rand([70, 20, 1024])
g = torch.rand([70, 20, 96, 1, 1])
w = torch.rand([96, 128, 128])
g = g * w # cuda out of memory
g = g.view(70, 20, 1536, 1024)
res = (g@x.unsqueeze(-1)).squeeze(-1)
print(res.shape)
</code></pre>
<p>So I‌ try to implement my own version because the problem occurs due to broadcasting in g*weight0. I try to find matmul function implementation in C++. I found the C++ implementation <a href="https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/LinearAlgebra.cpp#L338" rel="noopener nofollow ugc">here</a> but I don’t know how to access <code>at::mm_out</code> function.</p>
<p><img src="https://discuss.pytorch.org/uploads/default/original/2X/c/c360db8cbd05849be98dd11f95842fbb0210411e.png" alt="image" data-base62-sha1="rSoCDFza1Uog6CEGixm9nOXcRsO" width="653" height="224"></p>

username: tom
cooked: <p>The equivalent of <code>mm_out</code> is <code>torch.mm(..., out=...)</code>.</p>
<p>So is  the following correct? You have</p>
<pre><code class="lang-auto">x = x.view(70, 20, 1, 1, 1024)
g = g.view(70, 20, 96, 1, 1)
w = w.view(1, 1, 96, 16, 1024)
</code></pre>
<p>and want to conceptually compute</p>
<pre><code class="lang-auto">(x*g*w).sum(-1)
</code></pre>
<p>In this case, you might take a look at how <code>F.bilinear</code> is implemented (in Linear.cpp) - using a for lover the <code>96</code> entries. This avoids instantiating a too-large tensor.<br>
One easy way to do something like this is to do</p>
<pre><code class="lang-auto">res = torch.empty(70, 20, 96, 16)
for i in range(96):
    res[:,:, i] = (x[:,:,0]*g[:,:,i]*w[:,:,i]).sum(-1)
</code></pre>
<p>Quite likely, the backward isn’t 100% efficient and you might use <code>matmul</code> instead of summing, but is should give you a reasonable performance.</p>
<p>For a small additional speedup, you can use <code>matmul</code>.</p>
<p>Viele Grüße</p>
<p>Thomas</p>

username: march1905
cooked: <p><a class="mention" href="/u/tom">@tom</a> Thanks for your reply and also the pytorch team for such an amazing community.</p>
<p>The <code>w</code> shape must be <code>[96, 128,128]</code> when multiply by <code>g</code>. So, I can’t reshape it to <code>[96, 16, 1024]</code>. You gave me a good pointer though.</p>

username: tom
cooked: <p>But what’s your expectation with that? From the shapes you describe, it should not make a difference to the multiplication. (You can, of course, rename the view if you need the original shape afterwards.)</p>
<p>Best regards</p>
<p>Thomas</p>
transforms.ColorJitter() vs transforms.ColorJitter.getparams()

username: Boazrciasn
cooked: <p>Hello,<br>
I am working on torchvision 0.3.0, and the following code produces error, requires a list.</p>
<p>(a) transforms.ColorJitter.get_params(brightness=32. / 255, contrast=0.5)</p>
<p>However, the following code is valid.</p>
<p>(b) transforms.ColorJitter(brightness=32. / 255, contrast=0.5)</p>
<p>Is there a particular reason behind this distinction?</p>
<p>Best<br>
Barış</p>

username: alex.veuthey
cooked: <p><code>.get_params()</code>, from the <a href="https://pytorch.org/docs/stable/_modules/torchvision/transforms/transforms.html#ColorJitter" rel="nofollow noopener">source code</a>, requires lower and upper bounds for each parameter (brightness, contrast, saturation and hue), as well as each parameter to be set, as they don’t have default values.</p>
<p>However, the <code>ColorJitter.__init__()</code> method accepts both <code>int</code> and <code>list</code>or <code>tuple</code> input arguments, which are then properly formatted with the private method <code>_check_input()</code>.</p>
<p>Why do you want to use <code>.get_params()</code> instead of the more convenient form <code>ColorJitter(...)</code> ?</p>

username: Boazrciasn
cooked: <p>Thank you for the fast response!<br>
I need to transform stereo single channel images, so I use it to feed parameters to transforms.functional ops. Well anyway, I will enter the boundaries manually but I think same input properties between get_params() and ColorJitter(…) would be nice <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>
<p>Best,<br>
Barış</p>

username: Boazrciasn
cooked: <p>Apparently there is no ColorJitter in functional transforms LOL:D I assumed that it would exist haha!</p>
Are small "for" loops efficient in GPU?

username: K_Jay
cooked: <p>I want to embed 10 columns of categorical features to different dim sizes, so I write a “for” loop to enumerate each column and feed to its Embedding layer (I initialized 10 Embedding layers).</p>
<p>Here is my question:<br>
For each iteration, I have to go through the whole “for” loop. But it is a SMALL for loop because only 10 operations are involved. I would like to know if code like this could slow down the efficiency of GPU？</p>
<p>To be more clear, imagine I have a code that could use 100% of GPU, then I insert a small for loop in this code, is it efficient?</p>
<p>Thanks for answers!</p>
Pack sequence with Dataset

username: sh0416
cooked: <p>Hi,</p>
<p>I am looking for a representative snippet to integrate the <code>Dataset</code> and <code>DataLoader</code> class with <code>pack_sequence</code> and <code>pad_sequence</code>.</p>
<p>Is there any tutorials, snippets, examples for this use case?</p>
<p>I have a difficult time to build up a pipeline with <code>pack_sequence</code>.</p>
<p>Thanks,</p>
Why the LSTM dropout is not influence?

username: bamtercelboo
cooked: <p>demo:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/e/e995d243dbb87135f604c5292e0a39c7a5b2634f.png" data-download-href="https://discuss.pytorch.org/uploads/default/e995d243dbb87135f604c5292e0a39c7a5b2634f" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/2X/e/e995d243dbb87135f604c5292e0a39c7a5b2634f.png" alt="image" data-base62-sha1="xkoeXPKxidu4QMaq0uUbAY7ZTgb" width="690" height="110" data-dominant-color="323131"><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">942×151 9.49 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><img src="https://discuss.pytorch.org/uploads/default/original/2X/d/dbc1e288da16865b6b2088239f94efd1526776f8.png" alt="image" data-base62-sha1="vm3XFTD27FhvbeK2Kf19nGJH7i8" width="680" height="64"></p>
<p>the log:<br>
dropout = 0.5<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/f/f93b46d51235ec02b9483ebe7381bbdc9b544097.png" data-download-href="https://discuss.pytorch.org/uploads/default/f93b46d51235ec02b9483ebe7381bbdc9b544097" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/2X/f/f93b46d51235ec02b9483ebe7381bbdc9b544097.png" alt="image" data-base62-sha1="zyNTaCWMMlR1Cwi1ur7BqljenWf" width="690" height="325" data-dominant-color="E8E8E8"><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">800×377 10 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>dropout = 0.25<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/7/79e913c3db0443464cadb06d1a45efbfb6dd70d6.png" data-download-href="https://discuss.pytorch.org/uploads/default/79e913c3db0443464cadb06d1a45efbfb6dd70d6" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/2X/7/79e913c3db0443464cadb06d1a45efbfb6dd70d6.png" alt="image" data-base62-sha1="hot8EnMhbPi3mhpCKjxyLAVNgGy" width="690" height="250" data-dominant-color="EAEAEA"><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">833×302 7.64 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>who can explain it ?</p>

username: stephen-song
cooked: <p>u can find answer <a href="https://discuss.pytorch.org/t/dropout-in-lstm/7784">here</a></p>
Converting video to frames/images for depth prediction

username: abdur_rahman
cooked: <p>Hello every one, I am new here.<br>
I am using Pytorch for depth prediction through the paper ‘Deeper depth prediction by Lanina et al.’, I have to take video from AR Drone 2.0 and convert that to frames/images and then do the depth prediction on each image taken from the video. Afterwards depth map which is the output of neural network will be fed to RGBD SLAM along with its corresponding RGB image.<br>
Can some one help me with that.</p>
<p>Regards.</p>

username: jugaaribros
cooked: <p>If you want to Convert the Video into frames/images then you might try Online tools for this purpose. There are several tools that can solve your problem. But according to my opinion you should try <strong>YTB Converter Free</strong> for this purpose. As, it can easily convert the video into frames and images so you can go into the depth of each image. It contains many tools which might help you.<br>
Here is a link to it: <a href="https://ytbconverterfree.com/youtube-downloader-online-free" rel="nofollow noopener">https://ytbconverterfree.com/youtube-downloader-online-free</a></p>
Clearing gradients on tensors that aren't a part of a model

username: Stephen_Sheng
cooked: <p>So here is the setup that I have some questions regarding. Suppose we have a model M and we set the flag requires_grad = False. And lets instantiate a tensor X = torch.Tensor(input_shape) and set its flag X.requires_grad = True. Also lets create an optimizer optimX = optim.Adam(X). Suppose we have a function F which takes in M(X) and some data X_data and we run F(M(X),X_data).backward. Here the gradients for X are computed. Now normally for a model gradients are accumulated, but in this case our X is just a simple tensor. In the next run I would like to clear the gradients, but since X is just a tensor the method zero_grad is not an option. In my case are the gradients for X accumulated, if so how do I clear the gradients for the next run?</p>

username: Stephen_Sheng
cooked: <p>Nevermind I figured it out. The gradients are accumulated and stored in X.grad. If I want to clear it I can just set it to None.</p>
Proper way to generate gradient of log_prob(random_variable) where random variable is not sampled from the distribution

username: anirudhs96
cooked: <p>Hi,<br>
Grad of network parameters are all zero even though the loss value is non-zero. I don’t want to sample from the distribution and train (not implementing vanilla REINFORCE)</p>
<pre><code class="lang-auto">probs = policy(state)
m = Catagorical(probs)
log_prob = m.log_prob(action) # **action** generated from another source(not a neural network)
loss =  - log_prob * R
loss.backward()
</code></pre>
Intuition Behind Categorical Distribution Return Shape

username: rmehta1987
cooked: <p>If you use logits to represent a categorial distribution with a batch size and then sample N times, what is the intuition behind the return shape as Sampled Shape x Batch Size?  Wouldn’t it make more sense to have your Observations (Batch Size) x Samples drawn</p>
<p><code>logitz = torch.randn(100,15) # 15 classes with 100 batch size represented as log-probabilities</code><br>
<code>m = Categorical(logitz)</code><br>
<code>the_samples = m.sample(200)</code><br>
<code>the_samples.shape = [200, 100]</code></p>
Advanced Tensor slicing in C++

username: pablovela5620
cooked: <p>I’m trying to figure out how to do the following in the C++ Frontend</p>
<p>I have an (21,3) tensor</p>
<pre><code class="lang-auto">xyz=torch.tensor(
[[-31.986  69.746 353.42 ]
 [-37.302  31.703 339.31 ]
 [-56.901   5.73  330.64 ]
 [-54.698 -23.287 323.1  ]
 [-38.11  -42.968 316.82 ]
 [-18.578 -11.142 369.19 ]
 [ -0.725 -41.328 361.34 ]
 [ 12.068 -60.113 353.56 ]
 [ 24.138 -78.254 350.26 ]
 [ -0.     -0.    375.   ]
 [ 22.376 -33.838 388.76 ]
 [ 36.284 -56.047 381.05 ]
 [ 46.965 -73.672 368.   ]
 [ 14.386  10.085 375.35 ]
 [ 36.256 -22.517 385.73 ]
 [ 49.229 -42.654 382.12 ]
 [ 50.176 -49.916 360.85 ]
 [ 25.597  23.502 372.95 ]
 [ 48.176  11.614 364.04 ]
 [ 65.111   2.527 357.42 ]
 [ 83.033  -6.355 354.3  ]])
</code></pre>
<p>I want to convert it into a (5,5,3) array like below</p>
<pre><code class="lang-auto">[[[-31.986  69.746 353.42 ]
  [-37.302  31.703 339.31 ]
  [-56.901   5.73  330.64 ]
  [-54.698 -23.287 323.1  ]
  [-38.11  -42.968 316.82 ]]

 [[-31.986  69.746 353.42 ]
  [-18.578 -11.142 369.19 ]
  [ -0.725 -41.328 361.34 ]
  [ 12.068 -60.113 353.56 ]
  [ 24.138 -78.254 350.26 ]]

 [[-31.986  69.746 353.42 ]
  [ -0.     -0.    375.   ]
  [ 22.376 -33.838 388.76 ]
  [ 36.284 -56.047 381.05 ]
  [ 46.965 -73.672 368.   ]]

 [[-31.986  69.746 353.42 ]
  [ 14.386  10.085 375.35 ]
  [ 36.256 -22.517 385.73 ]
  [ 49.229 -42.654 382.12 ]
  [ 50.176 -49.916 360.85 ]]

 [[-31.986  69.746 353.42 ]
  [ 25.597  23.502 372.95 ]
  [ 48.176  11.614 364.04 ]
  [ 65.111   2.527 357.42 ]
  [ 83.033  -6.355 354.3  ]]]
</code></pre>
<p>Normally I would do this in python with advance slicing using forexample</p>
<pre><code class="lang-auto">indexing = torch.tensor([[0,1 ,2 ,3 ,4] ,  
                         [0,5 ,6 ,7 ,8] , 
                         [0,9 ,10,11,12],  
                         [0,13,14,15,16],  
                         [0,17,18,19,20]]) 

xyz[indexing]
</code></pre>
<p>How would I do something similar in C++? I’ve seen that the function `.slice(/<em>dim</em>/, /<em>start</em>/, /<em>stop</em>/, /<em>step</em>/) , but I’m not sure how I would acheive what I want using this</p>
<p>Thank you for the help!</p>

username: tom
cooked: <p>The C++ equivalent of <code>[...]</code> indexing is <code>torch::index(self, indices)</code> where indices is a vector of Tensors (which can be undefined).<br>
In your case:</p>
<pre><code class="lang-auto">std::vector&lt;torch::Tensor&gt; idx_v{indexing};
auto result = torch::index(xyz, idx_v);
</code></pre>
<p>Best regards</p>
<p>Thomas</p>

username: pablovela5620
cooked: <p>Worked perfectly, thank you! Incase anyone else reads this make sure that you’re indexing tensor is of type torch::kInt64</p>
Output is changing with image per gpu

username: ASMIftekhar
cooked: <p>I am facing a very weird issue here. So, I am trying to train a pretrained resnext model for some specific task. I removed the last few layers from resnext and feeding my images to it. So let’s say, output size from my truncated resnext is (batch size,1024,14,14). I am printing output[0][0][13].  This output changes with batch size per gpu. I am feeding exactly the same images.</p>
<p>Batch Size 1:(Using one GPU)<br>
Output:tensor([0.0000, 0.0000, 0.0931, 0.0179, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,<br>
0.0000, 0.0000, 0.0000, 0.0000, 0.0000]<br>
Batch Size 2: (Using one GPU)<br>
Output: tensor([0.0000, 0.0000, 0.2732, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,<br>
0.0000, 0.0000, 0.0000, 0.0000, 0.0000]<br>
Batch Size 2:(Using two GPUs)<br>
Output:tensor([0.0000, 0.0000, 0.0931, 0.0179, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,<br>
0.0000, 0.0000, 0.0000, 0.0000, 0.0000],</p>
<p>So, the result changes with number of images per gpu. Is there any explanation for this? This is just first iteration. I did not update any weights or anything.</p>

username: ptrblck
cooked: <p>Did you set your model to evaluation mode using <code>model.eval()</code>?<br>
Since ResNext uses batch norm layers, the batch statistics will change during training depending on the batch size.</p>

username: ASMIftekhar
cooked: <p>Ya I realized it. Thanks a lot for clearing it out.</p>
Why is the default ignore index `-100` in cross entropy loss?

username: StatisticDean
cooked: <p>From the source : <a href="https://pytorch.org/docs/stable/_modules/torch/nn/functional.html#cross_entropy" rel="nofollow noopener">https://pytorch.org/docs/stable/_modules/torch/nn/functional.html#cross_entropy</a></p>
<pre><code class="lang-auto">def cross_entropy(input, target, weight=None, size_average=None, ignore_index=-100,
                  reduce=None, reduction='mean'):
</code></pre>
<p>Is there a specific reason that this is -100?</p>

username: yoelshoshan
cooked: <p>I strongly doubt that there is any special reason that this is -100.<br>
a value like -100 is a reasonable default because it is highly unlikely that anyone will pass such value by mistake (unlike -1, which could be a result of off-by-when calculation).</p>
<p>There should be zero expected difference if you set ignore_index= -40 and pass target value of -40 for all of the samples that you want to be ignored in the gradient calculation.</p>
Getting Errors while saving model in .h5 in pytorch and loading in .DL4J

username: nikitha_kona
cooked: <p>I have a model in .h5 and I was able load it and evaluate in pytorch. But when I am trying to load the same .h5 in DL4J I am getting this error<br>
HDF5-DIAG: Error detected in HDF5 (1.10.2) thread 0:</p>
<p><span class="hashtag">#000:</span> H5F.c line 511 in H5Fopen(): unable to open file</p>
<pre><code>major: File accessibilty

minor: Unable to open file
</code></pre>
<p><span class="hashtag">#001:</span> H5Fint.c line 1604 in H5F_open(): unable to read superblock</p>
<pre><code>major: File accessibilty

minor: Read failed
</code></pre>
<p><span class="hashtag">#002:</span> H5Fsuper.c line 413 in H5F__super_read(): file signature not found</p>
<pre><code>major: File accessibilty

minor: Not an HDF5 file
</code></pre>
<p>Exception in thread “main” java.lang.RuntimeException: H5Fopen failed</p>
<p>at org.bytedeco.javacpp.hdf5$H5File.allocate(Native Method)</p>
<p>at org.bytedeco.javacpp.hdf5$H5File.(hdf5.java:13422)</p>
<p>at org.deeplearning4j.nn.modelimport.keras.Hdf5Archive.(Hdf5Archive.java:61)</p>
<p>at org.deeplearning4j.nn.modelimport.keras.utils.KerasModelBuilder.modelHdf5Filename(KerasModelBuilder.java:226)</p>
<p>at org.deeplearning4j.nn.modelimport.keras.KerasModelImport.importKerasSequentialModelAndWeights(KerasModelImport.java:194)<br>
and this how I save and load the model.<br>
t<strong>orch.save(m,‘mod.h5’)</strong><br>
<strong>m = torch.load(‘mod.h5’)</strong><br>
<strong>m.eval()</strong></p>
<p>Thanks</p>

username: ptrblck
cooked: <p>It looks like you are trying to load a model saved in PyTorch with a Java wrapper for Keras models.<br>
Keras does not support loading PyTorch models, so you won’t be able to load it.</p>
<p>Note that the file type (.h5 in this case) is just the filename extension.</p>

username: nikitha_kona
cooked: <p>Thanks a lot for your reply.I was told that .h5 models can be used in DL4J.But its throwing an error.</p>
Data preprocessing for image segmentation task

username: Rishav_Sapahia
cooked: <p>I am trying to do implement a research paper on image segmentation. Following is the pre-processing steps from the paper, Can anyone check and verify whether I am implementing correctly the preprocessing and data-loading steps or not-</p>
<ul>
<li>
<p>A validation split of 15% is selected</p>
</li>
<li>
<p>Random crops of size 512 × 512 are extracted randomly out of the original images ,We opt for a dynamic augmented data set, where training samples are generated randomly at the start of each mini-batch.</p>
</li>
<li>
<p>We artificially grow our data set by a factor of 8 through rotation at 90, 180 and 270 degrees and horizontal flips</p>
</li>
<li>
<p>We have implemented elastic deformation by sampling control points on a regularly spaced 100 × 100 grid. Each control point has isotropic Gaussian noise added with  <em>σ</em>  = 20</p>
</li>
</ul>
<p>Following is my code for the above task-</p>
<pre><code>data_transform = transforms.Compose([transforms.RandomCrop((512,512)),
                                 transforms.ToTensor(),
                                 transforms.RandomRotation([+90,+180]),
                                 transforms.RandomRotation([+180,+270]),
                                 transforms.RandomHorizontalFlip()
                                ])

dataset = datasets.ImageFolder(path_dir,transform = data_transform)
validation_split = 0.15
shuffle_dataset = True
random_seed = 42
dataset_size = len(dataset)
indices = list(range(dataset_size))
split = int(np.floor(validation_split*dataset_size))
if shuffle_dataset:
    np.random.seed(random_seed)
    np.random.shuffle(indices)
train_indices, val_indices = indices[split:], indices[:split]
train_sampler = SubsetRandomSampler(train_indices)
valid_sampler = SubsetRandomSampler(val_indices)
batch_size = 4
num_epochs = 10
iter_per_ep = len(train_sampler) // batch_size
train_loader = torch.utils.data.DataLoader(dataset, batch_size = batch_size,sampler = train_sampler)
valid_loader = torch.utils.data.DataLoader(dataset, batch_size = batch_size,sampler = valid_sampler)</code></pre>
Convert a 4 dims tensor to a list of 3 dims

username: tengyu
cooked: <p>Hi all, let’s say I have a 4 dims tensor:<br>
inputs = tensor.randn(N, C, H, W)</p>
<p>I want to get:<br>
inputs = [input_1, input_2, …, input_n]<br>
input_i.shape = [C, H, W]<br>
len(inputs) = N</p>
<p>Is there any elegant way to make this conversion? I can make it by a for loop but just feel not good.<br>
This might be a weird conversion, but I do need it because the upper level of my project needs it.<br>
Thank you for all for any suggestion!</p>

username: alex.veuthey
cooked: <p>Using a list comprehension is probably faster: <code>inputs = [i for i in inputs]</code></p>
<p>However, since Pytorch tensors can virtually be used as lists would (iterating, item assignment… I think), I’m really curious about your requirements. Can you reveal more about the “upper level” or is this information too sensitive?</p>

username: tengyu
cooked: <p>Hi Alex, thanks for the answer!<br>
It is because the upper level will zip() my inputs with another list. But I think you are right! I have never thought that zip() could directly work on a tensor (indeed it works)! Thanks a lot!</p>
Pytorch convolution and tensorflow convolution giving different results

username: Gaurav_Nayak
cooked: <p>In Tensorflow convolution:<br>
<code></code></p>
<pre>
y = np.random.rand(1,100,100,1)
filterx = np.random.rand(5,5,1,1)
a= tf.nn.conv2d(
    y,
    filterx, [1,1,1,1], 'VALID')
print(sess.run(a))
</pre>

In pytorch , for same input and weights:
<code>
<pre>
x = torch.nn.Conv2d(1,1,5, bias = False)
filter = np.transpose(filterx, (2,3,1,0))
x.weight = torch.nn.Parameter(torch.from_numpy(filter))
z = np.transpose(y, (0,3,1,2))
l = x(torch.from_numpy(z))
l = l.detach().numpy()
l = np.transpose(l,(0,2,3,1))
</pre>
</code>
Both l and a variable should have same o/p, but its not. Why convolution behavior is different in tensorflow and pytorch?

username: tom
cooked: <p>When doing these things, I would recommend to always use sizes that <em>are not</em> equal. Then shape compatibility and comparing the shapes tells you where you have the wrong order.</p>
<pre><code class="lang-python">import torch
import tensorflow
import numpy
y = numpy.random.rand(1,100,100,1)
filterx = numpy.random.rand(4,5,1,2)
a= tensorflow.nn.conv2d(
    y,
    filterx, [1,1,1,1], 'VALID')
with tensorflow.Session() as sess:
  t = (sess.run(a))



x = torch.nn.Conv2d(1,1,5, bias = False)
filter = numpy.transpose(filterx, (3,2,0,1))
x.weight = torch.nn.Parameter(torch.from_numpy(filter))
z = numpy.transpose(y, (0,3,1,2))
l = x(torch.from_numpy(z))
l = l.detach().numpy()
l = numpy.transpose(l,(0,2,3,1))

print(t.shape)
print(l.shape)
print(numpy.abs(t-l).max())
</code></pre>
<p>Gives 4e-15 or so, the double precision.</p>
<p>Best regards</p>
<p>Thomas</p>

username: tracer
cooked: <p>Good Day <a class="mention" href="/u/tom">@tom</a>, I tried your approach and it actually keeps the dimensions when applying filters.</p>
<p>But i have to ask:</p>
<ul>
<li>Could you explain, How you choosed these transpose operations ?</li>
<li>Which logic are you following to move the axes?</li>
</ul>
<p>I will appreciate if you could explain or point me in the right direction of what is being done.</p>
<p>thanks!</p>

username: tom
cooked: <p>Basically, one can read up on how Tensorflow and PyTorch typically order their batches of images (TF: NHWC, PyTorch: NCHW) and weights (TF: HWCiCo, PyTorch CoCiHW) and then implement it and fix anything that went wrong.<br>
When porting a complex model – like when <a class="mention" href="/u/ptrblck">@ptrblck</a> and I did <a href="https://github.com/lernapparat/lernapparat/tree/master/style_gan" rel="nofollow noopener">ported StyleGAN</a> – I usually find a couple of things where my first attempt is wrong. This can be tedious and error-prone when you don’t have a comparison point, which is why people would love first class <a href="http://nlp.seas.harvard.edu/NamedTensor" rel="nofollow noopener">named tensors</a>.</p>
<p>Best regards</p>
<p>Thomas</p>

username: tracer
cooked: <p>Thanks is very clear now, i wasn’t taking into account weights order.</p>
LSTM Hidden State Between batches

username: danill
cooked: <p>HI all.<br>
I’m training an lstm network on a long series by deviding it to subseries.<br>
Let’s say my series is a (f, 100) long (100 timesteps of f features in each step), and I divide it into 20 subseries of 5 steps long each.<br>
I want to look at two scenarios:<br>
In the first one we want plug these subseries 10 at a time to an LSTM model (so we will run lstm twice…), and have every subseries follow the previous one’s last timestep (i.e. [(s0,s1,s2,s3,s4), (s5,s6,s7,s8,s9), …]). So the initial hiddens (i.e (h0, c0)) will be of size (num_layers, num_batches, len_hidden). I then run the forward function on (input, (h0, c0)).<br>
What confuses me is that I want (I think we all want) the hidden vector to be time specific so I need it to start each batch with hidden’s last value from the previous batch, but I don’t know if that is the case, because I do need to give an initial value to every batch… If not, is there a way to do that without looping and feeding one batch at a time?<br>
The second scenario is similar : suppose I now take my subsequences to advance by one element each time (i.e. [(s1,s2,s3,s4,s5), (s2,s3,s4,s5,s6), (s3,s4,s5,s6,s7)…]) is there a way of making the second subseries’ h0 be the second subseries’ h1 (defining h0 to be (h0, c0))?</p>
<p>Third question is about whether I understand RNNs correctly:<br>
In my view, the hidden layer should be timestep specific (at least from the point you want to start remembering) but I have seen some code in which the hidden was just initialized to zero at every batch, also I haven’t found any documentation or questions regarding the choices of hidden initialization across batches.<br>
Thank you!</p>

username: danill
cooked: <p>Have I said something wrong? Is the question silly? Why isn’t anybody answering???</p>
What 'num_batches_tracked' in the new BN is for?

username: jxgu1016
cooked: <p>In PyTorch 0.4.1, the new added buffer ‘num_batches_tracked’ in BN can cause pretrained model incompatibility with old version like <a href="https://discuss.pytorch.org/t/solved-unexpected-key-s-in-state-dict-batches-tracked/23884/2">[SOLVED] Unexpected key(s) in state_dict: batches_tracked"</a>.</p>
<p>So I am wondering why we need this buffer?</p>

username: crcrpar
cooked: <p>It’s used to update <code>running_mean</code> and <code>running_variance</code>.<br>
They are used to normalize input samples from test/validation datasets.</p>

username: Yilin_Liu
cooked: <p>Hi <a class="mention" href="/u/crcrpar">@crcrpar</a>, could you please specify how this will affect the running_mean and running _variance? Thanks!</p>

username: Zhang_Chi
cooked: <p>any new comments on this ?</p>

username: thk_ihgg
cooked: <p>Hi, I think you can check this page to see what it is for:<br>
<a href="https://github.com/pytorch/pytorch/blob/10c4b98ade8349d841518d22f19a653a939e260c/torch/nn/modules/batchnorm.py#L58-L81" rel="nofollow noopener">github.com/pytorch/batchnorm.py</a></p>
<p>Just as its name implies, assuming you want to use <code>torch.nn.BatchNorm2d</code> (by default, with <code>track_running_stats=True</code>):</p>
<ol>
<li>When you are at training, the <code>num_batches_tracked</code> (starting from zero) will plus 1 for each mini-batch.</li>
<li>If you didn’t specify <code>momentum</code>, which is used for calculating running mean and variance by exponential method, then it will use <code>1/num_batches_tracked</code> as a factor to calculate them (i.e. cumulative method).</li>
</ol>
<p>I guess it should be clear why we need this buffer.</p>
Sliding max over dimension

username: LeanderK
cooked: <p>I’ve got a tensor where I want to make sure that all values in a certain axis are ascending. My idea was to slide a max over the dimension. Simple example:</p>
<p><code>[1,2,3,4,3,6]</code></p>
<p>after correction:</p>
<p><code>[1,2,3,4,4,6]</code></p>
<p>ideally, I would fold the max over a dimension using an accumulator (initialized with minus inf), but I wonder how to implement this in torch?</p>

username: LeviViana
cooked: <p>I think <code>x.gather(dim, x.argsort(dim))</code> solves your problem.</p>
<pre><code class="lang-python">import torch
x = torch.Tensor([[3, 1], [2, 4]])
print(x.gather(0, x.argsort(0))) # Columns sorted
print(x.gather(1, x.argsort(1))) # Rows sorted
</code></pre>

username: tom
cooked: <p>Hi Leander,</p>
<p><a href="https://github.com/pytorch/pytorch/issues/20240" rel="nofollow noopener">#20240</a> has a race who get’s to implement cummax.</p>
<p>Best regards</p>
<p>Thomas</p>

username: LeviViana
cooked: <p>Sorry I didn’t get your point the first time I read <img src="https://discuss.pytorch.org/images/emoji/apple/man_facepalming.png?v=9" title=":man_facepalming:" class="emoji" alt=":man_facepalming:">!</p>
C++ faster rcnn example

username: lsrk
cooked: <p>Hello,<br>
I made faster rcnn using c++ frontend based on maskrcnn-benchmark structure.<br>
<a href="https://github.com/lsrock1/maskrcnn_benchmark.cpp" rel="nofollow noopener">https://github.com/lsrock1/maskrcnn_benchmark.cpp</a></p>
<p>Using trained weight in python(maskrcnn-benchmark) i successfully reproduced the original performance res50 and res101<br>
The Parallel module of my implementation is not perfect. So, i couldn’t test training yet.</p>
<p>But this repo includes a script about python weight to jit and jit to c++ tensor and almost every functions in original repo(data loading, transform, weight loading etc.) with same structure.<br>
I think this implementation could be interesting.</p>
<p>Thanks!</p>

username: tom
cooked: <p>Thank you for sharing!</p>
Custom loss function does not work as expected on large batches

username: Daniel_Ortega
cooked: <p>Hi, I’m new to pytorch, and I’d like you to help me with something. I’m doing segmentation and need to apply a mask to the lost function nn.MSELoss() where:</p>
<p>I have the following function:</p>
<pre><code class="lang-auto">loss = mask.numel()/mask.sum() * self.criterion(output, target)
</code></pre>
<p>mask: is a binary mask of 0 and 1<br>
output: is the output of my network<br>
target: is the objective of the network</p>
<p>when I apply the function to a batch size of size 1, it works correctly.<br>
But when I apply it to a batch size greater than 1, I don’t get the desired results.</p>
<p>Try defining a custom loss function, but it doesn’t seem to be the solution either,</p>
<pre><code class="lang-auto">class MaskedMSE(nn.Module):
    def __init__(self):
        super(MaskedMSE,self).__init__()
        self.criterion = nn.MSELoss()

    def forward(self,input_a,target,density_mask):
        mask_f = torch.mean((density_mask.numel()/density_mask.shape[0])/density_mask.sum(dim=1).sum(dim=1).sum(dim=1)))

        self.loss = mask_f*self.criterion(input_a,target)
        return self.loss
</code></pre>
<p>I hope you can give me some guidance.</p>

username: ptrblck
cooked: <p>I’m not sure what the desired result is, but maybe this manual approach might help:</p>
<pre><code class="lang-python"># Single sample
N = 1
mask = torch.randint(0, 2, (N, 10, 10)).float()
output = torch.empty(N, 10, 10).uniform_(0, 1)
target = torch.randint(0, 2, (N, 10, 10)).float()
criterion = nn.MSELoss()
loss = mask.numel()/mask.sum() * criterion(output, target)

# Batch of 10 samples
N = 10
mask = torch.randint(0, 2, (N, 10, 10)).float()
output = torch.empty(N, 10, 10).uniform_(0, 1)
target = torch.randint(0, 2, (N, 10, 10)).float()
criterion = nn.MSELoss(reduction='none')
loss = (mask.size(1)*mask.size(2))/mask.sum([1, 2]) * criterion(output, target).mean([1, 2])
loss = loss.mean()
</code></pre>

username: Daniel_Ortega
cooked: <p>Thank you. It works as expected.</p>
Syntax for imagenet example on github?

username: DrEGPU
cooked: <p>Sorry if this is a stupid question with an obvious answer but I’ve been messing around the example on github to train imagenet. Instead, I used it on my own custom dataset which is structured similarly. It seemed to train OK (could be better), but I don’t know how make the script run in evaluate mode. I know you use the -e flag for evaluate, but how do I tell it to use my newly created PTH file? I guess I could try writing my own code, but since the github example already has an eval mode…</p>
<p>Here’s the github code:</p>
<aside class="onebox whitelistedgeneric">
  <header class="source">
      <img src="https://github.githubassets.com/favicon.ico" class="site-icon" width="16" height="16">
      <a href="https://github.com/pytorch/examples/tree/master/imagenet" target="_blank" rel="nofollow noopener">GitHub</a>
  </header>
  <article class="onebox-body">
    <img src="https://avatars2.githubusercontent.com/u/21003710?s=400&amp;amp;v=4" class="thumbnail onebox-avatar" width="60" height="60">

<h3><a href="https://github.com/pytorch/examples/tree/master/imagenet" target="_blank" rel="nofollow noopener">pytorch/examples</a></h3>

<p>A set of examples around pytorch in Vision, Text, Reinforcement Learning, etc. - pytorch/examples</p>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>


username: ptrblck
cooked: <p>You could pass the checkpoint path as the <code>--resume</code> argument and set <code>--evaulate</code> to just run the validation method.<br>
I assume you’ve already added your model definition etc. to the script.</p>
<p>Would that work for you or am I missing something?</p>

username: DrEGPU
cooked: <p>Thanks, I hadn’t thought of that. I’m still a novice. I trained my model and got a PTH file, so now my question is “now what?” I guess it’s time to evaluate. <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>
<p>“I assume you’ve already added your model definition etc. to the script.”</p>
<p>I’m not sure what you mean. I use the -a flag to make sure it’s using the right architecture (resnet101, in my case).</p>
How do I index a 2-D matrix row wise?

username: crytorch
cooked: <p>I would like to index a 2-D matrix row-wise and re-assign values.</p>
<p>For example, first consider a 1-D vector case where we have three 1-D tensors <code>t1, indexes, t2</code> with the same shape. We can do this indexing and re-assignment as follows:</p>
<pre><code class="lang-auto">indexes = torch.tensor([0, 2, 1, 3])
t1 = torch.tensor([0.0, 0.0, 0.0, 0.0])
t2 = torch.tensor([0.1, 0.2, 0.3, 0.4])

t1[indexes] = t2
</code></pre>
<p>Now, say that <code>t1, indexes, t2</code> are 2-D matrices instead of 1-D vectors and have the same shape <code>(R X C)</code>. I would like to do similar indexing as above for every row in these matrices where:</p>
<pre><code class="lang-auto">for i in range(R):
    t1[i][indexes[i]] = t2[i]
</code></pre>
<p>I would like to vectorize this operation instead of using a for loop. How do I do this?</p>

username: ptrblck
cooked: <p><code>.scatter_</code> should work in this case:</p>
<pre><code class="lang-python">indexes = torch.tensor([[0, 2, 1, 3],
                        [1, 0, 3, 2]])
t1 = torch.zeros_like(indexes).float()
t2 = torch.tensor([[0.1, 0.2, 0.3, 0.4],
                   [0.5, 0.6, 0.7, 0.8]])
t1.scatter_(1, indexes, t2)
</code></pre>
Problems porting Tensorflow model to PyTorch and code debugging

username: IamAdiSri
cooked: <p>Hi,</p>
<p>I’m trying to port <a href="https://github.com/tebesu/CollaborativeMemoryNetwork" rel="nofollow noopener">this</a> Tensorflow model to PyTorch (you can see my progress <a href="https://github.com/IamAdiSri/cmn4recosys" rel="nofollow noopener">here</a>).</p>
<p>When I run my code however, the loss does not seem to be dropping at all, and stabilizes ~.76 compared to the original Tensorflow model’s loss of ~.21</p>
<p>How should I go about debugging my code?</p>
<p>Another question about the implementation that I have is whether the code for l2 regularization is written correctly in PyTorch (in comparison to the reference code in TensorFlow).</p>
<pre><code class="lang-auto">    for k, batch in progress:
        optimizer.zero_grad()

        score_pos, score_neg = model(batch)
        batch_loss = criterion(score_pos, score_neg)
        
        # adding l2 regularisation
        for name, param in model.named_parameters():
            if name in ['mem_layer.hop_mapping.weight', 
                        'output_module.dense.weight', 
                        'output_module.out.weight']:
                l2 = torch.sqrt(param.pow(2).sum())
                batch_loss += (config.l2_lambda * l2)

        batch_loss.backward()        
        nn.utils.clip_grad_norm_(model.parameters(), config.grad_clip)
        optimizer.step()
</code></pre>
<p>Any help would be appreciated.</p>
Copy to shared memory remarkably slow

username: TimZaman
cooked: <p>I seem to be bottlenecked by shared memory transfers. Eg it seems remarkably slow:</p>
<pre><code class="lang-auto">for _ in range(64):
        start = time.time()
        x = torch.zeros([int(1e9)], dtype=torch.uint8)
        y = x.share_memory_()
        dt = time.time() - start
        print('dt=', dt)
        del x, y
</code></pre>
<p>Some benchmarks, given a 1GB uint8 tensor;<br>
<code>.clone()</code>: 10GB/s<br>
<code>.cuda()</code>: 5GB/s<br>
<code>.pin_memory()</code>: 10GB/s<br>
<code>.cuda() [when pinned]</code>: 10GB/s<br>
<code>.share_memory_()</code>: 1GB/s <img src="https://discuss.pytorch.org/images/emoji/apple/red_circle.png?v=9" title=":red_circle:" class="emoji" alt=":red_circle:"></p>
How to remove some output from the last layer

username: Muzammal_Naseer
cooked: <p>Hi,</p>
<p>I want to remove some of the ouputs from last layer of a pretrained pytorch model (lets say ResNet50). I want to keep the pretrained weights and biases in-tact but just want to create a new model that has an output of lets say (batch, 300) rather than (batch, 1000)</p>
<p>Thank You.</p>

username: ptrblck
cooked: <p>The <a href="https://pytorch.org/tutorials/beginner/finetuning_torchvision_models_tutorial.html#initialize-and-reshape-the-networks" rel="nofollow noopener">Interning Tutorial</a> gives you some information about changing the last layer to fit your use case.<br>
Basically you would have to replace e.g. <code>model.fc</code> with a new linear layer.</p>
Saving CNN Features

username: learning_pytorch
cooked: <p>Hello,</p>
<p>I plan to use pre-trained CNN for image classification. Also, I plan to train only the FC layers, hence the features shall stay fixed. With this in mind, Its beneficial to generate the features only once and use them over all epochs. My question is how can I save features into disk efficiently? Assume that each image has an image ID so during the forward pass, I can save features based on the image ID. But with high number of images, the size of my dictionary (where I will save features) will keep on expanding and eventually RAM shall not be able to handle it.  So how can I (efficiently) append features pertaining to the current batch in a dictionary (Saved on disk) without loading the dictionary into memory?</p>
<p>Or any other suggestions?</p>
<p>Thanks</p>

username: ptrblck
cooked: <p>If I’m not mistaken, fastai provides some kind of solution for this work flow.<br>
Unfortunately, I cannot find the topic here (or am not sure which keywords were used in the discussion), but maybe <a class="mention" href="/u/sgugger">@sgugger</a> or <a class="mention" href="/u/jphoward">@jphoward</a> might give you more information.</p>

username: sgugger
cooked: <p>It’s not in the library but we have something that does this in <a href="https://github.com/fastai/course-v3/blob/master/nbs/dl2/devise.ipynb" rel="nofollow noopener">this notebook</a> for our DeviSe lesson. See the <code>precompute_activations_dl</code> function, it just takes a regular model and a regular dataloader.</p>
Error Deploting on GCP(Fast.ai)

username: cabhijith
cooked: <p>Hi Everyone,<br>
I am getting the following error while trying to upload a Deep Learning model using fast.ai</p>
<p><code>File "/usr/local/lib/python3.6/site-packages/torch/serialization.py", line 194, in _check_seekable raise_err_msg(["seek", "tell"], e) File "/usr/local/lib/python3.6/site-packages/torch/serialization.py", line 187, in raise_err_msg raise type(e)(msg) AttributeError: 'list' object has no attribute 'seek'. You can only torch.load from a file that is seekable. Please pre-load the data into a buffer like io.BytesIO and try t o load from it instead.</code><br>
Any idea on how to solve this? I am not sure what else details I have to give. Please do ask me<br>
PS: Should I upload the server.py file?</p>

username: ptrblck
cooked: <p>It looks like you are trying to pass a list to <code>torch.load</code>.<br>
Could you post the code which throws this error and explain a bit, how you’ve saved the model?</p>

username: cabhijith
cooked: <p>Hey!<br>
Here is the code that is being used to deploy the model on Google Cloud Platform - <a href="https://github.com/cabhijith/google-app-engine/blob/master/app/server.py" rel="nofollow noopener">https://github.com/cabhijith/google-app-engine/blob/master/app/server.py</a></p>
<p>I saved the model using the learn.export() command on fastai, uploaded it to Google Drive and linked it to the above mentioned code. Sorry, I am not a expert so therefore I can’t pin-point the specific line throwing the error:) PLEASE ask for more details.<br>
Thanks for the help!</p>

username: ptrblck
cooked: <p>I’m unfortunately not that familiar with the fastai API, and I guess the error comes from the <code>load_learner</code> call, which calls <code>torch.load</code> <a href="https://github.com/fastai/fastai/blob/1b3bc029c8fcfa527023a79d8a663803dd9a81d8/fastai/basic_train.py#L610" rel="nofollow noopener">internally</a>.</p>
<p><a class="mention" href="/u/sgugger">@sgugger</a> might have some insight here.</p>

username: cabhijith
cooked: <p>Thanks! I did ask on the fast.ai platform, but did not get a reply. Thanks!</p>

username: ptrblck
cooked: <p>Are you able to load the export file locally?<br>
If you could create a small reproducible code snippet, I could have a look.<br>
The current code contains a lot of web stuff, which is probably not the source of this error.</p>

username: sgugger
cooked: <p>I didn’t see your post on the fastai forum, but that’s probably a better place to have this discussion. You are mixing two versions of the library in that setup.py file.</p>
<p>The fact you’re using <code>export_file_name = 'New_P100.pkl'</code> and <code>load_learner</code> suggests you’re on the latest API, but at the same time you use <code>load_learner</code> with a wrong syntax (it takes path, export_file_name and that’s pretty much it since your whole <code>Learner</code> has been serialized) and <code>learn.load</code> (which is the line that calls <code>torch.load</code> behind the scenes with a variable that I don’t see defined in the code (<code>model_file_name</code>).</p>