def copyToTensor(self, batch_size):
     tensor = PaddleTensor()
     tensor.name = self.name
     tensor.shape = [batch_size, self.shape_size]
     tensor.dtype = self.list[self.dtype]
     tensor.data = PaddleBuf(self.data)
     return tensor
Exemplo n.º 2
0
def fake_input(img):
    image = PaddleTensor()
    image.name = "image"
    image.shape = img.shape
    image.dtype = PaddleDType.FLOAT32
    image.data = PaddleBuf(img.flatten().tolist())
    return [image]
Exemplo n.º 3
0
def array2tensor(ndarray):
    """ convert numpy array to PaddleTensor"""
    assert isinstance(ndarray, np.ndarray), "input type must be np.ndarray"
    tensor = PaddleTensor()
    tensor.name = "data"
    tensor.shape = ndarray.shape
    if "float" in str(ndarray.dtype):
        tensor.dtype = PaddleDType.FLOAT32
    elif "int" in str(ndarray.dtype):
        tensor.dtype = PaddleDType.INT64
    else:
        raise ValueError("{} type ndarray is unsupported".format(tensor.dtype))

    tensor.data = PaddleBuf(ndarray.flatten().tolist())
    return tensor
Exemplo n.º 4
0
def preprocess(img):
    img = cv2.resize(img, (input_size, input_size))
    img = img.transpose((2, 0, 1))
    if modelname == "mobilenet-ssd":
        img = (img - 127.5) * 0.007843
    else:
        mean = np.array([103.94, 116.669, 123.68],
                        np.float32).reshape([3, 1, 1])
        img = img - mean
    image = PaddleTensor()
    image.name = "data"
    image.shape = [1, 3, input_size, input_size]
    image.dtype = PaddleDType.FLOAT32
    image.data = PaddleBuf(img.flatten().astype("float32").tolist())
    return [image]
Exemplo n.º 5
0
def warp_input(image_data, input_size):
    """
    deal input to paddle tensor
    :param image_data:          输入的图像
    :param image_shape:         原始图像的大小
    :param input_size:          输入图像的大小
    :return:
    """
    # image data
    image = PaddleTensor()
    image.name = 'image'
    image.shape = input_size
    image.dtype = PaddleDType.FLOAT32
    image.data = PaddleBuf(image_data.flatten().astype(np.float32).tolist())

    return image