AttributeError: 'Series' object has no attribute 'as_matrix' (From kaggle)

I am new to using Torch but I am trying to use a pretrained model to build my model. As a first step to understanding the process I am trying to duplicate the results from the kaggle site: Use pretrained PyTorch models | Kaggle

All is well until I reach the first line of cell 13: img, label = next(iter(train_dl))

I then get an AttributeError:

AttributeError Traceback (most recent call last)
/tmp/ipykernel_30361/1705970776.py in
----> 1 img, label = next(iter(train_dl))
2 print(img.size(), label.size())
3 fig = plt.figure(1, figsize=(16, 4))
4 grid = ImageGrid(fig, 111, nrows_ncols=(1, 4), axes_pad=0.05)
5 for i in range(img.size()[0]):

~/anaconda3/lib/python3.9/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 \

~/anaconda3/lib/python3.9/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)

~/anaconda3/lib/python3.9/site-packages/torch/utils/data/_utils/fetch.py in fetch(self, possibly_batched_index)
48 if self.auto_collation:
49
—> 50 data = [self.dataset[idx] for idx in possibly_batched_index]
51 else:
52 data = self.dataset[possibly_batched_index]

~/anaconda3/lib/python3.9/site-packages/torch/utils/data/_utils/fetch.py in (.0)
48 if self.auto_collation:
49
—> 50 data = [self.dataset[idx] for idx in possibly_batched_index]
51 else:
52 data = self.dataset[possibly_batched_index]

/tmp/ipykernel_30361/2070777975.py in getitem(self, idx)
12 fullname = join(self.root_dir, img_name)
13 image = Image.open(fullname)
—> 14 labels = self.labels.iloc[idx, 1:].as_matrix().astype(‘float’)
15 labels = np.argmax(labels)
16 if self.transform:

~/anaconda3/lib/python3.9/site-packages/pandas/core/generic.py in getattr(self, name)
5485 ):
5486 return self[name]
→ 5487 return object.getattribute(self, name)
5488
5489 def setattr(self, name: str, value) → None:

AttributeError: ‘Series’ object has no attribute ‘as_matrix’

I suspect that I am missing something obvious. Any help is greatly appreciated.

You seem to be running into a pandas error:
.as_matrix is deprecated since 0.23.0 in favor of .values, which is apparently also not the recommended way anymore and .to_numpy should be used.

Thank you very much! Both .values and .to_numpy() work for me.