# How to Classify Single Image using Loaded Net

**URL:** <https://discuss.pytorch.org/t/how-to-classify-single-image-using-loaded-net/1411>\
**Category:** Uncategorized\
**Created:** [March 27, 2017, 8:50pm UTC](https://discuss.pytorch.org/t/how-to-classify-single-image-using-loaded-net/1411 "2017-03-27T20:50:52Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![tymokvo](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/tymokvo/32/9527_2.png) [@tymokvo](https://discuss.pytorch.org/u/tymokvo)\
**Post date:** [March 27, 2017, 9:05pm UTC](https://discuss.pytorch.org/t/how-to-classify-single-image-using-loaded-net/1411/2 "2017-03-27T21:05:10Z")

</div>

I use something like this. I think it’s a mashup of code from various tutorials/examples so my apologies if I should be crediting someone…

uses PIL and torchvision.transforms

```
imsize = 256
loader = transforms.Compose([transforms.Scale(imsize), transforms.ToTensor()])

def image_loader(image_name):
    """load image, returns cuda tensor"""
    image = Image.open(image_name)
    image = loader(image).float()
    image = Variable(image, requires_grad=True)
    image = image.unsqueeze(0) #this is for VGG, may not be needed for ResNet
    return image.cuda() #assumes that you're using GPU

image = image_loader(PATH TO IMAGE)

your_trained_net(image)

```

hope that helps

---

_[View the full topic](https://discuss.pytorch.org/t/how-to-classify-single-image-using-loaded-net/1411)._
