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: 'int' object has no attribute 'item' #3

Open
chillizex opened this issue May 9, 2022 · 1 comment
Open

AttributeError: 'int' object has no attribute 'item' #3

chillizex opened this issue May 9, 2022 · 1 comment

Comments

@chillizex
Copy link

chillizex commented May 9, 2022

I just downloaded the dataset and the notebook and encounter error when training the model. I didn't modify any code yet.
I guess there is something wrong with the getitem or the MyDataset class.
What should I do?

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
C:\Users\CHILLI~1\AppData\Local\Temp/ipykernel_31604/3002996250.py in <module>
----> 1 train(model,dataloader , criterion, optimizer,sgdr_partial,num_epochs=10)

C:\Users\CHILLI~1\AppData\Local\Temp/ipykernel_31604/2037274202.py in train(model, data_loader, criterion, optimizer, scheduler, num_epochs)
     17       running_corrects = 0.0
     18 
---> 19       for data , target in data_loader[phase]:
     20         #load the data and target to respective device
     21         data , target = data.to(device)  , target.to(device)

c:\Users\chillizex\anaconda3\lib\site-packages\torch\utils\data\dataloader.py in __next__(self)
    528             if self._sampler_iter is None:
    529                 self._reset()
--> 530             data = self._next_data()
    531             self._num_yielded += 1
    532             if self._dataset_kind == _DatasetKind.Iterable and \

c:\Users\chillizex\anaconda3\lib\site-packages\torch\utils\data\dataloader.py in _next_data(self)
    568     def _next_data(self):
    569         index = self._next_index()  # may raise StopIteration
--> 570         data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
    571         if self._pin_memory:
    572             data = _utils.pin_memory.pin_memory(data)

c:\Users\chillizex\anaconda3\lib\site-packages\torch\utils\data\_utils\fetch.py in fetch(self, possibly_batched_index)
     47     def fetch(self, possibly_batched_index):
     48         if self.auto_collation:
---> 49             data = [self.dataset[idx] for idx in possibly_batched_index]
     50         else:
     51             data = self.dataset[possibly_batched_index]

c:\Users\chillizex\anaconda3\lib\site-packages\torch\utils\data\_utils\fetch.py in <listcomp>(.0)
     47     def fetch(self, possibly_batched_index):
     48         if self.auto_collation:
---> 49             data = [self.dataset[idx] for idx in possibly_batched_index]
     50         else:
     51             data = self.dataset[possibly_batched_index]

c:\Users\chillizex\anaconda3\lib\site-packages\torch\utils\data\dataset.py in __getitem__(self, idx)
    469         if isinstance(idx, list):
    470             return self.dataset[[self.indices[i] for i in idx]]
--> 471         return self.dataset[self.indices[idx]]
    472 
    473     def __len__(self):

C:\Users\CHILLI~1\AppData\Local\Temp/ipykernel_31604/2466280676.py in __getitem__(self, idx)
      7 
      8   def __getitem__(self,idx):
----> 9     d = self.df.iloc[idx.item()]
     10     image = Image.open(self.img_dir/d.image).convert("RGB")
     11     label = torch.tensor(d[1:].tolist() , dtype=torch.float32)

AttributeError: 'int' object has no attribute 'item'
@hariouat
Copy link

You have to delete item()

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