cityscape train.txt 数据 python读取子文件夹内所有文件

类似于:cityscapes前面的都是我自己的文件夹,你看你需要多长的自己截取.

./cityscapes/leftImg8bit/train/krefeld/krefeld_000000_032845_leftImg8bit.png
./cityscapes/leftImg8bit/train/krefeld/krefeld_000000_003707_leftImg8bit.png
./cityscapes/leftImg8bit/train/krefeld/krefeld_000000_034686_leftImg8bit.png
./cityscapes/leftImg8bit/train/krefeld/krefeld_000000_027075_leftImg8bit.png
./cityscapes/leftImg8bit/train/krefeld/krefeld_000000_010160_leftImg8bit.png
./cityscapes/leftImg8bit/train/krefeld/krefeld_000000_017342_leftImg8bit.png
./cityscapes/leftImg8bit/train/krefeld/krefeld_000000_002083_leftImg8bit.png
./cityscapes/leftImg8bit/train/krefeld/krefeld_000000_006274_leftImg8bit.png
./cityscapes/leftImg8bit/train/krefeld/krefeld_000000_005252_leftImg8bit.png
./cityscapes/leftImg8bit/train/krefeld/krefeld_000000_003096_leftImg8bit.png

生成代码:

def _get_files(data, dataset_split):
  """Gets files for the specified data type and dataset split.

  Args:
    data: String, desired data ('image' or 'label').
    dataset_split: String, dataset split ('train', 'val', 'test')

  Returns:
    A list of sorted file names or None when getting label for
      test set.
  """
  if data == 'label' and dataset_split == 'test':
    return None
  pattern = '*%s.%s' % (_POSTFIX_MAP[data], _DATA_FORMAT_MAP[data])
  search_files = os.path.join(
      FLAGS.cityscapes_root, _FOLDERS_MAP[data], dataset_split, '*', pattern)
  filenames = glob.glob(search_files)
  train_ob = open('test.txt', 'w')
  for ip in filenames:
      train_ob.write(ip)
      train_ob.write('\n')
  train_ob.close()
  return sorted(filenames)

然后我把我自己生成的上传一下吧:

https://download.csdn.net/download/u013249853/11866773

你可能感兴趣的:(cityscape train.txt 数据 python读取子文件夹内所有文件)