我刚开始使用pytorch的webdataset库。我已经使用webdataset.TarWriter()在系统本地创建了一个示例数据集的.tar文件。.tar文件的创建似乎是成功的,因为我可以在windows平台上分别提取它们,并验证相同的数据集文件。
现在,我创建了train_dataset = wds.Dataset(url),其中url是.tar文件的本地文件路径。在此之后,我执行以下操作:
train_loader = torch.utils.data.DataLoader(train_dataset, num_workers=0, batch_size=10)
sample = next(iter(train_loader))
print(sample)这导致我犯了这样的错误

如果我使用web示例: webdataset文档中提到的"http://storage.googleapis.com/nvdata-openimages/openimages-train-000000.tar":https://reposhub.com/python/deep-learning/tmbdev-webdataset.html,则相同的代码也可以正常工作
到目前为止我还不能理解这个错误。有没有办法解决这个问题?
发布于 2021-07-14 19:44:14
从昨天开始我也犯了同样的错误,我终于找到了罪魁祸首。WebDataset/tarIterators.py使用WebDataset/gopen.py。在gopen.py中,调用urllib.parse.urlparse来解析要打开的url,在本例中,url是D:/PhD/...。
gopen_schemes = dict(
__default__=gopen_error,
pipe=gopen_pipe,
http=gopen_curl,
https=gopen_curl,
sftp=gopen_curl,
ftps=gopen_curl,
scp=gopen_curl)
def gopen(url, mode="rb", bufsize=8192, **kw):
"""Open the URL. This uses the `gopen_schemes` dispatch table to dispatch based on scheme.
Support for the following schemes is built-in: pipe, file, http, https, sftp, ftps, scp.
When no scheme is given the url is treated as a file. You can use the OPEN_VERBOSE argument to get info about files being opened.
:param url: the source URL
:param mode: the mode ("rb", "r")
:param bufsize: the buffer size
"""
global fallback_gopen
verbose = int(os.environ.get("GOPEN_VERBOSE", 0))
if verbose:
print("GOPEN", url, info, file=sys.stderr)
assert mode in ["rb", "wb"], mode
if url == "-":
if mode == "rb":
return sys.stdin.buffer
elif mode == "wb":
return sys.stdout.buffer
else:
raise ValueError(f"unknown mode {mode}")
pr = urlparse(url)
if pr.scheme == "":
bufsize = int(os.environ.get("GOPEN_BUFFER", -1))
return open(url, mode, buffering=bufsize)
if pr.scheme == "file":
bufsize = int(os.environ.get("GOPEN_BUFFER", -1))
return open(pr.path, mode, buffering=bufsize)
handler = gopen_schemes["__default__"]
handler = gopen_schemes.get(pr.scheme, handler)
return handler(url, mode, bufsize, **kw)正如您在字典中看到的,__default__函数是gopen_error。这是返回您所看到的错误的函数。url上的pr = urlparse(url)将生成一个url解析,其中方案(pr.scheme)是'd',因为您的磁盘名为D。但是,它应该是'file',以便函数按预期工作。由于它不等于'file‘或字典中的任何其他方案(http、https、sftp等),因此将使用默认函数,该函数将返回错误。我通过在gopen_schemes字典中添加d=gopen_file避免了这个问题。我希望这对你有暂时的帮助。我也会在WebDataset的GitHub页面上解决这个问题,如果我得到了更实际的更新,我会让这个页面保持更新。
祝好运!
https://stackoverflow.com/questions/68299665
复制相似问题