# Comparing the function difference with torch.nn.Module.named_children
## torch.nn.Module.named_children
```python
torch.nn.Module.named_children()
```
For more information, see [torch.nn.Module.named_children](https://pytorch.org/docs/1.5.0/nn.html#torch.nn.Module.named_children).
## mindspore.nn.Cell.name_cells
```python
mindspore.nn.Cell.name_cells()
```
For more information, see [mindspore.nn.Cell.name_cells](https://mindspore.cn/docs/en/r2.0.0-alpha/api_python/nn/mindspore.nn.Cell.html#mindspore.nn.Cell.name_cells).
## Differences
PyTorch: The function returns a Generator over immediate children modules, yielding both the names of the modules as well as the modules themselves.
MindSporeļ¼The function returns OrderedDict over immediate cells, containing both the names of the cells as well as the cells themselves.
## Code Example
```python
import mindspore as ms
import numpy as np
from mindspore import nn
class ConvBN(nn.Cell):
def __init__(self):
super(ConvBN, self).__init__()
self.conv = nn.Conv2d(3, 64, 3)
self.bn = nn.BatchNorm2d(64)
def construct(self, x):
x = self.conv(x)
x = self.bn(x)
return x
class MyNet(nn.Cell):
def __init__(self):
super(MyNet, self).__init__()
self.build_block = nn.SequentialCell(ConvBN(), nn.ReLU())
def construct(self, x):
return self.build_block(x)
# The following implements mindspore.nn.Cell.name_cells() with MindSpore.
net = MyNet()
print(net.name_cells())
```
```text
# Out:
OrderedDict([('build_block', SequentialCell<
(0): ConvBN<
(conv): Conv2d
(bn): BatchNorm2d
>
(1): ReLU<>
>)])
```
```python
import torch.nn as nn
class ConvBN(nn.Module):
def __init__(self):
super(ConvBN, self).__init__()
self.conv = nn.Conv2d(3, 64, 3)
self.bn = nn.BatchNorm2d(64)
def forward(self, x):
x = self.conv(x)
x = self.bn(x)
return x
class MyNet(nn.Module):
def __init__(self):
super(MyNet, self).__init__()
self.build_block = nn.Sequential(ConvBN(), nn.ReLU())
def construct(self, x):
return self.build_block(x)
# The following implements torch.nn.Module.named_children() with torch.
net = MyNet()
print(net.named_children(), "\n")
for name, child in net.named_children():
print("Name: ", name)
print("Child: ", child)
```
```text
# Out:
Name: build_block
Child: Sequential(
(0): ConvBN(
(conv): Conv2d(3, 64, kernel_size=(3, 3), stride=(1, 1))
(bn): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(1): ReLU()
)
```