BSNet icon indicating copy to clipboard operation
BSNet copied to clipboard

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.

Open NavyasriElpula opened this issue 3 years ago • 7 comments

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.

NavyasriElpula avatar Nov 24 '22 11:11 NavyasriElpula

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.

spraise avatar Nov 24 '22 14:11 spraise

Ok sir. Thankyou. I ll look into it. Actually im running this in google colab. And i tried to print 'modelfile' it gave output as "None".

On Thu, 24 Nov 2022 at 19:49, Jijie Wu @.***> wrote:

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.

— Reply to this email directly, view it on GitHub https://github.com/PRIS-CV/BSNet/issues/2#issuecomment-1326515162, or unsubscribe https://github.com/notifications/unsubscribe-auth/APP2BSUHEDG24FEKVA7Y7TLWJ52O5ANCNFSM6AAAAAASKJ7E2M . You are receiving this because you authored the thread.Message ID: @.***>

NavyasriElpula avatar Nov 25 '22 06:11 NavyasriElpula

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.

spraise avatar Dec 01 '22 04:12 spraise

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

NavyasriElpula avatar Dec 21 '22 09:12 NavyasriElpula

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

spraise avatar Dec 22 '22 06:12 spraise

Hi! NavyasriElpula,

I guess this error is caused by your modification, in fact 'topk_labels' is already a GPU Tensor, and we turned this to cpu in order to manipulate it as a numpy type object, and we turned it into a cpu in order to manipulate it with the numpy type. If the GPU is available, our code runs without problems and does not need to be modified, although in a colab environment.

Thank you for your attention to our work!

Sincerely, Jijie Wu

NavyasriElpula @.***> 于2023年1月3日周二 07:25写道:

Thankyou. I modified as per your suggestions. I was getting following error and I tried checking if colab detecting gpu, it is detecting. Epoch 0 | Batch 0/100 | Loss 0.370344 Epoch 0 | Batch 10/100 | Loss 0.137445 Epoch 0 | Batch 20/100 | Loss 0.075194 Epoch 0 | Batch 30/100 | Loss 0.051320 Epoch 0 | Batch 40/100 | Loss 0.038922 Epoch 0 | Batch 50/100 | Loss 0.031343 Epoch 0 | Batch 60/100 | Loss 0.026234 Epoch 0 | Batch 70/100 | Loss 0.022557 Epoch 0 | Batch 80/100 | Loss 0.019789 Epoch 0 | Batch 90/100 | Loss 0.017626

AttributeError Traceback (most recent call last) https://localhost:8080/# 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")

2 frames https://localhost:8080/# in correct(self, x) 54 55 topk_scores, topk_labels = scores.data.topk(1, 1, True, True) ---> 56 topk_ind = topk_labels.gpu().np() 57 top1_correct = np.sum(topk_ind[:,0] == y_query) 58 return float(top1_correct), len(y_query)

AttributeError: 'Tensor' object has no attribute 'gpu'

— Reply to this email directly, view it on GitHub https://github.com/PRIS-CV/BSNet/issues/2#issuecomment-1369459477, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALCTMM4VEEL6DZUYMTE2YKLWQPH7BANCNFSM6AAAAAASKJ7E2M . You are receiving this because you commented.Message ID: @.***>

spraise avatar Jan 07 '23 12:01 spraise

Thankyou,sir.

NavyasriElpula avatar Feb 20 '23 10:02 NavyasriElpula