0
$\begingroup$

I trained my EfficientNet (CNN) and got accuracy=0.73. The question is how to check it on one concrete image from the testing set? How to write a code in python for it? I described the testing set this way:

testing_data = np.load("testing_data.npy", allow_pickle = True)
test_X = torch.Tensor([i[0] for i in testing_data]).view(-1, 3, 224, 224)
test_y = torch.Tensor([i[1] for i in testing_data])

This one (https://pytorch.org/docs/stable/data.html ch5) doesn't work for me because I didn't use torch.utils.data.DataLoader in the previous code. My model is called net. I only tried something like this:

net(test_X[0])

but got an error:

RuntimeError: Expected 4-dimensional input for 4-dimensional weight [32, 3, 3, 3], but got 3-dimensional input of size [3, 224, 224] instead
$\endgroup$
9
  • 1
    $\begingroup$ May you develop on what your problem is ? net(test_X[0]) should work, does it returns an error ? Maybe you need to use x = torch.unsqueeze(test_X[0]) in case you have dimension issues. $\endgroup$ – Ubikuity May 1 at 22:43
  • $\begingroup$ @Ubikuity I'm getting this error: "Expected 4-dimensional input for 4-dimensional weight [32, 3, 3, 3], but got 3-dimensional input of size [3, 224, 224] instead" what is quite strange for me $\endgroup$ – Adolf Miszka May 1 at 22:48
  • 1
    $\begingroup$ Maybe x = torch.unsqueeze(test_X[0], 0). Second argument corresponds to where we add the empty dimension, which is the first slot (index 0) in our case. $\endgroup$ – Ubikuity May 1 at 22:56
  • 1
    $\begingroup$ I don't know what your network is supposed to do, this outputs looks like a classification output where the 1 output is the detected class, so here it means this image belongs to class nº2. We usually use torch.argmax(output) to get the maximum of this vector, which is the detected class. doc of this function is right here pytorch.org/docs/stable/generated/torch.argmax.html $\endgroup$ – Ubikuity May 1 at 23:14
  • 1
    $\begingroup$ You're welcome :) $\endgroup$ – Ubikuity May 1 at 23:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.