akankshakshurai/cuda-error-resolution-analysis huggingface dataset:
How to reshape [1, 1, 3, 50] to [1, 1, 3, 75]?

username: ahmadkhan242
cooked: <p>I am trying to do upsampling in UNet, but while concatenating the encoder matrix with the decoder matrix I am getting a different matrix, and here I don’t want to downsize the decoded matrix.</p>

username: ptrblck
cooked: <p>You cannot reshape a tensor of the shape <code>[1, 1, 3, 50]</code> into <code>[1, 1, 3, 75]</code> as the number of elements differ.<br>
Depending on your use case you could either repeat a subset of the original tensor or use an interpolation method to increase the number of elements e.g. via <code>out = F.interpolate(torch.randn([1, 1, 3, 50]), (3, 75))</code>.</p>

username: ahmadkhan242
cooked: <p>Thanks, it worked.<br>
Ya, I used the wrong word “reshape”.</p>
The classifier predicts labels randomly

username: TTyRAeLL
cooked: <p>I use AlexNet to run the cifar-10 dataset and I encounter a problem. The accuracy may be 10% with no change as training. Its seems that the classifier just randomly predicts the labels. I wonder how to fix this problem</p>

username: hash-ir
cooked: <p>Please add a code example explaining what you are doing.</p>
Problems after installing pytorch on windows

username: KansaiUser
cooked: <p>I have installed pytorch in a conda environment using</p>
<pre><code class="lang-auto">conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
</code></pre>
<p>However after that I try doing <code>import torch</code><br>
and I get the following error</p>
<pre><code class="lang-auto">Microsoft Visual C++ Redistributable is not installed, this may lead to the DLL load failure.  
It can be downloaded at https://aka.ms/vs/16/release/vc_redist.x64.exe                                 
Traceback (most recent call last):                                                                                       
 File "&lt;stdin&gt;", line 1, in &lt;module&gt;                                                                                     
File "C:\Users\aliag\anaconda3\envs\pytorchPractice\lib\site-packages\torch\__init__.py", line 127, in &lt;module&gt;           
raise err                                                                                                           
OSError: [WinError 126] 指定されたモジュールが見つかりません。 
Error loading "C:\Users\aliag\anaconda3\envs\pytorchPractice\lib\site-packages\torch\lib\asmjit.dll" 
or one of its dependencies.                                                 
&gt;&gt;&gt; 
</code></pre>
<p>I would really appreciate some help to correct this problem</p>

username: KansaiUser
cooked: <p>I found the solution. I had not adequately installed CUDA. When I did it again, the problem dissapears</p>

username: Prithvi_Shankar
cooked: <p><a class="mention" href="/u/kansaiuser">@KansaiUser</a>, I’m having the same problem. Can you discuss in detail how you solved it?</p>

username: navneethc
cooked: <p><em>Bumping this up</em></p>
<p>Does anyone have a clear solution to this issue? I faced this when I updated from 1.5.0 to 1.6.0 and soon after that doing a fresh install in a new environment. I already have a couple of versions of Visual C++ Redistributable installed (2013 and 2017).</p>

username: navneethc
cooked: <p>Answering my own question: the situation was set right when I installed the Redistributable that’s linked in the error message. However, I don’t understand why the existing ones didn’t work. Also, if this is an requirement that’s not available as part of a conda repository, why is this not mentioned as part of the installation steps?</p>
Creating a cosine-similarity loss function for a supervised learning task

username: hollowcodes
cooked: <p>I would like to make a <strong>loss function based on cosine similarity</strong> to cluster my data (which is labled) in 2d space. I want it to pass through a NN which ends with two output neurons (x and y coordinates). So lets say x_i , t_i , y_i are input, target and output of the neural network. Then the target is one-hot encoded (classification) but the output are the coordinates (regression).<br>
So to calculate the loss Id like to check the cosine similarity of the output with all other outputs of the dataset which have the same target. So <strong>I want to minimize the cosine angle between all datapoints which have the same target</strong> . So the loss could not be computed every training-step but first when the entire dataset has passed through the network once. So if I would built a <strong>custom loss function in Pytorch</strong> it would need loops and if-else checks to collect or find all the same labels. Is that even differentiable then? Or can I just implement it in Pytorch and the dynamic computation graph will figure it out itself? Answers appreciated!</p>

