使用tf.data在Tensorflow-2.0中读取图像和蒙版(用于分割问题)>

问题描述 投票:0回答:1

我正在尝试通过单击this链接来读取图像数据集以解决分割问题(​​1类)。我的主文件夹包含两个文件夹,即(a)img(b)maskimg包含图像样本,mask包含相应的蒙版。我的方法是生成图像的路径,然后更改字符串路径(即img-> mask)。我修改了提供的代码here,现在看起来是:

def process_path(file_path):
  file_path_str = str(file_path)
  file_path_mask = file_path_str.replace('img', 'mask') 
  # load the raw data from the file as a string
  img = tf.io.read_file(file_path)
  img = decode_img(img)

  mask = tf.io.read_file(str(file_path_mask))
  mask = decode_mask(mask)
  return img, mask

但是,当我尝试使用以下方法查看样本大小时:

for image, mask in labeled_ds.take(1):
  print("Image shape: ", image.numpy().shape)
  print("Mask shape: ", mask.numpy().shape)

我收到以下错误:

InvalidArgumentError: NewRandomAccessFile failed to Create/Open: Tensor("arg0:0", shape=(), dtype=string) : The filename, directory name, or volume label syntax is incorrect. ; Unknown error [[{{node ReadFile_1}}]] [Op:IteratorGetNextSync]

问题:关于如何从给定的文件夹中读取图像和遮罩而没有以上错误的任何建议?

我正在尝试通过以下链接读取图像数据集以了解分割问题(​​1-类)。我的主文件夹包含两个文件夹,即(a)img(b)蒙版。 img包含图像样本和蒙版...

tensorflow tensorflow-datasets
1个回答
0
投票

我们可以使用tf.regex.replace重命名字符串。因此,代替python字符串替换,请使用:file_path_mask = tf.regex_replace(file_path, "img", "mask")。对于TF 2.0,请使用tf.strings.regex_replace

© www.soinside.com 2019 - 2024. All rights reserved.