Getting error at evaluate function

Hello,

I’m on my course project and wanted to classify bird images.

I kinda sticked to the provided code and adjusted the class PetsDataset(Dataset) to fit for my dataset.
That took me some time but it worked.
In cell 13 I can plot the loaded Dataset.

But when I transfer the dataset to the GPU and run the model, I get an error I don’t know how to deal with (cell 37)

AttributeError Traceback (most recent call last)

in ()
----> 1 history = [evaluate(model, valid_dl)]
2 history

8 frames

in to_device(data, device)
11 if isinstance(data, (list, tuple)):
12 return [to_device(x, device) for x in data]
—> 13 return data.to(device, non_blocking=True)
14
15

AttributeError: ‘str’ object has no attribute ‘to’

Can someone tell me whats my mistake?
Maybe because my self.classes is a dictionary and not a list?

If I run it on CPU I get the error:

AttributeError Traceback (most recent call last)

in ()
----> 1 history = [evaluate(model, valid_dl)]
2 history

5 frames

/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in nll_loss(input, target, weight, size_average, ignore_index, reduce, reduction)
2258 raise ValueError(‘Expected 2 or more dimensions (got {})’.format(dim))
2259
-> 2260 if input.size(0) != target.size(0):
2261 raise ValueError(‘Expected input batch_size ({}) to match target batch_size ({}).’
2262 .format(input.size(0), target.size(0)))

AttributeError: ‘list’ object has no attribute ‘size’

SOLVED

The categories were labeled as string ‘001’ not int 1 and my targets had values 1-200 instead of 0-199

1 Like

oke thanks for advice