username: tom
cooked: <aside class="quote no-group" data-username="hollowcodes" data-post="1" data-topic="97276">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/hollowcodes/48/22773_2.png" class="avatar"> hollowcodes:</div>
<blockquote>
<p>So if I would built a <strong>custom loss function in Pytorch</strong> it would need loops and if-else checks to collect or find all the same labels. Is that even differentiable then? Or can I just implement it in Pytorch and the dynamic computation graph will figure it out itself? Answers appreciated!</p>
</blockquote>
</aside>
<p>So you (likely, except for tiny datasets) cannot just backpropagate through everything because you’d exhaust memory before that. I’d probably look at adapting the self-supervised learning methods (like MoCo) - in a nutshell they</p>
<ul>
<li>maximize batch size as far as they can,</li>
<li>use a longer history of data (without computing gradients for this bit) when computing the gradients for the other parts.</li>
</ul>
<p>Best regards</p>
<p>Thomas</p>

username: hollowcodes
cooked: <p>Thank you for your answer, it led me to contrastive learning and that did it for me! Greetings from munich <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>
DataLoader worker is killed by signal - only on parallel runs

username: dvirginz
cooked: <p><strong>I know this error is extremely popular and there are a lot of threads about it, unfortunately, none discusses specifically on my scenario, and I wasn’t able to solve my problem using the previous posts</strong>.</p>
<p>Configuration:</p>
<pre><code class="lang-auto">Cuda 10.1
Python 3.7
pytorch 1.6

sysctl kernel.shmmax
kernel.shmmax = 18446744073692774399
</code></pre>
<p>2 GPUS, 20 cores.</p>
<p>The error ( DataLoader worker (pid 27351) is killed by signal: Killed ) occurs only when I try to dispatch two parallel runs, I.e</p>
<p>Works:<br>
<code>python train -gpus 0,1 num_data_workers 20</code></p>
<p>Crashes (both runs crash at the same time, with different pids) :<br>
first shell:<br>
<code>python train -gpus 0 num_data_workers 5</code><br>
second shell<br>
<code>python train -gpus 1 num_data_workers 5</code></p>
<p>Any idea what can cause that? My dataset does not use any shared storage (I load a NumPy array representing the whole dataset at the start of training).</p>

username: ptrblck
cooked: <p>Are you seeing the same error if <code>num_workers=0</code> are used for the parallel run?</p>

username: dvirginz
cooked: <p>Luckely no, this is what I’m currently doing(one script uses multiple workers and the other is set to =0)</p>

username: ptrblck
cooked: <p>If you are using Windows, are you adding the if-clause protection as described in the <a href="https://pytorch.org/docs/stable/notes/windows.html#usage-multiprocessing">Windows FAQ</a>?</p>

username: dvirginz
cooked: <p>Nope, Ubuntu 18.04.<br>
Ideaa?</p>

username: ptrblck
cooked: <p>Usually you would see the <code>DataLoader</code> crash with this error if one of the workers encountered an error in loading the data.<br>
Setting <code>num_workers=0</code> and rerunning the code should yield the real error message.<br>
Since that’s working fine my best guess is that “something” related to multiprocessing isn’t working properly. Maybe you could try to use a docker container and see, if it would work there?</p>

username: dvirginz
cooked: <p>Is there a chance that the dataloader will crash <em>not</em> during <code>getItem</code>?<br>
I’m using a headless machine, thus creating a stub display using <code>orca</code>. I now realize that sometimes during parallel runs with <code>workers=0</code> the system gets into a deadlock and hangs forever.<br>
Does that may result in a dataloader crashing in a multithreaded scenario?</p>

username: ptrblck
cooked: <p>I don’t know but wouldn’t exclude this possibility.<br>
Is your node properly working without <code>orca</code>?</p>

username: dvirginz
cooked: <p>Yes, thank you for helping drilling down on the problem.<br>
Unfortunately it’s orca, preserving shared memory in a greedy manner, resulting in oo shared memory when two processes want to use the library.</p>
<p>Thanks</p>
LSTM loop output of previous timestep as input

username: Yash_Jain1
cooked: <p>Is there any way to loop back output of an LSTM back into itself for a fixed number of timesteps? One way can be using for loop but I think it will be significantly slower.<br>
In short an alternative of this.</p>
<pre><code class="lang-auto">        for i in range(k): 
            a0, (h0, c0) = lstm(h0, a0)
