Cannot convert list to array: ValueError: only one element tensors can be converted to Python scalar问题及解决办法
我想把pytorch网络得出的特征进行保存在list中,然后转换为array为我所用,直接将pytorch网络的输出特征(tensor类型)保存在list中会报如上错误,具体原因不详,我们可以通过对每一个输出的特征tensor进行target_features = target_features.numpy()操作,将每一个特征转化为numpy之后进行 list。append(target_features)操作即可。在解决该问题的过程中,可以使用x.shape以及x.type来对tensor进行了解, 并最终修改错误