conv2d(): argument 'input' (position 1) must be Tensor, not str in loop function
I am trying to write a loop function to extract features from my data and save it in the list. 

And here is my code:

import pickle

output_features = []

with torch.no_grad():
    for (inputs, labels) in dataloaders.items():
        x=feature_extractor(inputs)
        output_features.append(x)
        output_features = torch.cat(output_features).numpy

pickle.dump(output_features, open("features.pkl", "w")) 


But i have an error. 

conv2d(): argument 'input' (position 1) must be Tensor, not str


Then I changed again it to 

with torch.no_grad():
    for i, (inputs, labels) in enumerate(dataloaders['val']):
        x=feature_extractor(inputs)
        output_features.append(x)
        output_features = torch.cat(output_features).numpy

pickle.dump(output_features, open("features.pkl", "wb"))   



Then I got this error 

'builtin_function_or_method' object has no attribute 'append'


Please, someone, explain to me why I got this error and how to get features from each input with its label and save them in an array. Thank you 

For the first issue, it really depends on how the data is saved into the dataloader. But according to convention, I'm guessing it holds tuples of (input tensor, label), which can simply be accessed by for (inputs, labels) in dataloader:. The enumeration isn't compulsory, unless you would like to keep count of each iteration.

As for the second error, this is because you accidentally wrote output_features = torch.cat(output_features).numpy, which calls a built-in method, instead of applying it to the output tensor. You can correct this to output_features = torch.cat(output_features).numpy() and you should be able to get the output features fine!
