Hi Salome!



 ssalome:

(tensor([[[-1.9000, -1.9000, -1.9000,  …, -1.9000, -1.9000, -1.9000],
…
[ 0.0955,  0.2864,  0.4079,  …, -0.6506, -0.5986, -0.6159]]]), array([0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 1., 0., 0., 0.],
dtype=float32), ‘00001250_006.png’)
this is a tuple(input_img tensor, output_vector, image_id)


Well, this is confusing.  In the code you posted, you had the variables
inputs, labels, and imgindex.  But now you seem to be calling
them “input_img tensor, output_vector, image_id”.  I will guess that
these are the same things.


Image type and shape => <class ‘torch.Tensor’> torch.Size([1, 224, 224])
Output type and shape =><class ‘numpy.ndarray’> (15,)
Image id/imgindex(name of the image file) type=><class ‘str’>


Now I’m guessing that “Image” is what you just called “input_img
tensor", “Output” is “output_vector”, and “Image id/imgindex(name
of the image file)”  is “image_id”.
(And I’m also guessing that you haven’t given the shape and type()
of the variable outputs in your code, that is, the object returned by
your model.)
So it looks like what your code calls inputs is a single 224x224 image
with a leading singleton (size = 1) dimension, and that what your
code calls labels is a single numpy array of (floating-point) binary
labels, one for each of your fifteen classes.  Note, I don’t see your
batch size of 250 anywhere.
Your inputs tensor should be a batch of 250 images.  It should
most likely be a tensor of shape [250, 224, 244], unless your
model is expecting its input images to carry a “channel” dimension
of nChannel = 1, in which case your input tensor should have
shape [250, 1, 224, 244].
Your labels tensor should be  a pytorch tensor (not a numpy array),
and should be a  batch of sets of (floating-point) binary class labels,
one for each of your 15 classes, and therefore should have shape
[250, 15].


(fc): Linear(in_features=512, out_features=15, bias=True)


Although you didn’t provide the information for what your outputs
variable is, logically, and based on the last layer of your model, it
should have shape [batch size, nClass], that is, [250, 15].
It will be your model's predicted raw-score logits for each of your
250 samples being in each of your 15 classes.
This is what your data should look like.  But it looks like the shape of
your model outputs and the shape of your labels aren’t matching
up properly, presumably somewhere in your evaluation() function.
Could you call something like
trainAcc = evaluation (trainloader, resnet)
print (trainAcc)
testAcc = evaluation (testloader, resnet)
print (testAcc)

before you run any training?  (And call evaluation() in two separate
lines of code, as above.)
Good luck.
K. Frank