张量切片后,我想使用地图功能更改切片图像

时间:2020-05-28 23:47:37

标签: python tensorflow tensorflow2.0 map-function

    <div class="container">
        <div class="child header">Header</div>
        <div class="child leftcol">
            <div class="greenleft">Yes</div>
            <p>Content on the left</p>
        </div>
        <div class="child rightcol">
            <div class="redright">No</div>
            <p>Content on the right</p>
        </div>
    </div>

这将在数据集中包含(图像路径,框)信息。
现在我需要将imagepath更改为真实图像

所以我做函数

dataset = tf.data.Dataset.from_tensor_slices((images,boxes)).shuffle(100).batch(1)

tf.Tensor(
[b'/media/jake/mark-4tb3/input/datasets/pascal/VOCtrainval_11-May-2012/VOCdevkit/VOC2012/JPEGImages/2008_000297.jpg'
 b'/media/jake/mark-4tb3/input/datasets/pascal/VOCtrainval_11-May-2012/VOCdevkit/VOC2012/JPEGImages/2008_000045.jpg'], shape=(2,), dtype=string) <tf.RaggedTensor [[[1, 86, 301, 295], [86, 204, 229, 330], [259, 187, 371, 330], [4, 140, 120, 292], [224, 112, 354, 334]], [[44, 41, 454, 341]]]>

然后我应用地图功能

def func(images):
    images = np.array(images)
    newSize = [300,300]
    if isprint:print('image_A->',images[0].decode("utf-8"))    

    image = cv2.imread(images[0].decode("utf-8"))
    if isprint:print(image.shape)
    image = np.array(image)
    scale_x = newSize[0] / image.shape[1]
    scale_y = newSize[1] / image.shape[0]
    image = cv2.resize(image, (newSize[0], newSize[1]))
    return tf.convert_to_tensor(image,dtype=tf.uint8)

但是我只想更改图像数据集,而其他保留。
我想知道这是正确的方法以及如何解决?

0 个答案:

没有答案