Solution to the problem of loading the data set_mobile file code

There were some problems when reproducing the GitHub project. It is strange that every project will encounter problems that have not been seen before. With the help of the author, I successfully started training this project-Region Normalization for Image Inpainting.
Yesterday, I took a closer look at the code. Although I don’t understand everything , the amount of code in this project is not large, and the logical relationship in most places is relatively clear, which is beneficial. debugging.

Question :
1.Insert picture description here
This problem first appeared. The basic information found on the Internet is that the program does not have permission to access this path'/data'. After careful searching and thinking, I found that there is no such path under my account. Later, I found that it was a parameter of the object created by the program, which was the default model save path. Just change it to your own path.

2.Insert picture description hereInsert picture description here
Although one of the above two pictures can run the program and one error, but the same error. You can see that the number of files loaded after loading datasets is 1 and the other is 0. Obviously, there must be a problem with only 1 training set.

Start single step!
The following is a record of single-step debugging: The
problem lies in the dataloader module, then set a breakpoint where you print the'===> Loading datasets'.
Insert picture description here
Here you can also use pycharm to view the code, which can facilitate the grasp of the code. For example, you can know that when you step to line 262, you will enter the build_dataloader function. After entering the function under linux, pycharm also goes to the target code.
Insert picture description here
Here you can see that it has entered the Daraset function again. Continue to follow up.
Insert picture description here
You can see that flist is the path of the data set we gave, pointing to a flist file, the content of this file is the image of the training set. No problem here, continue to enter the function self.load_flist().
Insert picture description here
Here you can see that the load_flist function loads the data set and finally only loads the file'val_image.flist', but not the data set pointed to by the file content. The above total instance number=1 is also clear.
Insert picture description here
You can see that the problem lies in the flist file, which is generated by the code given in the author's project. If it doesn't work, then don't use him. In the code for loading the data set above, it can be seen that when the data set is read in, it is judged whether the data path given when running the program is a directory or a file. For the image_flist and mask_flist in the figure below, I will directly give them the absolute path of the data set. The following is before and after the modification. So
Insert picture description here
Insert picture description here
far, you can load the data set by directly specifying the path.

3. In the
end, the following error appeared. I was
Insert picture description here
puzzled. After checking it for a long time, I didn't find an accurate solution. Finally, the author reminded that the path of the mask was wrong and it was not loaded. After the modification, the training started successfully.

another:

In the process of debugging this code, I was familiar with isinstance() to determine the object type, glob.glob() to match the file name, and it was the first time to use pdb to single-step debug python.
Because the pictures with different contents under the data set are in different folders, they need to be collected under one folder, and the following functions are used

import os,shutil
sourceDir=''			#源目录
targetDir=''            #目标目录
for root, dirs, files in os.walk(sourceDir):
    for file in files:
        shutil.copy(os.path.join(root,file),targetDir) #复制
      # shutil.move(os.path.join(root,file),targetDir) #移动

Where root is the current directory,
dirs is all subdirectories
of the current directory , files is all the files in the current directory,
this program can traverse to all the files in the subdirectories under the sourceDir directory.

Guess you like

Origin blog.csdn.net/qq_41872271/article/details/105285028