I found a pretrained model online that was trained using DataParallel and I want to retrain the final layer using my own dataset. I load the model and modify the last layer as follows:
model_ft = torch.load(base_model, map_location={'cuda:0': 'cpu'})
for param in model_ft.module.parameters():
    param.requires_grad = False
num_ftrs = model_ft.module.classifier.in_channels
features = list(model_ft.module.classifier.children())[:-1] # remove last later
features.extend([nn.Conv2d(num_ftrs, n_classes*n_atom_outputs, kernel_size=1, bias=True)])
model_ft.module.classifier = nn.Sequential(*features)


When I run the code, I get the following error during forward propagation: Traceback (most recent call last):
File “code/train.py”, line 157, in train_model
outputs = model(inputs)
File “/usr/local/lib/python3.5/dist-packages/torch/nn/modules/module.py”, line 325, in call
result = self.forward(*input, **kwargs)
…
…
…
File “/usr/local/lib/python3.5/dist-packages/torch/nn/parallel/_functions.py”, line 94, in _get_stream
if _streams[device] is None: IndexError: list index out of range
I believe this is because the model has been wrapped with DataParallel but I do not have a GPU. May I know how can I remove DataParallel from a pretrained model? Or is there a better way to resolve the error? Thank you!