python - 值错误: no gopen handler defined

标签 python deep-learning pytorch pypi

我刚开始使用 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)

这导致我出现这样的错误 enter image description here

如果我使用 Web url 示例,相同的代码可以正常工作:"http://storage.googleapis.com/nvdata-openimages/openimages-train-000000.tar" webdataset文档中提到:https://reposhub.com/python/deep-learning/tmbdev-webdataset.html

到目前为止我无法理解这个错误。您知道如何解决这个问题吗?

最佳答案

从昨天开始我就遇到了同样的错误,我终于找到了罪魁祸首。 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 。这是返回您所看到的错误的函数。 pr = urlparse(url)在您的网址上将生成一个 urlparse,其中方案( pr.scheme )为 'd'因为你的磁盘名为D。但是,它应该是'file'以使该功能按预期工作。由于它不等于“file”或字典中的任何其他方案(http、https、sftp 等),因此将使用默认函数,该函数会返回错误。我通过添加 d=gopen_file 来规避这个问题到gopen_schemes字典。我希望这可以暂时帮助您。我还将在 WebDataset GitHub 页面上解决此问题,并在获得更实用的更新时保持此页面更新。

祝你好运!

关于python - 值错误: no gopen handler defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68299665/

相关文章:

Python: "foo() for i in range(bar)"是什么意思?

python - 如何将 scipy.sparse 矩阵元素乘以广播的密集一维数组?

python - 类型错误 : 'int' object is not callable in loss. 向后()

python - 如何计算图像数据集中 RGB 值的 3x3 协方差矩阵?

python-3.x - 根据pytorch数据集中的文件名拆分数据集

python - 如何在另一个 "frame window"内的窗口中查找元素的 xpath

python - 是否可以使用棉花糖验证列表?

windows - 低于3.0计算能力的GPU上的Keras?

python - Keras 使用自定义损失优化两个输出

r - 具有类别不平衡的 H2O 深度学习