我正在尝试运行来自 GitHub 的动作识别代码。原始代码使用 4 个 GPU 的批处理大小 128。我只有两个 GPU,所以我无法匹配它们的 bacth 大小。无论如何,我可以批量补偿这种差异吗?我在某处看到 iter_size 可能会根据公式进行补偿effective_batchsize= batch_size*iter_size*n_gpu
。这个公式中的 iter_size 是多少?我使用 PYthorch 而不是 Caffe。
artificial-intelligence neural-network deep-learning pytorch
作为 pytorch 框架(0.4.1)中的练习,我尝试在简单的线性层(Z = XW + B)中显示 X(gX 或 dSdX)的梯度。为了简化我的玩具示例,我从 Z 之和(不是损失)向后()。
综上所述,我想要 S=sum(XW+B) 的 gX(dSdX)。
问题是 Z (dSdZ) 的梯度为 None。结果,gX 当然也是错误的。
import torch
X = torch.tensor([[0.5, 0.3, 2.1], [0.2, 0.1, 1.1]], requires_grad=True)
W = torch.tensor([[2.1, 1.5], [-1.4, 0.5], [0.2, 1.1]])
B = torch.tensor([1.1, -0.3])
Z = torch.nn.functional.linear(X, weight=W.t(), bias=B)
S = torch.sum(Z)
S.backward()
print("Z:\n", Z)
print("gZ:\n", Z.grad)
print("gX:\n", X.grad)
Run Code Online (Sandbox Code Playgroud)
结果:
Z:
tensor([[2.1500, 2.9100],
[1.6000, 1.2600]], grad_fn=<ThAddmmBackward>)
gZ:
None
gX:
tensor([[ 3.6000, -0.9000, 1.3000],
[ 3.6000, -0.9000, 1.3000]])
Run Code Online (Sandbox Code Playgroud)
如果我使用 …
import PIL as Image
Image.fromarray(cv2.imread(link, cv2.IMREAD_GRAYSCALE))
Run Code Online (Sandbox Code Playgroud)
我目前正在尝试完成一个项目,但我的 Linux GPU 服务器上不断出现太多文件打开错误,导致服务器崩溃。
我正在使用如上所示的代码加载 3 个图像以进行 CNN 分类。任何面临同样问题的人都有解决方案吗?
谢谢。
我在运行facebookresearch的maskrcnn-benchmark官方代码时遇到的问题,加载预训练模型时出错。
该代码在学校的远程服务器上运行,显卡是 NVIDIA P100。
checkpointer = DetectronCheckpointer(cfg,模型,优化器,调度程序,output_dir,save_to_disk)extra_checkpoint_data = checkpointer.load(cfg.MODEL.WEIGHT)arguments.update(extra_checkpoint_data)
我希望能够正确运行代码并理解为什么会出现这个问题。
在训练时,最好初始化隐藏状态而不是将其设置为 0。但我想知道在验证和测试时初始化隐藏状态是好是坏。谢谢
class loss(Function):
@staticmethod
def forward(ctx,x,INPUT):
batch_size = x.shape[0]
X = x.detach().numpy()
input = INPUT.detach().numpy()
Loss = 0
for i in range(batch_size):
t_R_r = input[i,0:4]
R_r = t_R_r[np.newaxis,:]
t_R_i = input[i,4:8]
R_i = t_R_i[np.newaxis,:]
t_H_r = input[i,8:12]
H_r = t_H_r[np.newaxis,:]
t_H_i = input[i,12:16]
H_i = t_H_i[np.newaxis,:]
t_T_r = input[i, 16:32]
T_r = t_T_r.reshape(4,4)
t_T_i = input[i, 32:48]
T_i = t_T_i.reshape(4,4)
R = np.concatenate((R_r, R_i), axis=1)
H = np.concatenate((H_r, H_i), axis=1)
temp_t1 = np.concatenate((T_r,T_i),axis=1)
temp_t2 = np.concatenate((-T_i,T_r),axis=1)
T = np.concatenate((temp_t1,temp_t2),axis=0)
phi_r = …
Run Code Online (Sandbox Code Playgroud) 我在配备 Nvidia Quadro P5200 的 Lenovo Thinkpad P72 上安装了 Windows 10,并且我绝对需要安装 (py)torch v0.4.1 才能使用3D Mask R-CNN。所以我尝试了以下链接:\n https://github.com/pytorch/pytorch/issues/19457
\n\n但是,当我完成“python setup.py install”时,我得到:
\n\nC:\\Users\\...\\pytorch-0.4.1\\build>msbuild INSTALL.vcxproj /p:Configuration=Release\nMicrosoft (R) Build Engine, version 4.8.3752.0\n[Microsoft .NET Framework, Version 4.0.30319.42000]\nCopyright (C) Microsoft Corporation. Tous droits r\xc3\xa9serv\xc3\xa9s.\n\nLa g\xc3\xa9n\xc3\xa9ration a d\xc3\xa9marr\xc3\xa9 31/03/2020 07:03:00.\nProjet "C:\\Users\\...\\pytorch-0.4.1\\build\\INSTALL.vcxproj" sur le noud 1 (cibles par d\xc3\xa9faut).\nC:\\Users\\...\\pytorch-0.4.1\\build\\INSTALL.vcxproj(32,3): error MSB4019: Le projet import\xc3\xa9 "C:\\Microsoft.Cpp.Default.props" est introuvable. V\xc3\xa9rifiez que le chemin d\'acc\xc3\xa8s dans la d\xc3\xa9claration <Import> est correct et que le fichier existe sur le …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Huggingface 的 BertModel 和 Pytorch 开发一个二元分类器。\n分类器模块是这样的:
\n\nclass SSTClassifierModel(nn.Module):\n\n def __init__(self, num_classes = 2, hidden_size = 768):\n super(SSTClassifierModel, self).__init__()\n self.number_of_classes = num_classes\n self.dropout = nn.Dropout(0.01)\n self.hidden_size = hidden_size\n self.bert = BertModel.from_pretrained(\'bert-base-uncased\')\n self.classifier = nn.Linear(hidden_size, num_classes)\n\n def forward(self, input_ids, att_masks,token_type_ids, labels):\n _, embedding = self.bert(input_ids, token_type_ids, att_masks)\n output = self.classifier(self.dropout(embedding))\n return output\n
Run Code Online (Sandbox Code Playgroud)\n\n我训练模型的方式如下:
\n\nloss_function = BCELoss()\nmodel.train()\nfor epoch in range(NO_OF_EPOCHS):\n for step, batch in enumerate(train_dataloader):\n input_ids = batch[0].to(device)\n input_mask = batch[1].to(device)\n token_type_ids = batch[2].to(device)\n labels = batch[3].to(device)\n # assuming …
Run Code Online (Sandbox Code Playgroud) python cross-entropy pytorch python-3.7 huggingface-transformers
我看到似乎有更多人有同样的问题,但没有解决。我正在尝试使用 Anaconda 安装Pytorch3D并收到以下 PackageNotFound 错误。
Collecting package metadata (current_repodata.json): done Solving environment: failed with initial frozen solve. Retrying with flexible solve. Collecting package metadata (repodata.json): done Solving environment: failed with initial frozen solve. Retrying with flexible solve.
PackagesNotFoundError: The following packages are not available from current channels:
- pytorch3d
Current channels:
- https://conda.anaconda.org/pytorch3d/win-64
- https://conda.anaconda.org/pytorch3d/noarch
- https://repo.anaconda.com/pkgs/main/win-64
- https://repo.anaconda.com/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/r/win-64
- https://repo.anaconda.com/pkgs/r/noarch
- https://repo.anaconda.com/pkgs/msys2/win-64
- https://repo.anaconda.com/pkgs/msys2/noarch
To search for alternate channels that may provide the conda package …
Run Code Online (Sandbox Code Playgroud) 看起来 pytorch 的 Transformer 层无法提供可重现的输出。cpu和gpu都会出现这种情况。我知道有时会因为 GPU 上的并行计算而发生这种情况。
emb = nn.Embedding(10, 12).to(device)
inp1 = torch.LongTensor([1, 2, 3, 4]).to(device)
inp1 = emb(inp1).reshape(inp1.shape[0], 1, 12) #S N E
encoder_layer = nn.TransformerEncoderLayer(d_model=12, nhead=4)
transformer_encoder = nn.TransformerEncoder(encoder_layer, num_layers=4)
out1 = transformer_encoder(inp1)
out2 = transformer_encoder(inp1)
Run Code Online (Sandbox Code Playgroud)
out1 和 out2 不同。它可以在 cpu 上进行多处理,但结果看起来太不稳定。如何解决这个问题?
pytorch ×10
python ×3
anaconda ×1
installation ×1
lstm ×1
pip ×1
python-3.7 ×1
python-3.x ×1
pytorch3d ×1
torch ×1
windows ×1