Using affine_grid and grid_sample on intermediate output

Can the methods affine_grid and grid_sample be used inside the forward method of a network?
The forward pass looks like this

def forward(self, x):
        x = self.conv1(x)
        x = self.bn1(x)
        x = self.relu(x)
        x = self.maxpool(x)

        x = self.layer1(x)
        x = self.layer2(x)
        x = self.layer3(x)

I’m interested in using the above methods on x where affine_grid should perform translation and grid_sample reflection padding

That sound be possible and the Spatial Transformer Network uses both methods in its forward pass.