文件目录形式如下:
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.txt
和val.txt
两个文件,如下: