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

Format of 'flist' #15

Open
AterLuna opened this issue Apr 18, 2018 · 38 comments
Open

Format of 'flist' #15

AterLuna opened this issue Apr 18, 2018 · 38 comments
Labels
good first issue Good for newcomers

Comments

@AterLuna
Copy link

AterLuna commented Apr 18, 2018

I want to train network with new dataset.
For training, I tried to modify inpaint.yml file, but I'm not sure about how to set dataset path.
It seems that I have to add new dataset as 'flist' file to DATA_FLIST, but I cannot find how to make appropriate 'flist' files.
Is there any reference for flist file format, or some examples of them?

@TrinhQuocNguyen
Copy link

TrinhQuocNguyen commented Apr 18, 2018

Hi AterLuna,
You have to write code for yourself to generate the flist file. Here is my code:

#!/usr/bin/python

import argparse
import os
from random import shuffle

parser = argparse.ArgumentParser()
parser.add_argument('--folder_path', default='./training_data', type=str,
                    help='The folder path')
parser.add_argument('--train_filename', default='./data_flist/train_shuffled.flist', type=str,
                    help='The output filename.')
parser.add_argument('--validation_filename', default='./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 + "/" + dir_item
        # print(dir_item)

        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.mknod(args.train_filename)

    if not os.path.exists(args.validation_filename):
        os.mknod(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)



@JiahuiYu
Copy link
Owner

@TrinhQuocNguyen Thanks for you response. @AterLuna In addition, the format of file lists are attached. You can either use absolute path or relative path for training.

/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00027049.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00017547.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00023248.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00029613.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00007055.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00021404.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00008928.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00003579.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00010811.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00014556.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00015131.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00015634.png
...
...

@AterLuna
Copy link
Author

@TrinhQuocNguyen Thank you for sharing your codes. I'll try it with my dataset.
@JiahuiYu Thank you for your example.

@TrinhQuocNguyen
Copy link

TrinhQuocNguyen commented Apr 18, 2018

@AterLuna , Supposed you want to use my code, you need to make a new directory named training_data. In that directory, you make 2 more new directories: training and validation respectively and put your images in those.
@JiahuiYu You are super welcome, thank you for your contribution.

@javanli
Copy link

javanli commented Jun 26, 2018

@TrinhQuocNguyen
In your code ,line 41,for validation_item in training_folder:
maybe it should be for validation_item in validation_folder?

@TrinhQuocNguyen
Copy link

TrinhQuocNguyen commented Jul 5, 2018

I have modified a little bit for anyone needs it. Moreover, you may apply "data augmentation" and put them into other folders ( folder1, folder2,...) without being messy 😄
The directory tree should be looked like:

- model_logs
- neuralgym_logs
- training_data
  -- training
    --- <folder1>
    --- <folder2>
    --- .....
  -- validation
    --- <val_folder1>
    --- <val_folder2>
    --- .....
- <this_file.py>
import argparse
import os
from random import shuffle

parser = argparse.ArgumentParser()
parser.add_argument('--folder_path', default='./training_data', type=str,
                    help='The folder path')
parser.add_argument('--train_filename', default='./data_flist/train_shuffled.flist', type=str,
                    help='The train filename.')
parser.add_argument('--validation_filename', default='./data_flist/validation_shuffled.flist', type=str,
                    help='The validation filename.')
parser.add_argument('--is_shuffled', default='1', type=int,
                    help='Needed to be shuffled')

if __name__ == "__main__":

    args = parser.parse_args()

    # get the list of directories and separate them into 2 types: training and validation
    training_dirs = os.listdir(args.folder_path + "/training")
    validation_dirs = os.listdir(args.folder_path + "/validation")

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

    # append all files into 2 lists
    for training_dir in training_dirs:
        # append each file into the list file names
        training_folder = os.listdir(args.folder_path + "/training" + "/" + training_dir)
        for training_item in training_folder:
            # modify to full path -> directory
            training_item = args.folder_path + "/training" + "/" + training_dir + "/" + training_item
            training_file_names.append(training_item)

    # append all files into 2 lists
    for validation_dir in validation_dirs:
        # append each file into the list file names
        validation_folder = os.listdir(args.folder_path + "/validation" + "/" + validation_dir)
        for validation_item in validation_folder:
            # modify to full path -> directory
            validation_item = args.folder_path + "/validation" + "/" + validation_dir + "/" + 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)

    # 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.mknod(args.train_filename)

    if not os.path.exists(args.validation_filename):
        os.mknod(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)

@ChiediVenia
Copy link

I have modified a little bit for anyone needs it. Moreover, you may apply "data augmentation" and put them into other folders ( folder1, folder2,...) without being messy smile
The directory tree should be looked like:

