JiahuiYu / generative_inpainting

DeepFill v1/v2 with Contextual Attention and Gated Convolution, CVPR 2018, and ICCV 2019 Oral
http://jiahuiyu.com/deepfill/
Other
3.28k stars 789 forks source link

form of flist #542

Open Tiuuuuu opened 1 year ago

Tiuuuuu commented 1 year ago

!/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 commented 1 year ago

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.