python - 调整 RGB 张量的大小
问题描述
我想在 pytorch 中调整 3-D RBG 张量的大小。我知道如何调整 4-D 张量的大小,但不幸的是,这种方法不适用于 3-D。
输入是:
#input shape: [3, 100, 200] ---> desired output shape: [3, 80, 120]
如果我有一个 4-D 矢量它工作正常。
#input shape: [2, 3, 100, 200]
out = torch.nn.functional.interpolate(T,size=(100,80), mode='bilinear')
有什么建议么?提前致谢!
解决方案
感谢jodag,我找到了答案:
# input shape [3, 200, 120]
T = T.unsqueeze(0)
T = torch.nn.functional.interpolate(T,size=(100,80), mode='bilinear')
T = T.squeeze(0)
# output shape [3, 100, 80]
推荐阅读
- mysql - 在 SQL 中显示满足条件的结果
- java - 用于拆分数字 ID 的正则表达式(java)
- python - Python 和 Django 时区格式 Postgres
- node.js - joi 验证模式:值可能有多种长度
- c# - DirectX C# SolidBrush 绘制白色
- swift - 感受“对速度的需求” 使用 reduce(into:_:) 计算封闭数组中的三元组元素
- postgresql - 使用两个字典创建全文搜索配置
- python - 使用雪花连接器和 COPY INTO 功能将 csv 上传到雪花时如何指定分隔符
- javascript - 嵌套数组的深度过滤
- r - 如何在 R 中解析文件并更改字符串