- model_logs
- neuralgym_logs
- training_data
  -- training
    --- <folder1>
    --- <folder2>
    --- .....
  -- validation
    --- <val_folder1>
    --- <val_folder2>
    --- .....
- <this_file.py>
import argparse
import os
from random import shuffle

parser = argparse.ArgumentParser()
parser.add_argument('--folder_path', default='./training_data', type=str,
                    help='The folder path')
parser.add_argument('--train_filename', default='./data_flist/train_shuffled.flist', type=str,
                    help='The train filename.')
parser.add_argument('--validation_filename', default='./data_flist/validation_shuffled.flist', type=str,
                    help='The validation filename.')
parser.add_argument('--is_shuffled', default='1', type=int,
                    help='Needed to be shuffled')

if __name__ == "__main__":

    args = parser.parse_args()

    # get the list of directories and separate them into 2 types: training and validation
    training_dirs = os.listdir(args.folder_path + "/training")
    validation_dirs = os.listdir(args.folder_path + "/validation")

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

    # append all files into 2 lists
    for training_dir in training_dirs:
        # append each file into the list file names
        training_folder = os.listdir(args.folder_path + "/training" + "/" + training_dir)
        for training_item in training_folder:
            # modify to full path -> directory
            training_item = args.folder_path + "/training" + "/" + training_dir + "/" + training_item
            training_file_names.append(training_item)

    # append all files into 2 lists
    for validation_dir in validation_dirs:
        # append each file into the list file names
        validation_folder = os.listdir(args.folder_path + "/validation" + "/" + validation_dir)
        for validation_item in validation_folder:
            # modify to full path -> directory
            validation_item = args.folder_path + "/validation" + "/" + validation_dir + "/" + 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)

    # 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.mknod(args.train_filename)

    if not os.path.exists(args.validation_filename):
        os.mknod(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)

I created the folder tree, I put the images in the folders, I launch the file with your code and I return this:

./training_data/training/folder1/asd.jpg
./training_data/training/folder6/vdikkj.jpeg
./training_data/training/folder4/vdb.jpeg
./training_data/training/folder2/images.jpeg
./training_data/training/folder3/scv.jpeg
./training_data/training/folder5/waq.jpeg
./training_data/training/folder8/123.jpeg
./training_data/training/folder9/das.jpeg
./training_data/training/folder7/index.jpeg
./training_data/validation/val_folder6/vdikkj.jpeg
./training_data/validation/val_folder9/das.jpeg
./training_data/validation/val_folder1/asd.jpg
./training_data/validation/val_folder2/images.jpeg
./training_data/validation/val_folder7/index.jpeg
./training_data/validation/val_folder3/scv.jpeg
./training_data/validation/val_folder5/waq.jpeg
./training_data/validation/val_folder8/123.jpeg
./training_data/validation/val_folder4/vdb.jpeg
Traceback (most recent call last):
File "this_file.py", line 58, in
os.mknod(args.train_filename)
FileNotFoundError: [Errno 2] No such file or directory

Can you help me?please.

@JiahuiYu
Copy link
Owner

JiahuiYu commented Oct 9, 2018

@ChiediVenia Please make sure that your input file exists. Normally it can be fixed by a careful check.

@ChiediVenia
Copy link

@ChiediVenia Please make sure that your input file exists. Normally it can be fixed by a careful check.

congratulations for the job ... and thanks for the reply.
What should be the input file?
I have created only the folders following the outline and the images of the sub folders. I havent created any other files or folders

@JiahuiYu
Copy link
Owner

JiahuiYu commented Oct 9, 2018

@ChiediVenia I wonder if you already have the following files and folders.

parser.add_argument('--folder_path', default='./training_data', type=str,
                    help='The folder path')
parser.add_argument('--train_filename', default='./data_flist/train_shuffled.flist', type=str,
                    help='The output filename.')
parser.add_argument('--validation_filename', default='./data_flist/validation_shuffled.flist', type=str,
                    help='The output filename.')

@ChiediVenia
Copy link

@ChiediVenia I wonder if you already have the following files and folders.

parser.add_argument('--folder_path', default='./training_data', type=str,
                    help='The folder path')
parser.add_argument('--train_filename', default='./data_flist/train_shuffled.flist', type=str,
                    help='The output filename.')
parser.add_argument('--validation_filename', default='./data_flist/validation_shuffled.flist', type=str,
                    help='The output filename.')

Thank you for your help

@TerminatorSd
Copy link

TerminatorSd commented Jan 31, 2019

os.mknod is not available to users on Mac OS, the solution can be found there Replaces os.mknod with portable equivalent

In short, replace mknod with open, like this:

os.open(args.train_filename, os.O_CREAT)
# os.mknod(args.train_filename)

@JiahuiYu
Copy link
Owner

@TerminatorSd I appreciate your information to this issue!

@YangSN0719

This comment has been minimized.

@YangSN0719
Copy link

I shall be very grateful to you

@JiahuiYu
Copy link
Owner

JiahuiYu commented Mar 9, 2019

@YangSN0719 Hi, most likely that your file list is incorrect. The error means there is no image file with the file list you provided. Please check carefully. One suggestion is to use absolute path of file list.

@YangSN0719
Copy link

Thank you very much for your reply. As a beginner, I am very sorry to disturb you. I will check your source file again @JiahuiYu

@YangSN0719
Copy link

@TrinhQuocNguyen
First of all, thank you very much for your source code, but the file I generated is unusually large, and there are not many pictures. I only selected 5000 for training and 300 for testing. The generated file screenshots are as follows,I would appreciate your reply
QQ截图20190312205018

@YangSN0719
Copy link

@TrinhQuocNguyen Sorry, as a beginner, I am very sorry to disturb you, I will look at your source file again, I hope you can send me your inpaint.yml file for my reference, thank you very much

@JiahuiYu
Copy link
Owner

@YangSN0719 I think you need line break for different image files, right? Each image file occupies one line.

@TrinhQuocNguyen
Copy link

TrinhQuocNguyen commented Mar 13, 2019

@TrinhQuocNguyen Sorry, as a beginner, I am very sorry to disturb you, I will look at your source file again, I hope you can send me your inpaint.yml file for my reference, thank you very much

@YangSN0719 I think you need line break for different image files, right? Each image file occupies one line.

That is what I think: you need line break like the author has provided as follows:

/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00027049.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00017547.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00023248.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00029613.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00007055.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00021404.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00008928.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00003579.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00010811.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00014556.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00015131.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00015634.png
...
...

@YangSN0719
Copy link

@TrinhQuocNguyen @JiahuiYu
Thank you very much for your reply.My problem has been solved and is under training,
please refer to the following link
https://blog.csdn.net/Gavinmiaoc/article/details/81250782

@JiahuiYu JiahuiYu added the good first issue Good for newcomers label Aug 9, 2019
@lx120
Copy link

lx120 commented Nov 21, 2019

Hi, should I use how many valid images in training process? Is it have any influence to training?

@JiahuiYu
Copy link
Owner

@lx120 The number of validation images does not affect training. They are for "validation" purpose.

Repository owner deleted a comment from redaghanem Jan 25, 2020
@JiahuiYu JiahuiYu reopened this Jan 25, 2020
@redaghanem
Copy link

Please i need help to train your model

I get error while training

@decajcd
Copy link

decajcd commented Feb 25, 2020

What is the number of training image channels?3 or 4?

@minushuang
Copy link

minushuang commented Jun 3, 2020

@TrinhQuocNguyen Thanks for you response. @AterLuna In addition, the format of file lists are attached. You can either use absolute path or relative path for training.

/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00027049.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00017547.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00023248.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00029613.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00007055.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00021404.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00008928.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00003579.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00010811.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00014556.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00015131.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00015634.png
...
...

thank u very much for your source code.my question is that the input for training need three pair images, it contains a raw image with mask, a mask and a inpainted image. but it seems that the file list you offered only have one type? what should i do if want to train with three-pairs input

@minushuang
Copy link

It's OK, the mask is auto generated in the code,thanks

@TrinhQuocNguyen Thanks for you response. @AterLuna In addition, the format of file lists are attached. You can either use absolute path or relative path for training.

/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00027049.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00017547.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00023248.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00029613.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00007055.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00021404.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00008928.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00003579.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00010811.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00014556.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00015131.png                                                                                                                                                                                                               
/home/jiahui.yu/data/celeba_hq/celeba_hq_images/img00015634.png
...
...

thank u very much for your source code.my question is that the input for training need three pair images, it contains a raw image with mask, a mask and a inpainted image. but it seems that the file list you offered only have one type? what should i do if want to train with three-pairs input

@Mortyzhang
Copy link

@TrinhQuocNguyen Thank you for sharing your codes. I'll try it with my dataset.
@JiahuiYu Thank you for your example.

Dear author, I want to ask if I need to prepare mask images for training? Thank you.

@HarveyYesan
Copy link

@TrinhQuocNguyen
Shell commands can achieve the same function to generate file lists. as following:
find folder/ -name "*.png" | sort > filepath.txt

