【发布时间】:2020-10-25 10:55:27
【问题描述】:
我正在尝试使用 AlexNet 作为我从 .wav 文件数据派生的 3 通道图像输入的特征提取器。我有形状 (593, 3, 227, 227) 的特征提取器的输入。但是,当使用 AlexNet 模型时,我得到了错误
Traceback (most recent call last):
File "MainUI.py", line 1625, in <module>
main(False)
File "MainUI.py", line 1604, in main
accuracy_measurement(oversample)
File "MainUI.py", line 1463, in accuracy_measurement
features = model.extract_features(features.double())
File "/Users/sruthikurada/opt/anaconda3/lib/python3.7/site-packages/alexnet_pytorch/model.py", line 77, in extract_features
x = self.features(inputs)
File "/Users/sruthikurada/opt/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 550, in __call__
result = self.forward(*input, **kwargs)
File "/Users/sruthikurada/opt/anaconda3/lib/python3.7/site-packages/torch/nn/modules/container.py", line 100, in forward
input = module(input)
File "/Users/sruthikurada/opt/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 550, in __call__
result = self.forward(*input, **kwargs)
File "/Users/sruthikurada/opt/anaconda3/lib/python3.7/site-packages/torch/nn/modules/conv.py", line 353, in forward
return self._conv_forward(input, self.weight)
File "/Users/sruthikurada/opt/anaconda3/lib/python3.7/site-packages/torch/nn/modules/conv.py", line 350, in _conv_forward
self.padding, self.dilation, self.groups)
RuntimeError: Expected object of scalar type Double but got scalar type Float for argument #3 'mat1' in call to _th_addmm_
导致此错误的代码:
features, labels = extract_features(train_files)
print(features.shape) # (593, 3, 227, 227)
import torch
from alexnet_pytorch import AlexNet
model = AlexNet.from_pretrained('alexnet')
features = torch.from_numpy(features).type('torch.DoubleTensor')
features = model.extract_features(features.double()) # <-- This is where the error occurs
print(features.shape)
如您所见,我使用了double() 命令,但这并没有帮助。您能提供一些帮助吗?
【问题讨论】:
-
我尝试了答案的建议,使用 .double() 命令,但它没有帮助功能仍然是 torch.float64
-
尝试 features = model.extract_features(features.float())
标签: python pytorch transfer-learning