Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'NoneType' 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. #2

Open
NavyasriElpula opened this issue Nov 24, 2022 · 7 comments

Comments

@NavyasriElpula
Copy link

NavyasriElpula commented Nov 24, 2022

Hello sir,
I have trained your model BSNet but when i try to run save_features.py file it is throwing this error.
Kindly resolve this issue.
my whole error is as below


/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataloader.py:566: UserWarning: This DataLoader will create 12 worker processes in total. Our suggested max number of worker in current system is 2, which is smaller than what this DataLoader is going to create. Please be aware that excessive worker creation might get DataLoader running slow or even freeze, lower the worker number to avoid potential slowness/freeze if necessary.
cpuset_checked))
AttributeError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/torch/serialization.py in _check_seekable(f)
307 try:
--> 308 f.seek(f.tell())
309 return True

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

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last)
5 frames
in
70
71 model = model.cuda()
---> 72 tmp = torch.load(modelfile)
73 state = tmp['state']
74 state_keys = list(state.keys())

/usr/local/lib/python3.7/dist-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
697 pickle_load_args['encoding'] = 'utf-8'
698
--> 699 with _open_file_like(f, 'rb') as opened_file:
700 if _is_zipfile(opened_file):
701 # The zipfile reader is going to advance the current file position.

/usr/local/lib/python3.7/dist-packages/torch/serialization.py in _open_file_like(name_or_buffer, mode)
233 return _open_buffer_writer(name_or_buffer)
234 elif 'r' in mode:
--> 235 return _open_buffer_reader(name_or_buffer)
236 else:
237 raise RuntimeError(f"Expected 'r' or 'w' in mode but got {mode}")

/usr/local/lib/python3.7/dist-packages/torch/serialization.py in init(self, buffer)
218 def init(self, buffer):
219 super(_open_buffer_reader, self).init(buffer)
--> 220 _check_seekable(buffer)
221
222

/usr/local/lib/python3.7/dist-packages/torch/serialization.py in _check_seekable(f)
309 return True
310 except (io.UnsupportedOperation, AttributeError) as e:
--> 311 raise_err_msg(["seek", "tell"], e)
312 return False
313

/usr/local/lib/python3.7/dist-packages/torch/serialization.py in raise_err_msg(patterns, e)
302 + " Please pre-load the data into a buffer like io.BytesIO and"
303 + " try to load from it instead.")
--> 304 raise type(e)(msg)
305 raise e
306

AttributeError: 'NoneType' 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.

@spraise
Copy link
Collaborator

spraise commented Nov 24, 2022

The code is no problem running in my place. Shows that "NoneType" when loading a trained model is generally because the corresponding model is not found, please confirm whether the parameters of train.py and save_features.py are consistent, you can print the value of the "modelfile" to further confirm the loaded model path. In addition, please change the "num_workers" of DataLoader to less than 2.

@NavyasriElpula
Copy link
Author

NavyasriElpula commented Nov 25, 2022 via email

@spraise
Copy link
Collaborator

spraise commented Dec 1, 2022

Our code runs on NVIDIA 2080Ti GPUs. In fact, for your case, just make sure that the model saved after training matches the model loaded during save_features and testing.

@NavyasriElpula
Copy link
Author

Thankyou for your response.
Im stuck with another error as follows while training with other dataset .Kindly suggest solution if possible.

RuntimeError Traceback (most recent call last)
[ in
119 model.load_state_dict(tmp['state'])
120
--> 121 model = train(base_loader, val_loader, model, optimization, start_epoch, stop_epoch, params)
122 print("model trained")

5 frames
in forward(self, z_support, z_query)
39 extend_final_feat_dim = self.feat_dim.copy() # [64, 19, 19]
40
---> 41 z_support = z_support.contiguous().view( self.n_way, self.n_support, self.feat_dim ).mean(1) # [5, 64, 19, 19]
42 z_query = z_query.contiguous().view( self.n_way
self.n_query, *self.feat_dim ) # [80, 64, 19, 19]
43

RuntimeError: shape '[5, 5, 64, 19, 19]' is invalid for input of size 462080

@spraise
Copy link
Collaborator

spraise commented Dec 22, 2022

For custom datasets, make sure the input size of the picture is 84 × 84, and check the value of way and shot.

@spraise
Copy link
Collaborator

spraise commented Jan 7, 2023 via email

@NavyasriElpula
Copy link
Author

NavyasriElpula commented Feb 20, 2023

Thankyou,sir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants