【发布时间】:2022-12-15 03:26:03
【问题描述】:
我有一个 sequential 容器,我想在里面使用 Tensor.view 函数。因此,我当前的解决方案如下所示:
class Reshape(nn.Module):
def __init__(self, *args):
super().__init__()
self.my_shape = args
def forward(self, x):
return x.view(self.my_shape)
在我的AutoEncoder课上我有:
self.decoder = nn.Sequential(
torch.nn.Linear(self.bottleneck_size, 4096*2),
Reshape(-1, 128, 8, 8),
nn.UpsamplingNearest2d(scale_factor=2),
...
有没有办法直接在 sequential 块中重塑张量,这样我就不需要使用外部创建的 Reshape 类?
谢谢
【问题讨论】:
标签: python machine-learning pytorch autoencoder