@chinakook Thanks.
I don't know it.
`mxnet.gluon.nn.Sequential` is a serial structure.
[python/mxnet/gluon/nn/basic_layers.py#L51](https://github.com/apache/incubator-mxnet/blob/master/python/mxnet/gluon/nn/basic_layers.py#L51)
```python
class Sequential(Block):
[...]
def forward(self, x):
for block in self._children.values():
x = block(x)
return x
```
How to use `Sequential` to implement a parallel structure like multi-column CNN?
[Single-Image Crowd Counting via Multi-Column Convolutional Neural Network
[Page:4]](https://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/Zhang_Single-Image_Crowd_Counting_CVPR_2016_paper.pdf)
I think `BlockList` is useful.
e.g.
```python
class MCCNN(nn.HybridBlock):
def __init__(self, num_filter, columns, aggregator, **kwargs):
super(MCCNN, self).__init__(**kwargs)
with self.name_scope():
self.column_blocks = BlockList(self, [get_column(num_filter,
kernel_size, dilations) for kernel_size, dilations in columns])
self.aggregator = get_aggregator(num_filter, aggregator[0],
aggregator[1])
self.conv1x1 = nn.Conv2D(channels = 1, kernel_size = (1, 1),
activation = 'relu')
def hybrid_forward(self, F, x):
column_outputs = [c(x) for c in self.column_blocks]
x = F.concat(*column_outputs, dim = 1)
x = self.aggregator(x)
x = self.conv1x1(x)
x = F.squeeze(x, axis = 1)
return x
```
And here is my BlockList implementation.
```python
def BlockList(self, block_list):
block_names = []
for block in block_list:
assert not hasattr(self, block.name)
setattr(self, block.name, block)
block_names.append(block.name)
class _BlockList:
def __init__(self, block_names, parent):
self.block_names = block_names
self.parent = parent
def __getitem__(self, i):
return getattr(self.parent, self.block_names[i])
return _BlockList(block_names, self)
```
[ Full content available at:
https://github.com/apache/incubator-mxnet/pull/11254 ]
This message was relayed via gitbox.apache.org for [email protected]