【发布时间】:2020-07-18 17:15:19
【问题描述】:
我有一个文件,其中包含我想加载到 Pytorch 中的图像路径,同时利用内置的数据加载器功能(多进程加载管道、数据增强等)。
def create_links():
data_dir = "/myfolder"
full_path_list = []
assert os.path.isdir(data_dir)
for _, _, filenames in os.walk(data_dir):
for filename in filenames:
full_path_list.append(os.path.join(data_dir, filename))
with open(config.data.links_file, 'w+') as links_file:
for full_path in full_path_list:
links_file.write(f"{full_path}\n")
def read_links_file_to_list():
config = ConfigProvider.config()
links_file_path = config.data.links_file
if not os.path.isfile(links_file_path):
raise RuntimeError("did you forget to create a file with links to images? Try using 'create_links()'")
with open(links_file_path, 'r') as links_file:
return links_file.readlines()
所以我有一个文件列表(或生成器,或其他任何工作),file_list = read_links_file_to_list()。
如何围绕它构建 Pytorch 数据加载器,以及如何使用它?
【问题讨论】:
-
你不能得到比pytorch.org官网后缀为beginner/data_loading_tutorial.html的文档更多的beginner。如果你想进入深度学习领域,你将不得不做一些阅读和工作——这是没有办法的。
标签: python pytorch dataloader custom-dataset