我正在尝试在我的Mac上安装Torch7,但此时安装暂停:
Not updating your shell profile.
You might want to
add the following lines to your shell profile:
export PATH=/Users/khsiddiqui/torch/install/bin:$PATH
export LD_LIBRARY_PATH=/Users/khsiddiqui/torch/install/lib:$LD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=/Users/khsiddiqui/torch/install/lib:$DYLD_LIBRARY_PATH
Run Code Online (Sandbox Code Playgroud)
不确定这意味着什么.上面我收到了以下输出
echo "Error: could not find ipython in PATH. Do you have it installed?"
fi
Run Code Online (Sandbox Code Playgroud)
但是我安装了iPython,因为我可以确认:
No update necessary, 'ipython' is up-to-date.
ipython-3.0.0-3.egg was installed on: Thu Apr 9 18:12:32 2015
kamransiquisMBP:torch khsiddiqui$ env | grep PATH
PATH=/Users/khsiddiqui/Library/Enthought/Canopy_64bit/User/bin:
/usr/local/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/opt/X11/bin:
/usr/texbin
Run Code Online (Sandbox Code Playgroud)
试图找到.bashrc文件
%edit .bashrc
WARNING: Argument given (.bashrc) can't be found as …Run Code Online (Sandbox Code Playgroud) 我有一个列向量,我想将其转换为行向量,但在执行此操作时出现以下错误。有没有办法在火炬中转置一维向量
th> bb
1
2
[torch.DoubleTensor of size 2]
[0.0005s]
th> bb:t()
[string "_RESULT={bb:t()}"]:1: calling 't' on bad self (Tensor must have 2 dimensions at /tmp/luarocks_torch-scm-1-5379/torch7/generic/Tensor.c:590)
stack traceback:
[C]: in function 't'
[string "_RESULT={bb:t()}"]:1: in main chunk
[C]: in function 'xpcall'
Run Code Online (Sandbox Code Playgroud) 我正在使用带有一些语义分割算法的 Torch 来生成分割图像的二进制掩码。然后我想根据该掩码裁剪图像。为了清楚起见,我需要在每个像素的基础上裁剪它。这似乎是一个简单的问题,但我能想到的唯一解决方案是反转draw maskCoco API 中的函数,或者迭代数组中的每个像素,并在不需要时将像素设置为黑色。我觉得有更好的方法可以做到这一点。Lua、Python、Go 或 C++ 中的库对我有用。有任何想法吗?
当我在主函数的这一行中调用 pytorch 中的 Network.parameters() 时出现问题:optimizer = optim.SGD(Network.parameters(), lr=0.001,momentum=0.9)
我得到错误代码:
TypeError: parameters() missing 1 required positional argument: 'self'
我的网络在这个类中定义
class Network(nn.Module):
def __init__(self):
super(Network, self).__init__()
self.conv1 = nn.Conv2d(1, 32, 5)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(32, 64, 5)
self.pool2 = nn.MaxPool2d(2, 2)
self.conv3 = nn.Conv2d(64, 64, 5)
self.pool2 = nn.MaxPool2d(2, 2)
self.fc1 = nn.Linear(64 * 5 * 5, 512)
self.fc2 = nn.Linear(512, 640)
self.fc3 = nn.Linear(640, 3756)
def forward(self, x):
x = self.pool(F.relu(self.conv(x)))
x = self.pool(F.relu(self.conv2(x)))
x = self.pool(F.relu(self.conv3(x)))
x …Run Code Online (Sandbox Code Playgroud) 遵循https://github.com/spro/practical-pytorch/blob/master/seq2seq-translation/seq2seq-translation.ipynb的教程
有一个USE_CUDA标志用于控制 CPU(当为 False)到 GPU(当为 True)类型之间的变量和张量类型。
使用en-fr.tsv 中的数据并将句子转换为变量:
import unicodedata
import string
import re
import random
import time
import math
from gensim.corpora.dictionary import Dictionary
import torch
import torch.nn as nn
from torch.autograd import Variable
from torch import LongTensor, FloatTensor
from torch import optim
import torch.nn.functional as F
import numpy as np
MAX_LENGTH = 10
USE_CUDA = False
# Turn a Unicode string to plain ASCII, thanks to http://stackoverflow.com/a/518232/2809427
def unicode_to_ascii(s):
return ''.join(
c for …Run Code Online (Sandbox Code Playgroud) 也许有人能够在这里帮助我.我正在尝试计算网络给定输出的交叉熵损失
print output
Variable containing:
1.00000e-02 *
-2.2739 2.9964 -7.8353 7.4667 4.6921 0.1391 0.6118 5.2227 6.2540
-7.3584
[torch.FloatTensor of size 1x10]
Run Code Online (Sandbox Code Playgroud)
和所需的标签,形式
print lab
Variable containing:
x
[torch.FloatTensor of size 1]
Run Code Online (Sandbox Code Playgroud)
其中x是0到9之间的整数.根据pytorch文档(http://pytorch.org/docs/master/nn.html)
criterion = nn.CrossEntropyLoss()
loss = criterion(output, lab)
Run Code Online (Sandbox Code Playgroud)
这应该工作,但不幸的是我得到一个奇怪的错误
TypeError: FloatClassNLLCriterion_updateOutput received an invalid combination of arguments - got (int, torch.FloatTensor, !torch.FloatTensor!, torch.FloatTensor, bool, NoneType, torch.FloatTensor, int), but expected (int state, torch.FloatTensor input, torch.LongTensor target, torch.FloatTensor output, bool sizeAverage, [torch.FloatTensor weights or None], torch.FloatTensor total_weight, int ignore_index) …Run Code Online (Sandbox Code Playgroud) 我正在研究PyTorch的基本教程,并遇到了NumPy数组和Torch张量之间的转换。该文件说:
Torch Tensor和NumPy数组将共享其基础内存位置,并且更改一个将更改另一个。
但是,以下代码似乎并非如此:
import numpy as np
a = np.ones((3,3))
b = torch.from_numpy(a)
np.add(a,1,out=a)
print(a)
print(b)
Run Code Online (Sandbox Code Playgroud)
在上述情况下,我看到更改自动反映在输出中:
[[2. 2. 2.]
[2. 2. 2.]
[2. 2. 2.]]
tensor([[2., 2., 2.],
[2., 2., 2.],
[2., 2., 2.]], dtype=torch.float64)
Run Code Online (Sandbox Code Playgroud)
但是当我写这样的东西时,不会发生同样的事情:
a = np.ones((3,3))
b = torch.from_numpy(a)
a = a + 1
print(a)
print(b)
Run Code Online (Sandbox Code Playgroud)
我得到以下输出:
[[2. 2. 2.]
[2. 2. 2.]
[2. 2. 2.]]
tensor([[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]], dtype=torch.float64)
Run Code Online (Sandbox Code Playgroud)
我在这里想念什么?
是否可以torch.utils.data.random_split()在拆分数据集时修复种子,以便可以重现测试结果?
我想降级我的 Google Colab 笔记本中使用的 Torch 版本。我怎么能那样做?
我打算在虚拟环境中安装火炬。所以我命令 !pip install torch,但有一个错误。
Collecting torch
Using cached torch-1.7.0-cp37-cp37m-win_amd64.whl(184.0 MB)
ERROR: torch ahs an invalid wheel, .dist-info directory not found
Run Code Online (Sandbox Code Playgroud)
在如何修复我的包中的“.dist-info 目录未找到”?在这里,一个答案说删除 Appdata/Local/pip/Cache flder 是有效的。
我该怎么办?