“IsADirectoryError: [Errno 21] Is a directory: ” It is a file

后端 未结 3 1455
抹茶落季
抹茶落季 2020-12-19 02:10

I already split the data into test and training set into the different folder. Now I need to load the patient data. Each patient has 8 images.

def load_datas         


        
3条回答
  •  粉色の甜心
    2020-12-19 02:42

    Do you have both files and directories inside your path? os.listdir will list both files and directories, so when you try to open a directory with np.load it will give that error. You can filter only files to avoid the error:

    data_paths = [os.path.join(in_dir, f) for f in os.listdir(in_dir)]
    data_paths = [i for i in data_paths if os.path.isfile(i)]
    

    Or all together in a single line:

    data_paths = [i for i in (os.path.join(in_dir, f) for f in os.listdir(in_dir)) if os.path.isfile(i)]
    

提交回复
热议问题