python - 使用数据读取器在 tensorflow 中读取 tiff 文件的正确方法

标签 python machine-learning tensorflow tiff

我正在使用 tensorflow 读取一些 tiff 格式的地理空间图像数据。我想使用类似的东西:

    images = tf.convert_to_tensor(image_list, dtype=tf.string)
    img_contents = tf.read_file(images)
    img = tf.image.decode_image(img_contents, channels=3)

我想我需要做的是自己写一个解码函数。但 img_contents 实际上是一个张量字符串,我无法直接使用它来访问文件。有什么方法可以读取 tiff 图像吗?

最佳答案

您可以在Python中解析文件,并通过feed_dict传递到TensorFlow训练图,遵循代码仅用于演示,但无法运行:

def read_tiff_file(file_path):
    #### code that read tiff_file content 
    return image_content # return the image content with 18 * 18 * 3

image_pl = tf.placeholder([18, 18, 3], tf.float32) # suppose your image is 18*18 with 3 channels

## constructing tf.graph with image_pl
## ...

train_step = tf.train.GradientDescentOptimizer(0.5).minimize(loss)

with tf.Session as sess:
    for file_name in file_name_list:
        image_content = read_tiff_file(file_name)
        sess.run(train_step, feed_dict={image_pl:image_content})

关于python - 使用数据读取器在 tensorflow 中读取 tiff 文件的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46155871/

相关文章:

machine-learning - 如何通过机器学习进行反向预测?

python - Word2VecKeyedVectors 的对象没有属性 'index_to_key'

python - 如何在一维 tensorflow 张量中省略零

python - 从另一列填充一个 DataFrame 列,但每第 n 行值

machine-learning - 变量共享 tensorflow

tensorflow - 神经网络权重太大?

tensorflow - 为什么在 Keras 指标函数中使用 axis=-1 ?

python - 自定义 Seaborn 调色板的颜色不一致

python - Python中单词的序数

python - 在Python中简单添加