gpt4 book ai didi

Tensorflow:如何将张量的 channel 从 RGB 切换到 BGR?

转载 作者:行者123 更新时间:2023-12-03 00:18:53 24 4
gpt4 key购买 nike

是否有一种快速方法将编码图像的张量从 RGB 转换为 BGR?

在 python 中,这将是这样的:

image = image[:, :, [2,1,0]]

最佳答案

您可以使用tf.strided_slicetf.reverse .

例如,

import tensorflow as tf

img = tf.reshape(tf.range(30), [2, 5, 3])

# the following two lines produce equivalent result:
img_channel_swap = img[..., ::-1]
img_channel_swap_1 = tf.reverse(img, axis=[-1])

请注意,tf.reverse的api是从tensorflow r1.0更改的。

关于Tensorflow:如何将张量的 channel 从 RGB 切换到 BGR?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42161916/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com