RuntimeError: shape is invalid for input || RuntimeError: Sizes of tensors must match except in dime

RuntimeError: shape '[24, 192, 14, 14]' is invalid for input of size 3612672

源代码:feature_tf = feature_tf.view(b,c,14,14) 其指定高宽和输入的feature_tf实际的高宽乘积不一致,比如其实际值是28*28,由于后续需要拼接,如果简单把14改成28,修改之后,又引发后续的拼接错误:

RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 14 but got size 28 for tensor number 1 in the list.

torch.cat((feature_cnn, feature_tf),dim=1),提示说二者高宽不匹配,这里可以根据特征图或模块进行修改,但是有时,这种尺寸不匹配可能是由于模型设计初期的一些假设不再成立所致,比如原来的代码是针对tiny版本设计的,但是加载的模型和预训练都是base版本的,就导致整个尺寸参数设定都不同,这样要改的就很多了,如果是要调通,就先按照预定的tiny版本以适配当前整个代码流程。

你可能感兴趣的:(深度学习)