thanks for your kind reply Alex.
your solution seems correct when I want to implement all operation and network without using tensor from scratch. But when I want to use a pretrained model, it is necessary to convert image to tensor.  This sample code shows this subject:
trained_model = torchvision.models.vgg16() #myModel()  #
trained_model.eval()
############ Import new image for classification #########################
img = Image.open('/home/morteza/PycharmProjects/transfer_learning/hymenoptera_data/val/ants/94999827_36895faade.jpg')
img.show()
loader = transforms.Compose([transforms.Scale(224), transforms.ToTensor()])
img = loader(img).float()
img = Variable(img)
img = img.unsqueeze(0)
pred = trained_model(img)
print(pred)

If I remove transforms.ToTensor(), I can not use Variable(img) and img.unsqueeze(0). Then when PIL image is fed to the model, dimension error is appeared. because the size of input image must be 1x1xw,h.