</code></pre>
<p><a class="mention" href="/u/ptrblck">@ptrblck</a></p>

username: udia
cooked: <p>As far as I am aware, there is no faster way to accomplish this task.</p><aside class="quote" data-post="15" data-topic="1012">
  <div class="title">
    <div class="quote-controls"></div>
    <img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/tlaurent/48/1502_2.png" class="avatar">
    <a href="https://discuss.pytorch.org/t/how-to-speed-up-for-loop-in-customized-rnn/1012/15">How to speed up for loop in customized RNN?</a> 
  </div>
  <blockquote>
    no unfortunately it is not a problem with the loop.  I run the cell 1000 times and it take 4.6 sec in total. Looking at the details of each run, each of them takes in average, 0.0045 sec. So the loop account for very little. Thanks though!
  </blockquote>
</aside>


username: Yash_Jain1
cooked: <p>Thank you for your reply!<br>
I was wondering if I give the LSTM the same input k times (sequence length k instead of 1) instead of unrolling the timesteps using for loop, will it produce the same outputs as before?<br>
For eg.<br>
<code> a0 = [h0, h0, h0, ..., h0] #k times</code><br>
<code>out, _ =  lstm (h0, a0)</code><br>
Will the out be same as appended a0 from the original for loop implementation?</p>
Loading array of text and labels into torchtext

username: glitch
cooked: <p>Greetings,<br>
This is my first time using <code>torchtext</code> and I found it really intuitive. So I was trying to implement a basic classifier using the same.</p>
<p>Certainly there are a lot of methods of importing data from a static file outside into the <code>torchtext.data.TabularDataset</code> but I found none to directly load lists of texts and labels into the functionality.</p>
<p>Here’s my sample:<br>
<code>tweets</code> :containing a list of tweets<br>
<code>labels</code> : denoting their respective sentiment</p>
<p>Till not I’ve defined <code>data.Fields</code> as:</p>
<blockquote>
<p>tweetField=torchtext.data.Field(sequential=True, tokenize=clean_tweets,                                                                                                   include_lengths=True,use_vocab=True)</p>
<p>sentimentField=torchtext.data.Field(sequential=False,use_vocab=False,pad_token=None,unk_token=None)</p>
<p>trainTestFields={‘tweet’:(‘t’,tweetField),‘sentiment’:(‘s’,sentimentField)}</p>
</blockquote>
<p>Can you help me figure out what I am missing ?</p>
Build from source fails at "test_xxx"

username: seliad
cooked: <p>Hi when building Pytorch from source according to instructions with conda, the build is successful until the test_xxx part, (tag v1.6.0).<br>
Is there a way to prevent this from happening?</p>
<p>Thanks <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

username: ptrblck
cooked: <p>Could you post the install log here, please?</p>
'NoneType' object has no attribute 'repeat'

username: Fan_FAN
cooked: <p>Hi, guys, when I run my ssim function, it shows an error:‘NoneType’ object has no attribute ‘repeat’ and I don’t know what’s wrong with my code.<br>
Two Inputs size are both 3 3 256 256</p>
<pre><code class="lang-auto">def isinstance(x, A_tuple): # real signature unknown; restored from __doc__
    """
    Return whether an object is an instance of a class or of a subclass thereof.
    
    A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to
    check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)
    or ...`` etc.
    """
    pass
def ssim(x: torch.Tensor, y: torch.Tensor, kernel_size: int = 11, kernel_sigma: float = 1.5,
         data_range: Union[int, float] = 1., reduction: str = 'mean', full: bool = False,
         k1: float = 0.01, k2: float = 0.03) -&gt; Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]:
    if isinstance(x, torch.ByteTensor) or isinstance(y, torch.ByteTensor):
        x = x.type(torch.float32)
        y = y.type(torch.float32)

    kernel = gaussian_filter(kernel_size, kernel_sigma).repeat(x.size(1), 1, 1, 1).to(y)

</code></pre>

username: ptrblck
cooked: <p>It seems <code>gaussian_filter</code> is not returning anything, which would raise this error.<br>
Could you check, if that might be the case?</p>
SGD OPTIMIZER initialization

