Using pre-trained resnet18 to train my own dataset

hello guys,

I am currently using this pre-trained code example to train my own dataset. My dataset classes have postures of humans like sitting and standup. I use resnet18 model for this.

As limitations, I have very few train images (15 at most) to test it.(will add more obv.) and I changed minor parts of the main.py like changing scale() to resize() because they were deprecated. In the run time it says Prec1,5 not working but code runs anyway.

The problem is I used the some of the same images in “val” or compeletely irrelevant ones to observe the loss/acc change.

edit: the images have 224x224 px size.

This was what I got: (compeletly irrelevant pics like birds in val)

Epoch: [89][0/1] Time 2.153 (2.153) Data 2.114 (2.114) Loss 0.6270 (0.6270) Prec@1 72.727 (72.727) Prec@5 100.000 (100.000)

Test: [0/1] Time 1.863 (1.863) Loss 0.7864 (0.7864) Prec@1 50.000 (50.000) Prec@5 100.000 (100.000)

  • Prec@1 50.000 Prec@5 100.000

Question is: If I add relevant 1000+ imgs to my “train” and x-amount to “val”. will it have different and proper results? Therefore, can I use it? Or should I scrap it and write my own as it is wrong/deprecated?

What is the error message stating that “Prec1,5” is not working?

How many classes do you currently have?

=> creating model 'resnet18'
main.py:171: UserWarning: invalid index of a 0-dim tensor. This will be an error in PyTorch 0.5. Use tensor.item() to convert a 0-dim tensor to a Python number
  losses.update(loss.data[0], input.size(0))
main.py:172: UserWarning: invalid index of a 0-dim tensor. This will be an error in PyTorch 0.5. Use tensor.item() to convert a 0-dim tensor to a Python number
  top1.update(prec1[0], input.size(0))
main.py:173: UserWarning: invalid index of a 0-dim tensor. This will be an error in PyTorch 0.5. Use tensor.item() to convert a 0-dim tensor to a Python number
  top5.update(prec5[0], input.size(0))

currently I have 2 classes. I havent changed the the code, as it can be seen from the link.

That’s just a warning for indexing a 0-dim tensor.
Just use .item() instead as suggested in the warning:

losses.update(loss.item(), input.size(0))
top1.update(prec1.item(), input.size(0))
top5.update(prec5.item(), input.size(0))

thanks for the fix. However, the reason for that part was to show if the pytorch’s own examples need to be updated on their github page. As i said, it’s still working with those errors.

Maybe my question was phrased wrong:

I tried to see the test result changes based on the “val” file inputs. I put irrelevant photos like cats to see if the alg fails to classify.

so in the end I got this after 89th epoch:

Epoch: [89][0/1] Time 2.153 (2.153) Data 2.114 (2.114) Loss 0.6270 (0.6270) Prec@1 72.727 (72.727) Prec@5 100.000 (100.000)

Test: [0/1] Time 1.863 (1.863) Loss 0.7864 (0.7864) Prec@1 50.000 (50.000) Prec@5 100.000 (100.000)

Prec@1 50.000 Prec@5 100.000

the question was: will the result in prec1 and prec5 change if I add 1000+ images? (indicating that diferent inputs in val folder made no change)