RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 3.82 GiB total capacity; 2.20 GiB already allocated; 27.88 MiB free; 2.32 GiB reserved in total by PyTorch)
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
调研方向
从 test_torch_encoding.py 开始,沿着 encoding/models/sseg/base.py、encoding/models/sseg/deeplab.py 以及 traceback 中显示的 ResNet 路径跟踪失败的调用。使用指定的模型和 GPU 重现报告的 CUDA out-of-memory 错误,然后确定此入口点是否支持 batch_size,以及应将何种行为视为已解决。
由索引模型根据 Issue 内容生成。
描述
How can I pass the batch_size to an script that is making use of encoding python package?
(torchenc) mona@goku:~$ python test_torch_encoding.py --batch_size 8
Traceback (most recent call last):
File "test_torch_encoding.py", line 15, in <module>
output = model.evaluate(img)
File "/home/mona/venv/torchenc/lib/python3.8/site-packages/torch_encoding-1.2.2b20210130-py3.8-linux-x86_64.egg/encoding/models/sseg/base.py", line 101, in evaluate
pred = self.forward(x)
File "/home/mona/venv/torchenc/lib/python3.8/site-packages/torch_encoding-1.2.2b20210130-py3.8-linux-x86_64.egg/encoding/models/sseg/deeplab.py", line 47, in forward
c1, c2, c3, c4 = self.base_forward(x)
File "/home/mona/venv/torchenc/lib/python3.8/site-packages/torch_encoding-1.2.2b20210130-py3.8-linux-x86_64.egg/encoding/models/sseg/base.py", line 96, in base_forward
c3 = self.pretrained.layer3(c2)
File "/home/mona/venv/torchenc/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/mona/venv/torchenc/lib/python3.8/site-packages/torch/nn/modules/container.py", line 117, in forward
input = module(input)
File "/home/mona/venv/torchenc/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/mona/venv/torchenc/lib/python3.8/site-packages/torch_encoding-1.2.2b20210130-py3.8-linux-x86_64.egg/encoding/models/backbone/resnet.py", line 95, in forward
out = self.conv2(out)
File "/home/mona/venv/torchenc/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/mona/venv/torchenc/lib/python3.8/site-packages/torch_encoding-1.2.2b20210130-py3.8-linux-x86_64.egg/encoding/nn/splat.py", line 50, in forward
x = self.bn0(x)
File "/home/mona/venv/torchenc/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/mona/venv/torchenc/lib/python3.8/site-packages/torch/nn/modules/batchnorm.py", line 131, in forward
return F.batch_norm(
File "/home/mona/venv/torchenc/lib/python3.8/site-packages/torch/nn/functional.py", line 2056, in batch_norm
return torch.batch_norm(
RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 3.82 GiB total capacity; 2.20 GiB already allocated; 27.88 MiB free; 2.32 GiB reserved in total by PyTorch)
code is:
(torchenc) mona@goku:~$ cat test_torch_encoding.py
import torch
import encoding
# Get the model
model = encoding.models.get_model('DeepLab_ResNeSt269_PContext', pretrained=True).cuda()
model.eval()
# Prepare the image
url = 'https://github.com/zhanghang1989/image-data/blob/master/' + \
'encoding/segmentation/pcontext/2010_001829_org.jpg?raw=true'
filename = 'example.jpg'
img = encoding.utils.load_image(encoding.utils.download(url, filename)).cuda().unsqueeze(0)
# Make prediction
output = model.evaluate(img)
predict = torch.max(output, 1)[1].cpu().numpy() + 1
# Get color pallete for visualization
mask = encoding.utils.get_mask_pallete(predict, 'pascal_voc')
mask.save('output.png')
I am not sure how you pass batch_size to code but I just followed https://github.com/zhanghang1989/PyTorch-Encoding/issues/224 would your code work at all with a GeForce 1650 Ti GPU?
Thanks a lot for your help.
- I get the error even with batch size of 1:
(torchenc) mona@goku:~$ python test_torch_encoding.py --batch_size 1
- 主要语言
- Python
- 星标
- 2k
- 派生
- 448
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
zhanghang1989/PyTorch-Encoding 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 30/100
zhanghang1989/PyTorch-Encoding#432 · 2 条评论 ·
-
难度 3/5 1-2 天 新手友好度 25/100
zhanghang1989/PyTorch-Encoding#430 · 3 条评论 · 2 个 reaction ·
-
,未关闭
难度 5/5 一周以上 新手友好度 1/100
-
难度 4/5 3-5 天 新手友好度 25/100
-
难度 4/5 3-5 天 新手友好度 25/100
zhanghang1989/PyTorch-Encoding#426 · 1 条评论 ·
查看 zhanghang1989/PyTorch-Encoding 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 85/100
Vector35/community-plugins#376 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
py-econometrics/pyfixest#1883 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
ietf-tools/rfc2html#81 ·
-
难度 1/5 1 小时以内 新手友好度 88/100
mysql/mysql-operator#60 ·
-
Python: Bug: split_plaintext_paragraph / split_markdown_paragraph can return a chunk larger than max_tokens可能已有人在做 @xThreeh 今天认领。 未关闭python triage
难度 2/5 1-3 小时 新手友好度 75/100
microsoft/semantic-kernel#14566 ·
维护者通常 4 天内回复