import osinput_dir = "D:/dataset_2020/dataset2020_jpg"input_img_paths =( [ os.path.join(input_dir, fname) for fname in os.listdir(input_dir) if fname.endswith(".jpg") ])print(len(input_img_paths))print(input_img_paths)
python批量读取文件夹内容(第二种)from pathlib import Pathdata_dir=Path("D:/dataset_2020/dataset2020_jpg/")print(data_dir)images = sorted(list(map(str, list(data_dir.glob("*.jpg")))))print(images)labels = [img.split(os.path.sep)[-1].split(".png")[0] for img in images]print(labels)