openmmlab classification将文件夹内训练数据写入txt文档

文件目录形式如下:
mynet
├── train
│ ├── 0
│ │ ├── 1_10026.tif
│ │ ├── 1_10027.tif
│ │ ├── …
│ ├── …
│ ├── 1
│ │ ├── 1_999.tif
│ │ ├── 1_9993.tif
│ │ ├── …
├── val
│ ├── 0
│ │ ├── 0_10026.tif
│ │ ├── 0_10027.tif
│ │ ├── …
│ ├── …
│ ├── 1
│ │ ├── 1_999.tif
│ │ ├── 1_9993.tif
│ │ ├── …
————————————————

import os

filePath = 'D:\\DeepLearning\\mmclassfication_res\\data\\mynet\\train'
with open("D:\\DeepLearning\\mmclassfication_res\\data\\mynet\\train.txt", "w+") as f:
    for train_class in os.listdir(filePath):
        for pic in os.listdir(filePath + '\\' + train_class):
            if os.path.splitext(pic)[1] == '.tif':
                 f.write(pic + ' ' + train_class + '\n')

filePath = 'D:\\DeepLearning\\mmclassfication_res\\data\\mynet\\val'
with open("D:\\DeepLearning\\mmclassfication_res\\data\\mynet\\val.txt", "w+") as f:
    for train_class in os.listdir(filePath):
        for pic in os.listdir(filePath + '\\' + train_class):
            if os.path.splitext(pic)[1] == '.tif':
                 f.write(pic + ' ' + train_class + '\n')

生成train.txtval.txt两个文件,如下:
openmmlab classification将文件夹内训练数据写入txt文档_第1张图片

你可能感兴趣的:(深度学习心得)