Search code examples
machine-learningdeep-learningcomputer-visionmxnetgluon

Rotating image and load to MXNet model


Is there a way to load a image, rotate it and load it to MXNet model (e.g: yolov3).
I use the below method but I don't think it's efficient:
1/ Load the image and rotate it with pillow

image = Image.open(img_path)
image = image.rotate(90)

2/ Save the image and then load it with gluoncv (I use yolo here so I used yolo.load_test):

#Save image
image.save(name +".png")

#Load image with gluoncv 
imgs_for_inference, imgs_for_plot = gluoncv.data.transforms.presets.yolo.load_test(
   images_names,
   short=512)

Solution

  • After trying some libraries, I found a more simple method for the problem without the need to save image and then load it (which is very inefficent). I used pillow to load the image and rotate it, then use transform_test to get MXNet tensor so as to feed to the model:

    from PIL import Image
    image = Image.open(path_to_image)
    image = image.rotate(90)
    tensor, _ = gluoncv.data.transforms.presets.yolo.transform_test(
        images,
        short=512
      )
    prediction = model(tensor)