这是我的部分代码片段
ms_group_norm = nn.GroupNorm(32, 2048*wf)
relu = nn.ReLU
adaptive_avg_pool_2d = ms.ops.AdaptiveAvgPool2D(output_size=1)
conv2d = nn.Conv2d(2048*wf, head_size, kernel_size=1, has_bias=True)
self.head = nn.SequentialCell(OrderedDict([
('gn', ms_group_norm),
('relu', relu),
('avg', adaptive_avg_pool_2d),
('conv', conv2d),
]))
运行后报错:
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/BiT/train.py", line 303, in <module>
main(parser.parse_args())
File "C:/Users/Administrator/PycharmProjects/BiT/train.py", line 184, in main
model = models.KNOWN_MODELS[args.model](head_size=10, zero_head=True)
File "C:\Users\Administrator\PycharmProjects\BiT\models.py", line 223, in <lambda>
('BiT-M-R152x4', lambda *a, **kw: ResNetV2([3, 8, 36, 3], 4, *a, **kw)),
File "C:\Users\Administrator\PycharmProjects\BiT\models.py", line 188, in __init__
('conv', nn.Conv2d(2048*wf, head_size, kernel_size=1, has_bias=True)),
File "C:\ProgramData\Anaconda3\envs\mindspore\lib\site-packages\mindspore\nn\layer\container.py", line 153, in __init__
self.insert_child_to_cell(name, cell)
File "C:\ProgramData\Anaconda3\envs\mindspore\lib\site-packages\mindspore\nn\cell.py", line 915, in insert_child_to_cell
raise TypeError(f"For 'insert_child_to_cell', the argument 'child_cell' should be 'Cell' if not None, "
TypeError: For 'insert_child_to_cell', the argument 'child_cell' should be 'Cell' if not None, but got type <class 'pybind11_builtins.pybind11_type'>.
nn.Conv2d在定义时应该是继承了Cell的吧,为什么会报错呢?是我的创建实例时的问题吗?
****************************************************解答*****************************************************
这个改成Cell试一下