username: lifeblack
cooked: <p>Hi! I want to set a optimizer with this parameters:</p>
<pre><code class="lang-auto">base_lr: 1e-2
momentum: 0.9
weight_decay: 0.0001
lr_policy: "step"
display: 100
max_iter: 100000
snapshot: 10000
gamma: 0.5
stepsize: 200000
snapshot_prefix: "model/DR2_stage1"
</code></pre>
<p>I simply write this:</p>
<pre><code class="lang-auto">model=Net(measurement_rate,block_size**2)
model.apply(weights_init)
model.to(device)
learning_rate = 0.001
optimizer = torch.optim.SGD(model.parameters(), lr=learning_rate , momentum=0.9)
scheduler = StepLR(optimizer, step_size=200000, gamma=0.5)
criterion=nn.MSELoss()
</code></pre>
<p>How can I apply first parameters to this code?</p>

username: ptrblck
cooked: <p>Could you explain what you mean by first parameters?</p>
All of the weights are nan

username: lifeblack
cooked: <p>hi I have a very simple linear net:</p>
<pre><code class="lang-auto">class Net(nn.Module):
    def __init__(self,measurement_rate,hidden=block_size**2):
        super(Net,self).__init__()
        self.fc=nn.Linear(int(np.floor(hidden*measurement_rate)),hidden)
    def forward(self,x):
        x=self.fc(x)
        return x
def weights_init(m):
    if isinstance(m, nn.Linear):
        m.weight.data.normal_(0.0,0.01)

model=Net(measurement_rate,block_size**2)
model.apply(weights_init)
model.to(device)
learning_rate = 0.001
optimizer = torch.optim.SGD(model.parameters(), lr=learning_rate , momentum=0.9)
scheduler = StepLR(optimizer, step_size=200000, gamma=0.5)
criterion=nn.MSELoss()

start_time = time.time()
n_epochs=1000000
print_every=500
test_loss_min=np.Inf
for epoch in range(n_epochs):
    print('Epoch:', epoch,'LR:', scheduler.get_last_lr())
    train_loss=0
    model.train()
    for iteration,(label,data) in enumerate(Train_Loader):
        optimizer.zero_grad()
        output=model(label.to(device))
        loss=criterion(output,data.to(device))
        loss.backward()
        optimizer.step()
        train_loss+=loss.item()*data.shape[0]
        if iteration % print_every==0:
            is_training=model.training
            test_loss=0
            model.eval()
            for (label,data) in Test_Loader:
                output=model(label.to(device))
                loss=criterion(output,data.to(device))
                test_loss+=loss.item()*data.shape[0]
            test_loss=test_loss/len(Test_Loader.sampler)
            if test_loss&lt;=test_loss_min:
                print('\t Test loss decreased ({:.6f}--&gt;{:.6f}). '.format(test_loss_min,test_loss))
                test_loss_min=test_loss
            model.train(mode=is_training)  
    scheduler.step()        
    train_loss=train_loss/len(Train_Loader.sampler)
    print(len(Train_Loader.sampler))
    print('weight',copy.deepcopy(model.fc.weight.data))
    print('Epoch: {} \tTraining loss:{:.6f}. Saving Model...'.format(epoch+1,train_loss))
    torch.save(model.state_dict(),('/content/drive/My Drive/dataset/model_step1.pt'))
end_time = time.time()
print('Duration: {}'.format(end_time - start_time))
</code></pre>
<p>I printed the weights. all of them are nan.<br>
loss also is nan.<br>
how can I fix this problem?</p>

username: ptrblck
cooked: <p>Are you seeing an increasing loss during your training?<br>
If so, your training is diverging and the model parameters might overflow after a certain number of iterations.<br>
To avoid it you could try to e.g. lower the learning rate.</p>
I want to delete some of the elements of the tensor array

username: skerlet_flandorle
cooked: <p>I want to delete some of the elements of the tensor array</p>
<p>Is there a function that can be<br>
changed from<br>
[1,2,3,4,5,6,7,8,9]<br>
to<br>
[6,7,8,9]<br>
?</p>

username: ptrblck
cooked: <p>I think you could just slice the tensor via <code>tensor[5:]</code>.</p>

