Try to translate MXNet architecture to Pytorch

username: chandra_sutrisno
cooked: <p>Hi member,</p>
<p>I am trying to translate a Resnet modified model architecture written on Mxnet to Pytorch. Below is the architecture:</p>
<blockquote>
<p>SegmentationNetwork(<br>
(cnn): HybridSequential(<br>
(0): Conv2D(1 → 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)<br>
(1): BatchNorm(axis=1, eps=1e-05, momentum=0.9, fix_gamma=False, use_global_stats=False, in_channels=64)<br>
(2): Activation(relu)<br>
(3): MaxPool2D(size=(3, 3), stride=(2, 2), padding=(1, 1), ceil_mode=False, global_pool=False, pool_type=max, layout=NCHW)<br>
(4): HybridSequential(<br>
(0): BasicBlockV1(<br>
(body): HybridSequential(<br>
(0): Conv2D(64 → 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(1): BatchNorm(axis=1, eps=1e-05, momentum=0.9, fix_gamma=False, use_global_stats=False, in_channels=64)<br>
(2): Activation(relu)<br>
(3): Conv2D(64 → 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(4): BatchNorm(axis=1, eps=1e-05, momentum=0.9, fix_gamma=False, use_global_stats=False, in_channels=64)<br>
)<br>
)<br>
(1): BasicBlockV1(<br>
(body): HybridSequential(<br>
(0): Conv2D(64 → 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(1): BatchNorm(axis=1, eps=1e-05, momentum=0.9, fix_gamma=False, use_global_stats=False, in_channels=64)<br>
(2): Activation(relu)<br>
(3): Conv2D(64 → 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(4): BatchNorm(axis=1, eps=1e-05, momentum=0.9, fix_gamma=False, use_global_stats=False, in_channels=64)<br>
)<br>
)<br>
(2): BasicBlockV1(<br>
(body): HybridSequential(<br>
(0): Conv2D(64 → 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(1): BatchNorm(axis=1, eps=1e-05, momentum=0.9, fix_gamma=False, use_global_stats=False, in_channels=64)<br>
(2): Activation(relu)<br>
(3): Conv2D(64 → 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(4): BatchNorm(axis=1, eps=1e-05, momentum=0.9, fix_gamma=False, use_global_stats=False, in_channels=64)<br>
)<br>
)<br>
)<br>
(5): HybridSequential(<br>
(0): BasicBlockV1(<br>
(body): HybridSequential(<br>
(0): Conv2D(64 → 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)<br>
(1): BatchNorm(axis=1, eps=1e-05, momentum=0.9, fix_gamma=False, use_global_stats=False, in_channels=128)<br>
(2): Activation(relu)<br>
(3): Conv2D(128 → 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(4): BatchNorm(axis=1, eps=1e-05, momentum=0.9, fix_gamma=False, use_global_stats=False, in_channels=128)<br>
)<br>
(downsample): HybridSequential(<br>
(0): Conv2D(64 → 128, kernel_size=(1, 1), stride=(2, 2), bias=False)<br>
(1): BatchNorm(axis=1, eps=1e-05, momentum=0.9, fix_gamma=False, use_global_stats=False, in_channels=128)<br>
)<br>
)<br>
(1): BasicBlockV1(<br>
(body): HybridSequential(<br>
(0): Conv2D(128 → 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(1): BatchNorm(axis=1, eps=1e-05, momentum=0.9, fix_gamma=False, use_global_stats=False, in_channels=128)<br>
(2): Activation(relu)<br>
(3): Conv2D(128 → 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(4): BatchNorm(axis=1, eps=1e-05, momentum=0.9, fix_gamma=False, use_global_stats=False, in_channels=128)<br>
)<br>
)<br>
(2): BasicBlockV1(<br>
(body): HybridSequential(<br>
(0): Conv2D(128 → 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(1): BatchNorm(axis=1, eps=1e-05, momentum=0.9, fix_gamma=False, use_global_stats=False, in_channels=128)<br>
(2): Activation(relu)<br>
(3): Conv2D(128 → 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(4): BatchNorm(axis=1, eps=1e-05, momentum=0.9, fix_gamma=False, use_global_stats=False, in_channels=128)<br>
)<br>
)<br>
(3): BasicBlockV1(<br>
(body): HybridSequential(<br>
(0): Conv2D(128 → 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(1): BatchNorm(axis=1, eps=1e-05, momentum=0.9, fix_gamma=False, use_global_stats=False, in_channels=128)<br>
(2): Activation(relu)<br>
(3): Conv2D(128 → 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(4): BatchNorm(axis=1, eps=1e-05, momentum=0.9, fix_gamma=False, use_global_stats=False, in_channels=128)<br>
)<br>
)<br>
)<br>
(6): HybridSequential(<br>
(0): Flatten<br>
(1): Dense(None → 64, Activation(relu))<br>
(2): Dropout(p = 0.5, axes=())<br>
(3): Dense(None → 64, Activation(relu))<br>
(4): Dropout(p = 0.5, axes=())<br>
(5): Dense(None → 4, Activation(sigmoid))<br>
)<br>
)<br>
)</p>
</blockquote>
<p>I can understand the architecture but the last block quite confusing.</p>
<blockquote>
<p>(6): HybridSequential(<br>
(0): Flatten<br>
(1): Dense(None → 64, Activation(relu))<br>
(2): Dropout(p = 0.5, axes=())<br>
(3): Dense(None → 64, Activation(relu))<br>
(4): Dropout(p = 0.5, axes=())<br>
(5): Dense(None → 4, Activation(sigmoid))<br>
)</p>
</blockquote>
<p>How to translate <strong>None</strong> as an input to Pytorch nn.Linear? It is the input dimension as I know but how come input has None dimension? The other one is the downsampling part:</p>
<blockquote>
<p>(downsample): HybridSequential(<br>
(0): Conv2D(64 → 128, kernel_size=(1, 1), stride=(2, 2), bias=False)<br>
(1): BatchNorm(axis=1, eps=1e-05, momentum=0.9, fix_gamma=False, use_global_stats=False, in_channels=128)<br>
)</p>
</blockquote>
<p>The previous block is</p>
<blockquote>
<p>(body): HybridSequential(<br>
(0): Conv2D(64 → 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)<br>
(1): BatchNorm(axis=1, eps=1e-05, momentum=0.9, fix_gamma=False, use_global_stats=False, in_channels=128)<br>
(2): Activation(relu)<br>
(3): Conv2D(128 → 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(4): BatchNorm(axis=1, eps=1e-05, momentum=0.9, fix_gamma=False, use_global_stats=False, in_channels=128)<br>
)</p>
</blockquote>
<p>How come the input to the downsampling block is not same as the output from the previous block?</p>
<p>and below is the scrrpt used to produce the last block:</p>
<blockquote>
<p>output.add(gluon.nn.Flatten())<br>
output.add(gluon.nn.Dense(64, activation=‘relu’))<br>
output.add(gluon.nn.Dropout(p_dropout))<br>
output.add(gluon.nn.Dense(64, activation=‘relu’))<br>
output.add(gluon.nn.Dropout(p_dropout))<br>
output.add(gluon.nn.Dense(4, activation=‘sigmoid’))</p>
</blockquote>
<p>Please advise</p>