Hi AterLuna,
You have to write code for yourself to generate the flist file. Here is my code:

#!/usr/bin/python

import argparse
import os
from random import shuffle

parser = argparse.ArgumentParser()
parser.add_argument('--folder_path', default='./training_data', type=str,
                    help='The folder path')
parser.add_argument('--train_filename', default='./data_flist/train_shuffled.flist', type=str,
                    help='The output filename.')
parser.add_argument('--validation_filename', default='./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 + "/" + dir_item
        # print(dir_item)

        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.mknod(args.train_filename)

    if not os.path.exists(args.validation_filename):
        os.mknod(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)

@win-ner
Copy link

win-ner commented Jan 2, 2021

Must it be divided into training set and validation set?

@sdulyq
Copy link

sdulyq commented Apr 13, 2021

I write something easy to modify.

from random import shuffle
import os

train_filename = 'G:/image_inpainting/train_shuffled.flist'
validation_filename = 'G:/image_inpainting/validation_shuffled.flist'
training_file_names = []
validation_file_names = []
training_path = 'G:/image_inpainting/training'
validation_path = 'G:/image_inpainting/validation'
training_items = os.listdir(training_path)
validation_items = os.listdir(validation_path)

# loop
for training_item in training_items:
    training_item = training_path + training_item
    training_file_names.append(training_item)

for validation_item in validation_items:
    validation_item = validation_path + validation_item
    validation_file_names.append(validation_item)


shuffle(training_file_names)
shuffle(validation_file_names)
# write
fo = open(train_filename, "w")
fo.write("\n".join(training_file_names))
fo.close()

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

@hashimhafeez
Copy link

Hi AterLuna,
You have to write code for yourself to generate the flist file. Here is my code:

#!/usr/bin/python

import argparse
import os
from random import shuffle

parser = argparse.ArgumentParser()
parser.add_argument('--folder_path', default='./training_data', type=str,
                    help='The folder path')
parser.add_argument('--train_filename', default='./data_flist/train_shuffled.flist', type=str,
                    help='The output filename.')
parser.add_argument('--validation_filename', default='./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 + "/" + dir_item
        # print(dir_item)

        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.mknod(args.train_filename)

    if not os.path.exists(args.validation_filename):
        os.mknod(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)

Hello i am newbe
Where should i place this code same inpait.yml file or to creat new one?

@eduardatmadenn
Copy link

Small detail here about the folder structure, maybe it helps: The code works as is, if the folder hierarchy is like this:

project_root/
├─ training_data/
│  ├─ name_of_db/
│  │  ├─ training/
│  │  ├─ validation/

@mowei951010
Copy link

I want to fix my photos, but running inpaint_ops.py doesn't work,
Hope the author can more detailed information I want to learn

@AnhPC03
Copy link

AnhPC03 commented Mar 12, 2023

Hi @JiahuiYu , @TrinhQuocNguyen
The flist.txt file only contains path to normal images? Where do I put mask of that images? Thank you

@fittiing
Copy link

嗨 AterLuna, 您必须自己编写代码来生成 flist 文件。这是我的代码:

#!/usr/bin/python

import argparse
import os
from random import shuffle

parser = argparse.ArgumentParser()
parser.add_argument('--folder_path', default='./training_data', type=str,
                    help='The folder path')
parser.add_argument('--train_filename', default='./data_flist/train_shuffled.flist', type=str,
                    help='The output filename.')
parser.add_argument('--validation_filename', default='./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 + "/" + dir_item
        # print(dir_item)

        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.mknod(args.train_filename)

    if not os.path.exists(args.validation_filename):
        os.mknod(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)

May I ask which directory and folder to place this. flist file in after writing?

@fittiing
Copy link

你好 AterLuna, 您必须自己编写代码来生成 flist 文件。这是我的代码:

#!/usr/bin/python

import argparse
import os
from random import shuffle

parser = argparse.ArgumentParser()
parser.add_argument('--folder_path', default='./training_data', type=str,
                    help='The folder path')
parser.add_argument('--train_filename', default='./data_flist/train_shuffled.flist', type=str,
                    help='The output filename.')
parser.add_argument('--validation_filename', default='./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 + "/" + dir_item
        # print(dir_item)

        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.mknod(args.train_filename)

    if not os.path.exists(args.validation_filename):
        os.mknod(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)

Hello, I ran according to your code and encountered this error. How can I solve it? Isn't this code creating a . flit file?Traceback (most recent call last):
File ".\1.py", line 59, in
with open(args.train_filename, 'w') as f:
FileNotFoundError: [Errno 2] No such file or directory: './data_flist/train_shuffled.flist'

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

No branches or pull requests