【问题标题】:Preprocessing a image for yolo pretrained net为 yolo 预训练网络预处理图像
【发布时间】:2019-07-16 17:02:02
【问题描述】:

我目前正在做一个项目,我需要使用yolo3_mobilenet1.0_coco,但输入图像需要从格式(300,300,3) 预处理到(1,3,300,300),这是im.resize((1,3,300,300)) 无法实现的,但有一些特殊的gluoncv 类中的函数为 data.transforms.presets.ssd.load_test("string_containing_image_file name", short=512) 但它们都将 "string of image file name" 作为输入参数,但我想传递具有原始图像作为输入的变量。

有什么功能可以让我做到这一点。因为它必须是我将要传递的变量,因为我不会获取图像文件名。

我已经试过了

x, img = data.transforms.presets.ssd.load_test(im_fname, short=512)

其中im_fname(300,300,3) 格式的图像文件名。 但我无法传递文件名,因为图像将从ImageDataGenerator 进入将使用此 yolo 网络的预处理函数。

【问题讨论】:

    标签: python numpy tensorflow yolo


    【解决方案1】:

    使用numpy,您可以使用以下代码简单地将图像从最后一个频道更改为第一个频道:

    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)
    

    【讨论】:

      猜你喜欢
      • 2020-10-03
      • 1970-01-01
      • 2018-10-08
      • 2016-02-19
      • 2017-05-23
      • 2016-03-31
      • 1970-01-01
      • 2018-11-02
      • 2021-12-19
      相关资源
      最近更新 更多