报错: TypeError: unsupported operand type(s) for *: ‘float’ and ‘NoneType’
原因: 网络模型中某些层未使用
详细过程:
1.报错位置如下,报这个错的原因是grad_Ec中某些部分数据为None
2.于是将网络中的参数尺寸以及grad数据输出
# 输出grad数据和网络模型尺寸
print("grad_Ef==================")
for p in zip(grad_Ef, self.net.FontEncoder.parameters()):
print("None",p[1].size()) if p[0]==None else
print(p[0].size(),p[1].size())
3.其输出结果如下,果然发现网络模型其中几层的grad为None
4.找到网络定义的代码,发现rcb0层定义了但在forward中并未使用,所以导致其中几层grad为None
5.将self.rcb0这一行注释掉即可