load test data in pytorch
All is in the title, I just want to know, how can I load my own test data (image.jpg) in pytorch in order to test my CNN.

You need to feed images to net the same as in training: that is, you should apply exactly the same transformations to get similar results.  

Assuming your net was trained using this code (or similar), you can see that an input image (for validation) undergoes the following transformations:


transforms.Compose([
            transforms.Resize(256),
            transforms.CenterCrop(224),
            transforms.ToTensor(),
            normalize,
        ])),



Following torchvision.transforms docs you can see that an input image goes through:


Resizing to 256x256 pix  
Cropping 224x224 rect from the center of the image
The image is converted from uint8 datatype to float in range [0, 1], and transposed to 3-by-224-by-224 array  
The image is normalize by subtracting mean and dividing by std.


You can do all this manually to any image

import numpy as np
from PIL import Image

pil_img = Image.open('image.jpg').resize((256, 256), Image.BILINEAR)  # read and resize
# center crop
w, h = pil_img.size
i = int(round((h - 224) / 2.))
j = int(round((w - 224) / 2.))
pil_img = pil_img.crop((j, i, j+224, i+224))
np_img = np.array(pil_img).astype(np.float32) / 255.
np_img = np.transpose(np_img, (2, 0, 1))  
# normalize
mean = [0.485, 0.456, 0.406]
std = [0.229, 0.224, 0.225]
for c in range(3):
  np_img = (np_img[c, ...] - mean[c]) / std[c]


Once you have np_img ready for your model, you can run a feed forward pass:

pred = model(np_img[None, ...])  # note that we add a singleton leading dim for batch

