AttributeError: 'list' object has no attribute 'seek'

when I run this code on google colab. The following error occur.
Please help me.

if cuda:
state_dic=torch.load(model_path[0])
encoder.load_state_dict(state_dic)
state_dic2=torch.load(model_path[1])
decoder.load_state_dict(state_dic2)

AttributeError: ‘list’ object has no attribute ‘seek’. You can only torch.load from a file that is seekable. Please pre-load the data into a buffer like io.BytesIO and try to load from it instead.

Could you provide the part of the code where you declare model_path?

1 Like

yes. I declare the model path as follow…

import glob
encoder_pkl=glob.glob("/content/drive/MyDrive/remote_sensing_image_captioning/test/encoder.pkl")
decoder_pkl=glob.glob("/content/drive/MyDrive/remote_sensing_image_captioning/test/decoder.pkl")
encdoder_pkl=encoder_pkl[0]
decoder_pkl=decoder_pkl[0]

model_path = [encoder_pkl, decoder_pkl]

def predict(img_name, model_path):
encoder = Encoder()
decoder = Decoder()
if cuda:
encoder = encoder.cuda()
decoder = decoder.cuda()
if model_path:
print(‘Loading the parameters of model.’)
if cuda:
state_dic=torch.load(model_path[0])
encoder.load_state_dict(state_dic)
state_dic2=torch.load(model_path[1])
decoder.load_state_dict(state_dic2)

The error occur when the model_path is passed to the parameter of predict function.

It seems model_path[0] and/or model_path[1] return a list instead of a file path or a buffer.

1 Like