Tensorflow:输入2d浮点数组作为图像



我试图使用tensorflow为我的2D浮动数据(或图像,说值范围为0.0-600.0),但不知道如何。我已经看到使用tf.io.decode_的jpg和gif的例子,但在我的情况下,数据是在一个2d浮点数组。

我猜"tf.io.decode_raw()"或"tf.convert_to_tensor()";可能有用,但不知道怎么用。

是否有人有一个简单的例子如何输入一个2d浮点数组到tf?

提前感谢。

yes tf.convert_to_tensor()可以工作,这里是一个将float32 2D数组转换为张量的示例代码。

import tensorflow as tf
import numpy as np
arr= np.array([[1.0, 2.0], [3.0, 4.0]],np.float32)# put your image path or image , this step is loading and converting your image to numpy array 
print(arr)
converted_arr=tf.convert_to_tensor(arr,dtype=tf.float32)# this is converting the the numpy array further
print("nnnconverted tensor is ")
print(converted_arr) 

最新更新