使用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())