a514514772
(Hui Po Wang)
April 27, 2020, 10:02am
#1
Hi all,

Assuming I have a input tensor with shape B x N x C x H x W, I want to apply the same CNN model f across the dimension N.

For now, I use for-loop to go over it.

```
out = []
for i in range(N):
out.append(self.conv(input[:, i])
```

I was wondering if there is any elegant way to do this.

Thanks.

1 Like

I work with spatio temporal data and implement stuff like you. My N is the temporal dimension. I have not found any other way than use a loop. Hope some1 can suggest some vectorization style approach

chetan06
(Chetan Pandey)
April 28, 2020, 3:53am
#3
```
from __future__ import division
import torch
from ._functions import SyncBatchNorm as sync_batch_norm
from .module import Module
from torch.nn.parameter import Parameter
from .. import functional as F
from .. import init
class _NormBase(Module):
"""Common base of _InstanceNorm and _BatchNorm"""
_version = 2
__constants__ = ['track_running_stats', 'momentum', 'eps',
'num_features', 'affine']
def __init__(self, num_features, eps=1e-5, momentum=0.1, affine=True,
track_running_stats=True):
super(_NormBase, self).__init__()
self.num_features = num_features
```

This file has been truncated. show original

You can check Pytorch source code for some better implementation