username: KarthikR
cooked: <p>When you say delete, do you mean you want to choose a (continuous) subset of the initial array (meaning slicing solution by <a class="mention" href="/u/ptrblck">@ptrblck</a> will help) or do you want to pick elements at random?</p>
Fastest way to perform validation step?

username: tenrand
cooked: <p>Hi<br>
I am new to pytorch<br>
I want to ask about the most efficient way of doing validation step. My training data is about 30 mil, batch size is 128 and doing validation step with about 15% of the data every 2000th training step, to check for early stopping. Training happens on gpu and currently validation step as well. (I have to stick to this 15% fraction, cant reduce it for an external reason)</p>
<p>I notice that validation step is taking a lot of time, almost as much as the 2000 training step. 2000 training steps take about 250 s while validation takes about 160 s. Is this typical? This looks quite inefficient. I tried increasing the validation batch size but i run out of cuda memory. Should i do it on cpu instead? Is there a general wisdom about this that i dont know about?<br>
Thank you for your answers.</p>

username: ptrblck
cooked: <p>If you haven’t wrapped the validation step into a <code>with torch.no_grad()</code> guard to save memory, you should do it. <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"><br>
Besides that there is no secret and the timing might be expected depending on your model, data loading etc.</p>
Logging and changing activation values outside the forward method

username: satbek
cooked: <p>Hi there,</p>
<p>It is possible to <strong>log</strong> activation values of neurons in a model, or even <strong>change</strong> them in the <code>forward</code> method.</p>
<p>Is it possible to <em>(i) log</em> and <em>(ii) change</em> activation values of neurons without modifying the underlying code of a model (without modifying the <code>forward</code> method)?</p>
<p>Thanks!</p>

username: ptrblck
cooked: <p>Yes, you can use forward hooks as described <a href="https://discuss.pytorch.org/t/how-can-l-load-my-best-model-as-a-feature-extractor-evaluator/17254/6">here</a> to inspect and manipulate the output activations.</p>
Torch Postprocess inference speed problem

username: nuhpiskin
cooked: <p>My model pre process is 500 fps and model fps is 1000 but post process model is stack 30 fps one line. Total fps is down. But this code line is very fast normaly. If ı change this line with under. Then this code is tack same location. I didint find anything like that. I treid every possibilities but same location is slow. <div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/7/9/7903160cfd49881df035488b154ac9c90875119e.png" data-download-href="https://discuss.pytorch.org/uploads/default/7903160cfd49881df035488b154ac9c90875119e" title="Screenshot from 2020-09-26 02-43-21"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/7/9/7903160cfd49881df035488b154ac9c90875119e_2_690x261.png" alt="Screenshot from 2020-09-26 02-43-21" data-base62-sha1="hgwnVycXW2HJyyw3ZPv2u6U5uFw" width="690" height="261" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/7/9/7903160cfd49881df035488b154ac9c90875119e_2_690x261.png, https://discuss.pytorch.org/uploads/default/optimized/3X/7/9/7903160cfd49881df035488b154ac9c90875119e_2_1035x391.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/7/9/7903160cfd49881df035488b154ac9c90875119e.png 2x" data-dominant-color="A4A4A0"><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">Screenshot from 2020-09-26 02-43-21</span><span class="informations">1334×506 77.7 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>

username: ptrblck
cooked: <p>If you are using the GPU you would have to synchronize the code before starting and stopping the timer.<br>
Otherwise the time will be accumulated in a blocking operation.<br>
Could this be the case for the different timings you are seeing?</p>

username: nuhpiskin
cooked: <p>Hi thanks for come back i solve last night. I’m measuring wrong like you said. Every thing is normal now.<br>
My model is slow</p>
Pytorch RuntimeError

