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

这篇博客介绍如何将openmmlab项目中mynet目录下的train和val子目录中的图像文件路径整理成txt文档,方便进行图像分类任务的训练。内容包括遍历文件夹,读取每个类别下的图像文件,并将它们的路径记录到对应的txt文件中。
4062

被折叠的 条评论
为什么被折叠?



