PyG导入HGBDataset:OSError: [Errno 22] Invalid argument: ‘data\\ACM\\acm\\raw\\?p=%2FACM.zip&dl=1‘

场景

使用PyG导入ACM数据集:

dataset = HGBDataset('data/ACM', name='ACM', transform=transform)

报错代码

Downloading https://cloud.tsinghua.edu.cn/d/2d965d2fc2ee41d09def/files/?p=%2FACM.zip&dl=1
https://cloud.tsinghua.edu.cn/d/2d965d2fc2ee41d09def/files/?p=%2FACM.zip&dl=1
path= data\ACM\acm\raw\?p=%2FACM.zip&dl=1
Traceback (most recent call last):
  File "F:/PyCharm 2021.3.3/projects/gnn-link-prediction/pyg/han_lp.py", line 36, in <module>
    dataset = HGBDataset('data/ACM', name='ACM', transform=transform)
  File "F:\Anaconda3\lib\site-packages\torch_geometric\datasets\hgb_dataset.py", line 55, in __init__
    super().__init__(root, transform, pre_transform)
  File "F:\Anaconda3\lib\site-packages\torch_geometric\data\in_memory_dataset.py", line 57, in __init__
    super().__init__(root, transform, pre_transform, pre_filter)
  File "F:\Anaconda3\lib\site-packages\torch_geometric\data\dataset.py", line 85, in __init__
    self._download()
  File "F:\Anaconda3\lib\site-packages\torch_geometric\data\dataset.py", line 146, in _download
    self.download()
  File "F:\Anaconda3\lib\site-packages\torch_geometric\datasets\hgb_dataset.py", line 78, in download
    path = download_url(url, self.raw_dir)
  File "F:\Anaconda3\lib\site-packages\torch_geometric\data\download.py", line 41, in download_url
    with open(path, 'wb') as f:
OSError: [Errno 22] Invalid argument: 'data\\ACM\\acm\\raw\\?p=%2FACM.zip&dl=1'

Process finished with exit code 1

解决

代码提示path无效,跳转到PyG源码中的相应位置:

def download_url(url: str, folder: str, log: bool = True):
    r"""Downloads the content of an URL to a specific folder.

    Args:
        url (string): The url.
        folder (string): The folder.
        log (bool, optional): If :obj:`False`, will not print anything to the
            console. (default: :obj:`True`)
    """

    filename = url.rpartition('/')[2]
    filename = filename if filename[0] == '?' else filename.split('?')[0]
    path = osp.join(folder, filename)

    if osp.exists(path):  # pragma: no cover
        if log:
            print(f'Using existing file {filename}', file=sys.stderr)
        return path

    if log:
        print(f'Downloading {url}', file=sys.stderr)

    makedirs(folder)

    context = ssl._create_unverified_context()
    print(url)
    data = urllib.request.urlopen(url, context=context)
    
    with open(path, 'wb') as f:
        f.write(data.read())

    return path

输出path:

path= data\ACM\acm\raw\?p=%2FACM.zip&dl=1

将path中的不规范符号去除:

path= 'data\ACM\acm\raw\FACM.zip'
with open(path, 'wb') as f:
        f.write(data.read())
  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Cyril_KI

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值