username: hedinghong
cooked: <p>Error Log information:</p>
<hr>
<p>RuntimeError: Caught RuntimeError in DataLoader worker process 2.<br>
Original Traceback (most recent call last):<br>
File “/home/hong/anaconda3/envs/pytesseract/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py”, line 178, in _worker_loop<br>
data = fetcher.fetch(index)<br>
File “/home/hong/anaconda3/envs/pytesseract/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py”, line 47, in fetch<br>
return self.collate_fn(data)<br>
File “/home/hong/anaconda3/envs/pytesseract/lib/python3.7/site-packages/torch/utils/data/_utils/collate.py”, line 74, in default_collate<br>
return {key: default_collate([d[key] for d in batch]) for key in elem}<br>
File “/home/hong/anaconda3/envs/pytesseract/lib/python3.7/site-packages/torch/utils/data/_utils/collate.py”, line 74, in <br>
return {key: default_collate([d[key] for d in batch]) for key in elem}<br>
File “/home/hong/anaconda3/envs/pytesseract/lib/python3.7/site-packages/torch/utils/data/_utils/collate.py”, line 55, in default_collate<br>
return torch.stack(batch, 0, out=out)<br>
RuntimeError: invalid argument 0: Tensors must have same number of dimensions: got 3 and 4 at /pytorch/aten/src/TH/generic/THTensor.cpp:603</p>
<hr>
<p>when I add one image and it’s label into my datasets , the error happens…<br>
but  before the addition it works OK and the added data seems no problem …<br>
the error happens because the tqdm fetchs the data but get error information …</p>
<p>would Someone  please do me a favor?</p>

username: ptrblck
cooked: <p>The error is raised if your <code>Dataset</code> is returning tensors with a variable shape or a different number of dimensions.<br>
In your case it seems that a some tensors have 3 dimensions while others have 4.<br>
Could you check that and let us know if you get stuck?</p>
Torch.linspace() precision issue in CUDA

username: BuzzLord
cooked: <p>I just tracked down an issue in my project that seems like a bug.  I’m shuffling a (large) tensor by making an index tensor with torch.linspace(), randomizing it with randperm(), then using the shuffled indices to index_select() the original tensor.  The index tensor argument has to be torch.long, so I make it by setting the linspace dtype to long in the call.</p>
<p>On the CPU this seems to work fine, but I’m seeing problems when I have it done on device=“cuda:0”.  It looks like it’s being computed as float32, then cast to long, which for large indices gives bad values.</p>
<pre><code class="lang-auto">&gt;&gt;&gt; torch.linspace(12713984, 16908287, 4194304, dtype=torch.long, device='cpu')[-4:]
tensor([16908284, 16908285, 16908286, 16908287])
&gt;&gt;&gt; torch.linspace(12713984, 16908287, 4194304, dtype=torch.long, device='cuda:0')[-4:]
tensor([16908284, 16908286, 16908288, 16908288], device='cuda:0')
</code></pre>
<p>This is happening in PyTorch 1.6.0, with Python 3.8.5.  It’s on Windows (Geforce driver 456.38) and Linux (450.66, and the 430 version I used before that).  I’ve been playing with this project for months and haven’t seen this until recently.  It might be due to a change in 1.6.0, which I only updated to in the last few weeks.</p>
<p>I’m just going to change it to call linspace with dtype=torch.float64, then cast to long, which seems to work fine.  But I thought I should post something about it.</p>

username: tom
cooked: <p>Don’t use linspace here but use arange. linspace uaes floating point under the hood more and that isn’t a good match with largeish integers.</p>
<p>Bestregards</p>
<p>Thomas</p>
Does resize affect image details?

username: bolt25
cooked: <p>Im working on image filtering right now and wanted to know if resizing in anyway has any kind of filtering effect on the images?</p>

username: ptrblck
cooked: <p>Resizing an image can be seen as a subsampling operation, which could need an anti-alasing filter to prevent aliasing effects (if the image frequencies start to overlap due to the sampling).<br>
<a href="https://en.wikipedia.org/wiki/Image_scaling">This Wikipedia article</a> gives you a high-level overview for a couple of interpolation techniques.</p>
<p>I haven’t seen a lot of thought in the machine learning area regarding aliasing effects in images and would guess that for a lot of use cases the default of image processing libraries seems to work. <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"></p>

username: shuohan
cooked: <p>Hi <a class="mention" href="/u/ptrblck">@ptrblck</a>, does <code>torch.nn.functional.interpolate</code> with <code>mode='bicubic'</code> or <code>'bilinear'</code> have any anti-aliasing built-in? Thank you.</p>

username: ptrblck
cooked: <p>I don’t think an anti-aliasing filter is used and just the resampling is performed based on <a href="https://github.com/pytorch/pytorch/blob/7763e1d7b1be5b13394396646cb00a8766b4a626/aten/src/ATen/native/cpu/UpSampleMoreKernel.cpp#L41">this implementation</a>.</p>