I am currently working on a project where I need to use a yolo3_mobilenet1.0_coco
but the input image needs to be preprocessed from a format (300,300,3)
to (1,3,300,300)
which is not being possible by im.resize((1,3,300,300))
but there are particular functions in gluoncv
class as data.transforms.presets.ssd.load_test("string_containing_image_file name", short=512)
but they all take "string of image file name"
as input argument but I want to pass the variable having the original image as input .
Are there any function that can allow me to do that. As it has to be the variable that I will be passing as I wont be getting the image file name.
I have already tried
x, img = data.transforms.presets.ssd.load_test(im_fname, short=512)
where im_fname
is the file name of the image in (300,300,3)
format . but I cant pass the file name as the images will be going from a ImageDataGenerator
into a preprocessing func where this yolo net will be used.
With numpy
, you can simply change the image from channel last to channel first using the following code:
import numpy as np
img = np.random.randn(300, 300, 3) # creating random image
print(img.shape) #Out: (300, 300, 3)
img_channel_first = np.moveaxis(img, -1, 0)
print(img_channel_first.shape) #Out: (3, 300, 300)
img_in = img_channel_first[np.newaxis,:]
print(img_in.shape) #Out: (1, 3, 300, 300)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.