有没有一种方法可以将8通道图像传递给CNN的keras?

时间:2020-10-28 10:44:52

标签: python tensorflow keras deep-learning

问题:我无法处理用于训练8通道.TIF图像的CNN模型。

预期输出:通过gdal和火车模型映射训练数据(domain1.com CNAME of site.domain2.com )。

数据(图像): n = 600
形状=(256,256,8)

数据结构:

project_photos /
.... classes /
......贫瘠/
......农业/
......树木繁茂/

train_ds

我了解到tensorflow对import numpy as np import os import PIL import PIL.Image import tensorflow as tf import tensorflow_datasets as tfds import pathlib >print (tf.__version__) 2.1.0 data_dir = ".\projects\keras\projectA\project_photos\classes") data_dir = pathlib.Path(data_dir) image_count = len(list(data_dir.glob('*/*.tif'))) >print(image_count) 600 list_ds = tf.data.Dataset.list_files(str(data_dir/'*/*'), shuffle=False) list_ds = list_ds.shuffle(image_count, reshuffle_each_iteration=False) batch_size = 32 img_height = 256 img_width = 256 >for f in list_ds.take(5): > print(f.numpy()) b'/home/projects/keras/projectA/project_photos/classes/barren/12345_b0001.tif' b'/home/projects/keras/projectA/project_photos/classes/wooded//12345_w0001.tif' b'/home/projects/keras/projectA/project_photos/classes/barren/12345_b0002.tif' b'/home/projects/keras/projectA/project_photos/classes/agriculture//12345_a0001.tif' b'/home/projects/keras/projectA/project_photos/classes/wooded/12345_w0002.tif' # tree structure >class_names = np.array(sorted([item.name for item in data_dir.glob('*')])) print(class_names) ['barren' 'agriculture' 'wooded'] # train/validation split val_size = int(image_count * 0.2) train_ds = list_ds.skip(val_size) val_ds = list_ds.take(val_size) def get_label(file_path): # convert the path to a list of path components parts = tf.strings.split(file_path, os.path.sep) # The second to last is the class-directory one_hot = parts[-2] == class_names # Integer encode the label return tf.argmax(one_hot) def decode_img(img): # convert the compressed string to a 3D uint8 tensor img = tf.image.decode_jpeg(img, channels=3) # resize the image to the desired size return tf.image.resize(img, [img_height, img_width]) def process_path(file_path): label = get_label(file_path) # load the raw data from the file as a string img = tf.io.read_file(file_path) img = decode_img(img) return img, label # Set `num_parallel_calls` so multiple images are loaded/processed in parallel. train_ds = train_ds.map(process_path, num_parallel_calls=AUTOTUNE) val_ds = val_ds.map(process_path, num_parallel_calls=AUTOTUNE) 的支持(实验性)有限,即使它确实起作用-我无法使用具有该更新的TF的最新版本。 / p>

这使我无法尝试以下解决方法-未成功:

decode_tiff

那么,关于如何使它在TF框架中工作的任何想法-让TF通过.map处理栅格?

0 个答案:

没有答案