Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

form of flist #542

Open
Tiuuuuu opened this issue Jun 27, 2023 · 1 comment
Open

form of flist #542

Tiuuuuu opened this issue Jun 27, 2023 · 1 comment

Comments

@Tiuuuuu
Copy link

Tiuuuuu commented Jun 27, 2023

#!/usr/bin/python
import pdb
import argparse
import os
from random import shuffle

parser = argparse.ArgumentParser()
parser.add_argument('--folder_path', default='D:/shenduxuexi/generative_inpainting-master/training_data', type=str,
help='The folder path')
parser.add_argument('--train_filename', default='D:/shenduxuexi/generative_inpainting-master/data_flist/train_shuffled.flist', type=str,
help='The output filename.')
parser.add_argument('--validation_filename', default='D:/shenduxuexi/generative_inpainting-master/data_flist/validation_shuffled.flist', type=str,
help='The output filename.')
parser.add_argument('--is_shuffled', default='1', type=int,
help='Needed to shuffle')

if name == "main":

args = parser.parse_args()

# get the list of directories
dirs = os.listdir(args.folder_path)
dirs_name_list = []

# make 2 lists to save file paths
training_file_names = []
validation_file_names = []

# print all directory names
for dir_item in dirs:
    # modify to full path -> directory
    dir_item = args.folder_path + "/"
    print(dir_item)
    #pdb.set_trace()
    training_folder = os.listdir(dir_item + "/training")
    for training_item in training_folder:
        training_item = dir_item + "/training" + "/" + training_item
        training_file_names.append(training_item)

    validation_folder = os.listdir(dir_item + "/validation")
    for validation_item in validation_folder:
        validation_item = dir_item + "/validation" + "/" + validation_item
        validation_file_names.append(validation_item)
# print all file paths
for i in training_file_names:
    print(i)
for i in validation_file_names:
    print(i)

# This would print all the files and directories

# shuffle file names if set
if args.is_shuffled == 1:
    shuffle(training_file_names)
    shuffle(validation_file_names)

# make output file if not existed
if not os.path.exists(args.train_filename):
    # os.mkon()函数在window系统不适用,改成open()函数,但是open()函数不能创建文件,所以需要手动创建文件train_shuffled.flist和
    #    validation_shuffled.flist两个文件
    open(args.train_filename)

if not os.path.exists(args.validation_filename):
    open(args.validation_filename)

# write to file
fo = open(args.train_filename, "w")
fo.write("\n".join(training_file_names))
fo.close()

fo = open(args.validation_filename, "w")
fo.write("\n".join(validation_file_names))
fo.close()

# print process
print("Written file is: ", args.train_filename, ", is_shuffle: ", args.is_shuffled)

that is ok! in windows. But you should creat train_shuffled.flist and validation_shuffled.flist manually.

@Tiuuuuu
Copy link
Author

Tiuuuuu commented Jun 27, 2023

There is a question!
In .flist,a picture is repeated twice,e.g.
D:/shenduxuexi/generative_inpainting-master/training_data/training/C1A000206N000000000PAA.png
D:/shenduxuexi/generative_inpainting-master/training_data/training/Img29836.png
D:/shenduxuexi/generative_inpainting-master/training_data/training/C1A000206N000000000PAA.png
IF you have 50 pictures in .training,train_shuffled .flist have 100 rows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant