text stringlengths 81 47k | source stringlengths 59 147 |
|---|---|
Question: <p>There are two PyTorch repositories :</p>
<ul>
<li><a href="https://github.com/hughperkins/pytorch" rel="noreferrer">https://github.com/hughperkins/pytorch</a></li>
<li><a href="https://github.com/pytorch/pytorch" rel="noreferrer">https://github.com/pytorch/pytorch</a></li>
</ul>
<p>The first clearly requir... | https://stackoverflow.com/questions/44371560/what-is-the-relationship-between-pytorch-and-torch |
Question: <p>How do I display a PyTorch <code>Tensor</code> of shape <code>(3, 224, 224)</code> representing a 224x224 RGB image?
Using <code>plt.imshow(image)</code> gives the error:</p>
<blockquote>
<p>TypeError: Invalid dimensions for image data</p>
</blockquote>
Answer: <p>Given a <code>Tensor</code> representing ... | https://stackoverflow.com/questions/53623472/how-do-i-display-a-single-image-in-pytorch |
Question: <p>I'm new to pytorch. I read much pytorch code which heavily uses tensor's <code>.data</code> member. But I search <code>.data</code> in the official document and Google, finding little. I guess <code>.data</code> contains the data in the tensor, but I don't know when we need it and when not? </p>
Answer: <... | https://stackoverflow.com/questions/51743214/is-data-still-useful-in-pytorch |
Question: <p>I'm trying to install specific PyTorch version under conda env:</p>
<p>Using pip:</p>
<pre><code>pip3 install pytorch==1.0.1
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underly... | https://stackoverflow.com/questions/64062637/install-specific-pytorch-version-pytorch-1-0-1 |
Question: <p>I've just found that PyTorch docs expose something that is called <a href="https://pytorch.org/docs/stable/jit.html?highlight=model%20features" rel="noreferrer">Torch Scripts</a>. However, I do not know:</p>
<ul>
<li>When they should be used?</li>
<li>How they should be used?</li>
<li>What are their benef... | https://stackoverflow.com/questions/53900396/what-are-torch-scripts-in-pytorch |
Question: <p>I am trying to perform matrix multiplication of multiple matrices in PyTorch and was wondering what is the equivalent of <code>numpy.linalg.multi_dot()</code> in PyTorch?</p>
<p>If there isn't one, what is the next best way (in terms of speed and memory) I can do this in PyTorch?</p>
<p>Code:</p>
<pre><cod... | https://stackoverflow.com/questions/64520994/pytorch-what-is-numpy-linalg-multi-dot-equivalent-in-pytorch |
Question: <p>Torch documentation says use</p>
<pre><code>pip install torch==1.4.0+cpu torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
</code></pre>
<p>to install the latest version of PyTorch. This works when I do it manually but when I add it to req.txt and do <code>pip install -r req.txt<... | https://stackoverflow.com/questions/60912744/install-pytorch-from-requirements-txt |
Question: <p>With python lists, we can do:</p>
<pre><code>a = [1, 2, 3]
assert a.index(2) == 1
</code></pre>
<p>How can a pytorch tensor find the <code>.index()</code> directly?</p>
Answer: <p>I think there is no direct translation from <code>list.index()</code> to a pytorch function. However, you can achieve similar ... | https://stackoverflow.com/questions/47863001/how-pytorch-tensor-get-the-index-of-specific-value |
Question: <p>Objective: Create a conda environment with pytorch and torchvision. Anaconda Navigator 1.8.3, python 3.6, MacOS 10.13.4.</p>
<p>What I've tried:</p>
<ul>
<li>In Navigator, created a new environment. Tried to install pytorch and torchvision but could not because the UI search for packages does not find an... | https://stackoverflow.com/questions/49951846/installing-pytorch-via-conda |
Question: <p>As the question says, what does <code>-1</code> of <code>view()</code> do in PyTorch?</p>
<pre class="lang-py prettyprint-override"><code>>>> a = torch.arange(1, 17)
>>> a
tensor([ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.,
11., 12., 13., 14., 15., 16.])
>... | https://stackoverflow.com/questions/50792316/what-does-1-of-view-mean-in-pytorch |
Question: <p><a href="https://i.sstatic.net/yBrXW.png" rel="noreferrer"><img src="https://i.sstatic.net/yBrXW.png" alt="enter image description here"></a></p>
<p>Such as this, I want to using some auxiliary loss to promoting my model performance.<br/>
Which type code can implement it in pytorch?</p>
<pre><code>#one
l... | https://stackoverflow.com/questions/53994625/how-can-i-process-multi-loss-in-pytorch |
Question: <p>I have a Pytorch code which generates a Pytorch tensor in each iteration of for loop, all of the same size. I want to assign each of those tensors to a row of new tensor, which will include all the tensors at the end. In other works something like this</p>
<pre><code>for i=1:N:
X = torch.Tensor([[1,2,3]... | https://stackoverflow.com/questions/59154920/indexing-pytorch-tensor |
Question: <p>I am very confused by how Pytorch deals with one-hot vectors. In this <a href="https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html" rel="noreferrer">tutorial</a>, the neural network will generate a one-hot vector as its output. As far as I understand, the schematic structure of the neural ne... | https://stackoverflow.com/questions/55549843/pytorch-doesnt-support-one-hot-vector |
Question: <p>I have build pytorch 2.0.1 from source. Using cuda 11.7, cudnn v8, and the driver for the nvidia GPU is 515.43.04 (CUDA version 11.7). Altough Pytorch seems to build successfully when I am trying to run examples downloaded from <a href="https://github.com/pytorch/examples" rel="nofollow noreferrer">github<... | https://stackoverflow.com/questions/76260489/run-pytorch-examples-with-pytorch-build-from-source |
Question: <p>What is the best way to perform hyperparameter optimization for a Pytorch model? Implement e.g. Random Search myself? Use Skicit Learn? Or is there anything else I am not aware of?</p>
Answer: <p>Many researchers use <a href="http://ray.readthedocs.io/en/latest/tune.html" rel="noreferrer">RayTune</a>. It'... | https://stackoverflow.com/questions/44260217/hyperparameter-optimization-for-pytorch-model |
Question: <p>I was trying to replicate <a href="https://discuss.pytorch.org/t/simple-working-example-how-to-use-packing-for-variable-length-sequence-inputs-for-rnn/2120" rel="noreferrer">How to use packing for variable-length sequence inputs for rnn</a> but I guess I first need to understand why we need to "pack&q... | https://stackoverflow.com/questions/51030782/why-do-we-pack-the-sequences-in-pytorch |
Question: <p>PyTorch's <code>torch.transpose</code> function only transposes 2D inputs. Documentation is <a href="http://pytorch.org/docs/master/torch.html#torch.transpose" rel="noreferrer">here</a>.</p>
<p>On the other hand, Tensorflow's <code>tf.transpose</code> function allows you to transpose a tensor of <code>N</... | https://stackoverflow.com/questions/44841654/no-n-dimensional-tranpose-in-pytorch |
Question: <p>When I use pytorch, it showed that my the cuda version pytorch used and cuda version of system are inconsistent, so I need rebuild pytorch from source.</p>
<pre class="lang-sh prettyprint-override"><code># install dependency
pip install astunparse numpy ninja pyyaml mkl mkl-include setuptools cmake cffi ty... | https://stackoverflow.com/questions/71075872/how-to-build-pytorch-source |
Question: <p>I was trying to use my current code with an A100 gpu but I get this error:</p>
<pre><code>---> backend='nccl'
/home/miranda9/miniconda3/envs/metalearningpy1.7.1c10.2/lib/python3.8/site-packages/torch/cuda/__init__.py:104: UserWarning:
A100-SXM4-40GB with CUDA capability sm_80 is not compatible with the... | https://stackoverflow.com/questions/66992585/how-does-one-use-pytorch-cuda-with-an-a100-gpu |
Question: <p>In PyTorch what is the difference between <code>new_ones()</code> vs <code>ones()</code>. For example,</p>
<pre><code>x2.new_ones(3,2, dtype=torch.double)
</code></pre>
<p>vs </p>
<pre><code>torch.ones(3,2, dtype=torch.double)
</code></pre>
Answer: <p>For the sake of this answer, I am assuming that you... | https://stackoverflow.com/questions/52866333/pytorch-new-ones-vs-ones |
Question: <p>I have a Dockerfile which installs PyTorch library from the source code.</p>
<p>Here is the snippet from Dockerfile which performs the installation from source code of pytorch</p>
<pre><code>RUN cd /tmp/ \
&& git clone https://github.com/pytorch/pytorch.git \
&& cd pytorch \
&& ... | https://stackoverflow.com/questions/68496906/pytorch-installation-for-different-cuda-architectures |
Question: <p>I'm trying to get pytorch with cuda 10 compatibility via :
conda install pytorch torchvision cudatoolkit=10.2 -c pytorch
from(<a href="https://discuss.pytorch.org/t/pytorch-with-cuda-11-compatibility/89254" rel="nofollow noreferrer">https://discuss.pytorch.org/t/pytorch-with-cuda-11-compatibility/89254</a>... | https://stackoverflow.com/questions/71822979/pytorch-cuda-for-ubuntu-20-04 |
Question: <p>I have a huge list of numpy arrays, where each array represents an image and I want to load it using torch.utils.data.Dataloader object. But the documentation of torch.utils.data.Dataloader mentions that it loads data directly from a folder. How do I modify it for my cause? I am new to pytorch and any help... | https://stackoverflow.com/questions/44429199/how-to-load-a-list-of-numpy-arrays-to-pytorch-dataset-loader |
Question: <p>everyone.
I'm stuck in using tensorboard in pytorch.
The point is add_embedding method makes the error like below:</p>
<pre><code>Traceback (most recent call last):
File "test2.py", line 126, in <module>
writer.add_embedding(features, metadata=class_labels, label_img = images.unsqueez... | https://stackoverflow.com/questions/66490589/pytorch-tensorboard-add-embedding-error |
Question: <p>What is volatile attribute of a Variable in Pytorch? Here's a sample code for defining a variable in PyTorch.</p>
<pre><code>datatensor = Variable(data, volatile=True)
</code></pre>
Answer: <p>Basically, set the input to a network to volatile if you are doing inference only and won't be running backpropa... | https://stackoverflow.com/questions/49837638/what-is-volatile-variable-in-pytorch |
Question: <p>I was wondering is there an equivalent PyTorch loss function for TensorFlow's <code>softmax_cross_entropy_with_logits</code>?</p>
Answer: <blockquote>
<p>is there an equivalent PyTorch loss function for TensorFlow's <code>softmax_cross_entropy_with_logits</code>?</p>
</blockquote>
<h3 id="torch.nn.functio... | https://stackoverflow.com/questions/46218566/pytorch-equivalence-for-softmax-cross-entropy-with-logits |
Question: <p>When there are max and absolute value operations in the pytorch model, how does pytorch implement the gradient descent of these operations during backpropagation
please give a detail answer,thank you!</p>
Answer: <p><code>torch.abs</code> is non-differentiable only at 0, and it seems that pytorch implemen... | https://stackoverflow.com/questions/75745988/pytorch-backpropagation |
Question: <p>I'm building Kmeans in pytorch using gradient descent on centroid locations, instead of expectation-maximisation. Loss is the sum of square distances of each point to its nearest centroid. To identify which centroid is nearest to each point, I use argmin, which is not differentiable everywhere. However, ... | https://stackoverflow.com/questions/54969646/how-does-pytorch-backprop-through-argmax |
Question: <p>I get this error:</p>
<pre><code>C:\Users>conda install pytorch torchvision -c soumith
Fetching package metadata .............
PackageNotFoundError: Package missing in current win-64 channels:
- pytorch
</code></pre>
<p>I got <code>conda install pytorch torchvision -c soumith</code> from <a href="h... | https://stackoverflow.com/questions/45906706/pytorch-install-with-anaconda-error |
Question: <p>I am currently working on converting some code from tensorflow to pytorch, I encountered problem with <a href="https://www.tensorflow.org/api_docs/python/tf/gather" rel="nofollow noreferrer"><code>tf.gather</code></a> func, there is no direct function to convert it in pytorch.</p>
<p>What I am trying to d... | https://stackoverflow.com/questions/57071002/pytorch-tensor-indexing |
Question: <p>I'm trying to get a basic app running with Flask + PyTorch, and host it on Heroku. However, I run into the issue that the maximum slug size is 500mb on the free version, and PyTorch itself is ~500mb.</p>
<p>After some google searching, someone wrote about finding a cpu-only version of PyTorch, and using th... | https://stackoverflow.com/questions/51730880/where-do-i-get-a-cpu-only-version-of-pytorch |
Question: <p>I am trying to integrate pytorch and pytorch-operators into kubeflow pipelines and I am not able to get a good resource for both. Is this possible in the current implementation?</p>
<p>I understand that TFJob and PyTorchJob all run training containers on top of a kubernetes cluster but I am trying to integ... | https://stackoverflow.com/questions/66201581/pytorch-and-pytorch-operator-kubeflow-pipelines |
Question: <p>I am unable to find the Pytorch version for cuda driver 12.2. Can anyone please guide me where can I find any material that helps.</p>
<p>I have installed currently pytorch version 11.7. While training the model i am facing following error.</p>
<p>**
RuntimeError(CUDA_MISMATCH_MESSAGE.format(cuda_str_versi... | https://stackoverflow.com/questions/76678846/pytorch-version-for-cuda-12-2 |
Question: <p>I'm having issues with implementing custom activation functions in Pytorch, such as Swish. How should I go about implementing and using custom activation functions in Pytorch?</p>
Answer: <p>There are <strong>four</strong> possibilities depending on what you are looking for. You will need to ask yourself ... | https://stackoverflow.com/questions/55765234/pytorch-custom-activation-functions |
Question: <p>I want to load a pre-trained word2vec embedding with gensim into a PyTorch embedding layer.</p>
<p>How do I get the embedding weights loaded by gensim into the PyTorch embedding layer?</p>
Answer: <p>I just wanted to report my findings about loading a gensim embedding with PyTorch.</p>
<hr>
<ul>
<li><h2... | https://stackoverflow.com/questions/49710537/pytorch-gensim-how-do-i-load-pre-trained-word-embeddings |
Question: <p>I'm using <em>Windows 10</em>, and my the installation dir is:
<code>anacoda2/python2.7/python3.6/opencv/cdua10/cudnn ....</code> </p>
<p>Now I want to install pytorch, with this command: <code>conda install pytorch -c pytorch</code></p>
<p>But as result I'm getting this error:</p>
<pre><code>C:\Users\M... | https://stackoverflow.com/questions/53137588/pytorch-backports-functools-lru-cache-conflict |
Question: <p>In NumPy, I would do</p>
<pre class="lang-py prettyprint-override"><code>a = np.zeros((4, 5, 6))
a = a[:, :, np.newaxis, :]
assert a.shape == (4, 5, 1, 6)
</code></pre>
<p>How to do the same in PyTorch?</p>
Answer: <pre><code>a = torch.zeros(4, 5, 6)
a = a[:, :, None, :]
assert a.shape == (4, 5, 1, 6)
</c... | https://stackoverflow.com/questions/65470807/how-to-add-a-new-dimension-to-a-pytorch-tensor |
Question: <p>I want to make a cross validation in my project based on Pytorch.
And I didn't find any method that pytorch provided to delete the current model and empty the memory of GPU. Could you tell that how can I do it?</p>
Answer: <p>Freeing memory in PyTorch works as it does with the normal Python garbage collec... | https://stackoverflow.com/questions/53350905/pytorch-delete-model-from-gpu |
Question: <p>I HAVE A ERROR IN INSTALLING PYTORCH:
PLEASE HELP ME.
CondaHTTPError: HTT P000 CONNECTION FAILED for url <a href="https://conda.anaconda.org/pytorch/win-64/current_repodata.json" rel="nofollow noreferrer">https://conda.anaconda.org/pytorch/win-64/current_repodata.json</a>
Elapsed: -</p>
<p>An HTTP error oc... | https://stackoverflow.com/questions/74107561/pytorch-install |
Question: <p>I've noticed that PyTorch 2.0.1 DataLoader is significantly slower than PyTorch 1.13 DataLoader, especially when the number of workers is set to something other than 0. I've done some research and found that this is due to a change in the way that PyTorch handles multiprocessing in version 2.0.1. In PyTorc... | https://stackoverflow.com/questions/77417920/pytorch-1-13-dataloader-is-significantly-faster-than-pytorch-2-0-1 |
Question: <p>I am trying to build PyTorch.
Reference site:<a href="https://github.com/hughperkins/pytorch" rel="nofollow noreferrer">https://github.com/hughperkins/pytorch</a></p>
<p>but, When we performed unit test, The following error occur.</p>
<pre><code>ImportError while importing test module '/home/usr2/pytorch... | https://stackoverflow.com/questions/53165990/pytorch-is-installed-but-not-imported |
Question: <p>I'm Trying to perform a Kmeans clusterization using the Pytorch-kmeans (<a href="https://github.com/subhadarship/kmeans_pytorch" rel="nofollow noreferrer">github</a>). I have aprox. 27M array with 512 elements each, the aprox. size of the numpy array is 51GB which is bigger than my GPU RAM (32GB). Is there... | https://stackoverflow.com/questions/63348557/using-pytorch-dataloader-in-pytorch-kmeans |
Question: <hr />
<p><strong>TLDR</strong>:</p>
<p><em>A simple (single hidden-layer) feed-forward Pytorch model trained to predict the function <code>y = sin(X1) + sin(X2) + ... sin(X10)</code> substantially underperforms an identical model built/trained with Keras. Why is this so and what can be done to mitigate the d... | https://stackoverflow.com/questions/73600481/400-higher-error-with-pytorch-compared-with-identical-keras-model-with-adam-op |
Question: <p>Suppose I have two arrays, and I want to calculate row-wise differences between every two rows of two matrices of the same shape as follows. This is how the procedure looks like in numpy, and I want to replicate the same thing in pytorch.</p>
<pre><code>>>> a = np.array([[1,2,3],[4,5,6]])
>>... | https://stackoverflow.com/questions/55884299/pytorch-compute-pairwise-difference-incorrect-result-in-numpy-vs-pytorch-and-di |
Question: <p>I have a newly installed Anaconda3 (version 2020.02) environment, and I have installed Pytorch GPU version by the command <code>conda install pytorch torchvision cudatoolkit=10.2 -c pytorch</code>. I have verified that my Pytorch indeed runs fine on GPU.</p>
<p>However, whenever I update Anaconda by <code>... | https://stackoverflow.com/questions/62630186/anaconda-always-want-to-replace-my-gpu-pytorch-version-to-cpu-pytorch-version-wh |
Question: <p>i am using python2.7 in virtual environment. i tried to install pytorch in python2.7 but i got error belows:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code... | https://stackoverflow.com/questions/57835948/how-to-install-pytorch-in-python2-7 |
Question: <p>I'm using the following command to install pytorch in my conda environment.</p>
<pre><code>conda install pytorch=0.4.1 cuda90 -c pytorch
</code></pre>
<p>However, I'm getting the following error</p>
<blockquote>
<p>Solving environment: failed</p>
<p>PackagesNotFoundError: The following packages are not ava... | https://stackoverflow.com/questions/63272687/unable-to-install-pytorch-in-ubuntu |
Question: <p>I am using MacBook Pro (16-inch, 2019, macOS 10.15.5 (19F96))</p>
<p>GPU</p>
<ul>
<li>AMD Radeon Pro 5300M</li>
<li>Intel UHD Graphics 630</li>
</ul>
<p>I am trying to use Pytorch with Cuda on my mac.</p>
<p>All of the guides I saw assume that i have Nvidia graphic card.</p>
<p>I found this: <a href="https... | https://stackoverflow.com/questions/63423463/using-pytorch-cuda-on-macbook-pro |
Question: <p>Good evening,
I have just installed PyTorch 0.4.0 and I'm trying to carry out the first tutorial "What is PyTorch?"
I have written a Tutorial.py file which I try to execute with Visual Studio Code</p>
<p>Here is the code :</p>
<pre><code>from __future__ import print_function
import torch
print (torch.__... | https://stackoverflow.com/questions/50319943/pytorch-error-message-torch-has-no-member |
Question: <p>I have CUDA 9.2 installed. For example:</p>
<pre><code>(base) c:\>nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Wed_Apr_11_23:16:30_Central_Daylight_Time_2018
Cuda compilation tools, release 9.2, V9.2.88
</code></pre>
<p>I installed PyTorch on... | https://stackoverflow.com/questions/52562352/pytorch-and-cuda-driver |
Question: <p>I have seen in some code examples, that people use .pwf as model file saving format. But in PyTorch documentation .pt and .pth are recommended. I used .pwf and worked fine for small 1->16->16 convolutional network.</p>
<p>My question is what is the difference between these formats? Why is .pwf extension n... | https://stackoverflow.com/questions/59095824/what-is-the-difference-between-pt-pth-and-pwf-extentions-in-pytorch |
Question: <p>What are the big differences between pytorch and numpy, in particular, the autograd.numpy package? ( since both of them can compute the gradient automatically for you.)
I know that pytorch can move tensors to GPU, but is this the only reason for choosing pytorch over numpy?
While pytorch is well known for... | https://stackoverflow.com/questions/62404451/pytorch-versus-autograd-numpy |
Question: <p>In numpy, <code>V.shape</code> gives a tuple of ints of dimensions of V.</p>
<p>In tensorflow <code>V.get_shape().as_list()</code> gives a list of integers of the dimensions of V.</p>
<p>In pytorch, <code>V.size()</code> gives a size object, but how do I convert it to ints?</p>
Answer: <p>For PyTorch v1... | https://stackoverflow.com/questions/46826218/pytorch-how-to-get-the-shape-of-a-tensor-as-a-list-of-int |
Question: <p>Is there any way I can run the python library pytorch in pyodide? I tried installing pytorch with micropip but it gives this error message:</p>
<blockquote>
<p>Couldn't find a pure Python 3 wheel for 'pytorch'</p>
</blockquote>
Answer: <p>In Pyodide micropip only allows to install pure python wheels (i.e.... | https://stackoverflow.com/questions/64358372/run-pytorch-in-pyodide |
Question: <p>I can't get PyTorch to work.</p>
<p>I have cuda and NVIDIA drivers installed</p>
<pre><code>nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Jun__8_16:49:14_PDT_2022
Cuda compilation tools, release 11.7, V11.7.99
Build cuda_11.7.r11.7/compiler.31... | https://stackoverflow.com/questions/75688024/pytorch-error-803-system-has-unsupported-display-driver-cuda-driver-combinat |
Question: <p>Following the example from: </p>
<p><a href="https://github.com/jcjohnson/pytorch-examples" rel="noreferrer">https://github.com/jcjohnson/pytorch-examples</a></p>
<p>This code trains successfully: </p>
<pre><code># Code in file tensor/two_layer_net_tensor.py
import torch
device = torch.device('cpu')
# ... | https://stackoverflow.com/questions/51041128/pytorch-predict-single-example |
Question: <p>I installed pytorch via conda with cuda 7.5</p>
<pre><code>conda install pytorch=0.3.0 cuda75 -c pytorch
>>> import torch
>>> torch.cuda.is_available()
True
</code></pre>
<p>I didn't do any other installations for cuda other than this, since it looks like pytorch comes with cuda</p>
<... | https://stackoverflow.com/questions/52298146/cuda-home-in-pytorch-installation |
Question: <p>Guys I am new to python and deeplearning world</p>
<p>I tried to install pytorch using conda</p>
<p>I get this Error...</p>
<pre><code>(base) C:\WINDOWS\system32>conda install pytorch
</code></pre>
<blockquote>
<p>`Solving environment: failed</p>
</blockquote>
<p>PackagesNotFoundError: The follow... | https://stackoverflow.com/questions/47943081/pytorch-pip-and-conda-error |
Question: <p>I go to the PyTorch website and select the following options</p>
<p>PyTorch Build: Stable (1.2)</p>
<p>Your OS: Windows</p>
<p>Package: pip</p>
<p>Language: Python 3.7</p>
<p>CUDA: None</p>
<p>(All of these are correct)</p>
<p>Than it displays a command to run</p>
<p><code>pip3 install torch==1.2.0... | https://stackoverflow.com/questions/57642019/pytorch-not-downloading |
Question: <p>After installing pytorch via</p>
<pre><code>RUN python3 -m pip install --no-cache-dir torch==1.9.1
</code></pre>
<p>I realised that corresponding docker layer is 1.78GB
Is there any way to reduce pytorch size? Current version is with GPU & Cuda 10.2</p>
Answer: <p>If you are not using <strong>gpu</str... | https://stackoverflow.com/questions/69526212/pytorch-package-too-huge |
Question: <p>I'm transffering a Tensorflow code to a PyTorch code.<br />
Below lines are the problem I couldn't solve yet.<br />
I'm not familiar with PyTorch so that it's not easy for me to find the matching methods in PyTorch library.<br />
Anyone can help me?<br />
p.s. The shape of alpha is (batch, N).</p>
<pre><co... | https://stackoverflow.com/questions/65092587/tensorflow-to-pytorch |
Question: <p>I understand that PyTorch tensors are homogenous, ie, each of the elements are of the same type.</p>
<p>How do I find out the type of the elements in a PyTorch tensor?</p>
Answer: <p>There are three kinds of things:</p>
<pre><code>dtype || CPU tensor || GPU tensor
torch.... | https://stackoverflow.com/questions/53374499/get-the-data-type-of-a-pytorch-tensor |
Question: <p>I am trying to make a simple PyTorch model and convert it to PyTorch jit script using below code. (Final goal is to convert it to PyTorch Mobile)</p>
<pre><code>class Concat(nn.Module):
def __init__(self):
super(Concat, self).__init__()
def forward(self, x):
return torch.cat(x,1)
... | https://stackoverflow.com/questions/74907368/runtime-error-when-converting-pytorch-model-to-pytorch-jit-script |
Question: <p>I am trying to install Pytorch in python 3.12.0 and cuda 12.1 in windows 11 ? But I get the error</p>
<p>ERROR: could not find a version that satisfies the requirement torch(from version: None)
ERROR: No matching distribution found for torch</p>
<p>I installed the nvidia cuda 12.1 as well</p>
<p>I tried to... | https://stackoverflow.com/questions/77478747/pytorch-installation |
Question: <p>I am trying to convert a Keras Model to PyTorch. Now, it involves the <code>UpSampling2D</code> from <code>keras</code>. When I used <code>torch.nn.UpsamplingNearest2d</code> in pytorch, as default value of <code>UpSampling2D</code> in keras is <code>nearest</code>, I got different inconsistent results. Th... | https://stackoverflow.com/questions/71585394/keras-upsampling2d-vs-pytorch-upsampling |
Question: <p>I loaded a custom PyTorch model and I want to find out its input shape. Something like this:</p>
<pre><code>model.input_shape
</code></pre>
<p>Is it possible to get this information?</p>
<hr />
<p><strong>Update:</strong> <code>print()</code> and <code>summary()</code> don't show this model's input shape, ... | https://stackoverflow.com/questions/66488807/pytorch-model-input-shape |
Question: <p>I have a pandas dataframe, <code>df</code>:</p>
<pre class="lang-none prettyprint-override"><code> c1 c2
0 10 100
1 11 110
2 12 120
</code></pre>
<p>How do I iterate over the rows of this dataframe? For every row, I want to access its elements (values in cells) by the name of the columns. For exa... | https://stackoverflow.com/questions/16476924/how-can-i-iterate-over-rows-in-a-pandas-dataframe |
Question: <p>How can I select rows from a DataFrame based on values in some column in Pandas?</p>
<p>In SQL, I would use:</p>
<pre class="lang-sql prettyprint-override"><code>SELECT *
FROM table
WHERE column_name = some_value
</code></pre>
Answer: <p>To select rows whose column value equals a scalar, <code>some_value<... | https://stackoverflow.com/questions/17071871/how-do-i-select-rows-from-a-dataframe-based-on-column-values |
Question: <p>How do I change the size of figure drawn with Matplotlib?</p>
Answer: <p><a href="https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.figure.html" rel="noreferrer"><code>figure</code></a> tells you the call signature:</p>
<pre><code>from matplotlib.pyplot import figure
figure(figsize=(8, 6), dpi=... | https://stackoverflow.com/questions/332289/how-do-i-change-the-size-of-figures-drawn-with-matplotlib |
Question: <p>I want to change the column labels of a Pandas DataFrame from</p>
<pre><code>['$a', '$b', '$c', '$d', '$e']
</code></pre>
<p>to</p>
<pre><code>['a', 'b', 'c', 'd', 'e']
</code></pre>
Answer: <p>Just assign it to the <code>.columns</code> attribute:</p>
<pre><code>>>> df = pd.DataFrame({'$a':[1,2]... | https://stackoverflow.com/questions/11346283/renaming-column-names-in-pandas |
Question: <p>To delete a column in a DataFrame, I can successfully use:</p>
<pre class="lang-py prettyprint-override"><code>del df['column_name']
</code></pre>
<p>But why can't I use the following?</p>
<pre class="lang-py prettyprint-override"><code>del df.column_name
</code></pre>
<p>Since it is possible to access the... | https://stackoverflow.com/questions/13411544/delete-a-column-from-a-pandas-dataframe |
Question: <p>How do I get the number of rows of a pandas dataframe <code>df</code>?</p>
Answer: <p>For a dataframe <code>df</code>, one can use any of the following:</p>
<ul>
<li><code>len(df.index)</code></li>
<li><code>df.shape[0]</code></li>
<li><code>df[df.columns[0]].count()</code> (== <a href="https://pandas.pyd... | https://stackoverflow.com/questions/15943769/how-do-i-get-the-row-count-of-a-pandas-dataframe |
Question: <p>How do I select columns <code>a</code> and <code>b</code> from <code>df</code>, and save them into a new dataframe <code>df1</code>?</p>
<pre class="lang-none prettyprint-override"><code>index a b c
1 2 3 4
2 3 4 5
</code></pre>
<p>Unsuccessful attempt:</p>
<pre class="lang-py pretty... | https://stackoverflow.com/questions/11285613/selecting-multiple-columns-in-a-pandas-dataframe |
Question: <p>I have the following DataFrame (<code>df</code>):</p>
<pre><code>import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.rand(10, 5))
</code></pre>
<p>I add more column(s) by assignment:</p>
<pre class="lang-py prettyprint-override"><code>df['mean'] = df.mean(1)
</code></pre>
<p>How can I move ... | https://stackoverflow.com/questions/13148429/how-to-change-the-order-of-dataframe-columns |
Question: <p>I created a DataFrame from a list of lists:</p>
<pre class="lang-py prettyprint-override"><code>table = [
['a', '1.2', '4.2' ],
['b', '70', '0.03'],
['x', '5', '0' ],
]
df = pd.DataFrame(table)
</code></pre>
<p>How do I convert the columns to specific types? In this case, I want to ... | https://stackoverflow.com/questions/15891038/change-column-type-in-pandas |
Question: <p>How do I create an empty <code>DataFrame</code>, then add rows, one by one?</p>
<p>I created an empty <code>DataFrame</code>:</p>
<pre><code>df = pd.DataFrame(columns=('lib', 'qty1', 'qty2'))
</code></pre>
<p>Then I can add a new row at the end and fill a single field with:</p>
<pre><code>df = df._set_valu... | https://stackoverflow.com/questions/10715965/create-a-pandas-dataframe-by-appending-one-row-at-a-time |
Question: <p>I work with Series and DataFrames on the terminal a lot. The default <code>__repr__</code> for a Series returns a reduced sample, with some head and tail values, but the rest missing.</p>
<p>Is there a builtin way to pretty-print the entire Series / DataFrame? Ideally, it would support proper alignment, ... | https://stackoverflow.com/questions/19124601/pretty-print-an-entire-pandas-series-dataframe |
Question: <h2>Background</h2>
<p>I just upgraded my Pandas from 0.11 to 0.13.0rc1. Now, the application is popping out many new warnings. One of them like this:</p>
<pre class="lang-none prettyprint-override"><code>E:\FinReporter\FM_EXT.py:449: SettingWithCopyWarning: A value is trying to be set on a copy of a slice fr... | https://stackoverflow.com/questions/20625582/how-to-deal-with-settingwithcopywarning-in-pandas |
Question: <p>I have this DataFrame and want only the records whose EPS column is not NaN:</p>
<pre class="lang-none prettyprint-override"><code> STK_ID EPS cash
STK_ID RPT_Date
601166 20111231 601166 NaN NaN
600036 20111231 600036 NaN 12
600016 20111231 600016 4.3 NaN
6... | https://stackoverflow.com/questions/13413590/how-to-drop-rows-of-pandas-dataframe-whose-value-in-a-certain-column-is-nan |
Question: <p>I have the following indexed DataFrame with named columns and rows not- continuous numbers:</p>
<pre class="lang-none prettyprint-override"><code> a b c d
2 0.671399 0.101208 -0.181532 0.241273
3 0.446172 -0.243316 0.051767 1.577318
5 0.614758 0.075793 -0.451460 -0.... | https://stackoverflow.com/questions/12555323/how-to-add-a-new-column-to-an-existing-dataframe |
Question: <p>I want to get a list of the column headers from a Pandas DataFrame. The DataFrame will come from user input, so I won't know how many columns there will be or what they will be called.</p>
<p>For example, if I'm given a DataFrame like this:</p>
<pre class="lang-none prettyprint-override"><code> y gdp ... | https://stackoverflow.com/questions/19482970/get-a-list-from-pandas-dataframe-column-headers |
Question: <p>Let’s say I have the following Pandas dataframe:</p>
<pre><code>df = DataFrame({'A': [5,6,3,4], 'B': [1,2,3,5]})
df
A B
0 5 1
1 6 2
2 3 3
3 4 5
</code></pre>
<p>I can subset based on a specific value:</p>
<pre><code>x = df[df['A'] == 3]
x
A B
2 3 3
</code></pre>
<p>... | https://stackoverflow.com/questions/12096252/use-a-list-of-values-to-select-rows-from-a-pandas-dataframe |
Question: <p>How can I convert a list of dictionaries into a DataFrame?
I want to turn</p>
<pre class="lang-py prettyprint-override"><code>[{'points': 50, 'time': '5:00', 'year': 2010},
{'points': 25, 'time': '6:00', 'month': "february"},
{'points':90, 'time': '9:00', 'month': 'january'},
{'points_h1':2... | https://stackoverflow.com/questions/20638006/convert-list-of-dictionaries-to-a-pandas-dataframe |
Question: <p>I have tried to puzzle out an answer to this question for many months while learning pandas. I use SAS for my day-to-day work and it is great for it's out-of-core support. However, SAS is horrible as a piece of software for numerous other reasons.</p>
<p>One day I hope to replace my use of SAS with pyth... | https://stackoverflow.com/questions/14262433/large-data-workflows-using-pandas |
Question: <p>I have a dataframe in pandas which I would like to write to a CSV file.</p>
<p>I am doing this using:</p>
<pre class="lang-py prettyprint-override"><code>df.to_csv('out.csv')
</code></pre>
<p>And getting the following error:</p>
<pre class="lang-none prettyprint-override"><code>UnicodeEncodeError: 'ascii' ... | https://stackoverflow.com/questions/16923281/writing-a-pandas-dataframe-to-csv-file |
Question: <p>Is there a way to widen the display of output in either interactive or script-execution mode?</p>
<p>Specifically, I am using the <code>describe()</code> function on a Pandas <code>DataFrame</code>. When the <code>DataFrame</code> is five columns (labels) wide, I get the descriptive statistics that I want... | https://stackoverflow.com/questions/11707586/how-do-i-expand-the-output-display-to-see-more-columns-of-a-pandas-dataframe |
Question: <p>I'm starting from the pandas DataFrame documentation here: <em><a href="http://pandas.pydata.org/pandas-docs/stable/dsintro.html" rel="noreferrer">Introduction to data structures</a></em></p>
<p>I'd like to iteratively fill the DataFrame with values in a time series kind of calculation. I'd like to initial... | https://stackoverflow.com/questions/13784192/creating-an-empty-pandas-dataframe-and-then-filling-it |
Question: <p>I have the following DataFrame:</p>
<pre class="lang-none prettyprint-override"><code> daysago line_race rating rw wrating
line_date
2007-03-31 62 11 56 1.000000 56.000000
2007-03-10 83 11 67 1.0... | https://stackoverflow.com/questions/18172851/deleting-dataframe-row-in-pandas-based-on-column-value |
Question: <p>I have a dataframe that looks like</p>
<pre class="lang-none prettyprint-override"><code>Year quarter
2000 q2
2001 q3
</code></pre>
<p>How do I add a new column by combining these columns to get the following dataframe?</p>
<pre class="lang-none prettyprint-override"><code>Year quarter perio... | https://stackoverflow.com/questions/19377969/combine-two-columns-of-text-in-pandas-dataframe |
Question: <p>Can someone explain how these two methods of slicing are different? I've seen <a href="https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html" rel="noreferrer">the docs</a>
and I've seen previous similar questions (<a href="https://stackoverflow.com/questions/28757389/loc-vs-iloc-vs-ix-vs-at... | https://stackoverflow.com/questions/31593201/how-are-iloc-and-loc-different |
Question: <p>I want to find the number of <code>NaN</code> in each column of my data.</p>
Answer: <p>Use the <a href="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.isna.html" rel="noreferrer"><code>isna()</code></a> method (or it's alias <code>isnull()</code> which is also compatible with older pandas ... | https://stackoverflow.com/questions/26266362/how-do-i-count-the-nan-values-in-a-column-in-pandas-dataframe |
Question: <p>I have a pandas DataFrame and I want to delete rows from it where the length of the string in a particular column is greater than 2.</p>
<p>I expect to be able to do this (per <a href="https://stackoverflow.com/questions/11881165/slice-pandas-dataframe-by-row">this answer</a>):</p>
<pre><code>df[(len(df[... | https://stackoverflow.com/questions/13851535/how-to-delete-rows-from-a-pandas-dataframe-based-on-a-conditional-expression |
Question: <ul>
<li>How can I perform a (<code>INNER</code>| (<code>LEFT</code>|<code>RIGHT</code>|<code>FULL</code>) <code>OUTER</code>) <code>JOIN</code> with pandas?</li>
<li>How do I add NaNs for missing rows after a merge?</li>
<li>How do I get rid of NaNs after merging?</li>
<li>Can I merge on the index?</li>
<li>... | https://stackoverflow.com/questions/53645882/pandas-merging-101 |
Question: <p>I have a pandas DataFrame with a column of string values. I need to select rows based on partial string matches.</p>
<p>Something like this idiom:</p>
<pre class="lang-py prettyprint-override"><code>re.search(pattern, cell_in_question)
</code></pre>
<p>returning a boolean. I am familiar with the syntax of... | https://stackoverflow.com/questions/11350770/filter-pandas-dataframe-by-substring-criteria |
Question: <p>How can I achieve the equivalents of SQL's <code>IN</code> and <code>NOT IN</code>?</p>
<p>I have a list with the required values. Here's the scenario:</p>
<pre class="lang-py prettyprint-override"><code>df = pd.DataFrame({'country': ['US', 'UK', 'Germany', 'China']})
countries_to_keep = ['UK', 'China']
#... | https://stackoverflow.com/questions/19960077/how-to-filter-pandas-dataframe-using-in-and-not-in-like-in-sql |
Question: <p>I want to filter my dataframe with an <code>or</code> condition to keep rows with a particular column's values that are outside the range <code>[-0.25, 0.25]</code>. I tried:</p>
<pre><code>df = df[(df['col'] < -0.25) or (df['col'] > 0.25)]
</code></pre>
<p>But I get the error:</p>
<blockquote>
<p>Va... | https://stackoverflow.com/questions/36921951/truth-value-of-a-series-is-ambiguous-use-a-empty-a-bool-a-item-a-any-o |
Question: <p>I have the following DataFrame:</p>
<pre><code> Col1 Col2 Col3 Type
0 1 2 3 1
1 4 5 6 1
...
20 7 8 9 2
21 10 11 12 2
...
45 13 14 15 3
46 16 17 18 3
...
</code></pre>
<p>The DataFrame is read from a CSV file. All... | https://stackoverflow.com/questions/29576430/shuffle-dataframe-rows |
Question: <p>I'm trying to use pandas to manipulate a .csv file but I get this error:</p>
<blockquote>
<p>pandas.parser.CParserError: Error tokenizing data. C error: Expected 2 fields in line 3, saw 12</p>
</blockquote>
<p>I have tried to read the pandas docs, but found nothing.</p>
<p>My code is simple:</p>
<pre><cod... | https://stackoverflow.com/questions/18039057/pandas-parser-cparsererror-error-tokenizing-data |
Question: <p>I have two variables as follows.</p>
<pre class="lang-py prettyprint-override"><code>a = 2
b = 3
</code></pre>
<p>I want to construct a DataFrame from this:</p>
<pre class="lang-py prettyprint-override"><code>df2 = pd.DataFrame({'A':a, 'B':b})
</code></pre>
<p>This generates an error:</p>
<pre class="lang-... | https://stackoverflow.com/questions/17839973/constructing-dataframe-from-values-in-variables-yields-valueerror-if-using-all |
Question: <p>How to convert an index of a dataframe into a column?</p>
<p>For example:</p>
<pre class="lang-none prettyprint-override"><code> gi ptt_loc
0 384444683 593
1 384444684 594
2 384444686 596
</code></pre>
<p>to</p>
<pre class="lang-none prettyprint-override"><code> in... | https://stackoverflow.com/questions/20461165/how-to-convert-index-of-a-pandas-dataframe-into-a-column |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.