【发布时间】:2019-01-04 02:26:26
【问题描述】:
我正在尝试制作一个渐进式自动编码器,并且我想了几种在训练期间扩展我的网络的方法。但是,我总是卡在这一部分,我不知道更改输入(编码器)和输出(解码器)通道是否会影响我的网络。请参阅下面的示例。
X = torch.randn( 8, 1, 4, 4,) # A batch of 8 grayscale images of 4x4 pixels in size
Encoder = nn.Sequential( Conv2D( 1, 16, 3, 1, 1 ), nn.ReLU() ) # starting setup 16 3x3 kernels
如果我从网络打印上述权重,我会得到 [1, 16, 3, 3] 的大小,每个大小为 3x3 的 16 个内核 如果我想扩大网络,我需要节省这些权重,因为希望它已经在那些 4x4 图像输入上训练有素。
X = torch.randn( 8, 1, 8, 8) # increase the image size from 4x4 to 8x8
...
new_model = nn.Sequential()
then do...
# copy the previous layer and its weights from the original encoder
# BTW My issue starts here.
# Add/grow the new_model with new layers concat with the old layer, also modify the input channela so they can link correctly
# Final result would be like something below.
new_model = nn.Sequential( Conv2D( **1**, 8, 3, 1, 1 ), nn.ReLU(), Conv2D( **8**, 16, 3, 1, 1 ), nn.ReLU() )
Encoder = new_model
# Repeat process
一切看起来都不错,但是因为我更改了输入通道,权重的大小也发生了变化,这是我一直坚持一段时间的问题。您可以通过运行简单地检查这一点,
foo_1 = nn.Conv2d(1, 1, 3, 1, 1) # You can think this as the starting Conv2D from the starting encoder
foo_2 = nn.Conv2d(3, 1, 3, 1, 1) # You can think this as the modfiied starting Conv2D with an outer layer outputting 3 channels connecting to it
print(foo_1.weight.size()) # torch.Size([1, 1, 3, 3])
print(foo_2.weight.size()) # torch.Size([1, 3, 3, 3])
最初,我认为 foo_1 和 foo_2 的权重大小相同,因为两者都只使用一个 3x3 内核,但事实并非如此。我希望你现在能看到我的困境,经过 x 个时期后,我需要增加另一个卷积,我必须弄乱输入大小才能正确地制作新层链,但是如果我改变输入大小,权重的形状会有所不同并且我不知道如何粘贴旧状态。
我一直在研究 pytorch 和 IMO 中的 pro gan 实现,它们不容易阅读。我如何建立更多机构来正确逐步发展您的网络?
【问题讨论】:
标签: python machine-learning conv-neural-network pytorch autoencoder