MindSpore报错截图如下:
ValueError: For reshape the shape of inputs_x is [256, 48, 64] the value of input_shape value is [48,64] the profuct of the shape of input_x should be equal to product of input_shape, but product of the shape of input_x is 786432, product of input shape is 3072
首先我们要学会看框架提供给我们的报错调用栈,通过调用栈我们可以知道是由于哪里的Reshape算子导致的,从图中我们可以知道报错Reshape算子的位置位于
mindspore/ops/_grad/grad_math_ops.py文件的86行,
然后,通过vim去定位我们可以知道此处其实是Mul算子的反向报错意思是输入input_x的shape和我们的目标shape大小不一致,输入input_x的shape是一个[256,48,64],而这里的目标shape是[48,64]。
解决方法:
我们知道了是Mul算子报错,其实通过调用栈能够大致知道哪个Mul算子里面的反向报错。Mul算子有两个输入x和y,在这里我们可以将x 的shape扩一维,然后再tile成和y一样的shape。总之一句话,正向x和y的shape一致就可以。