Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dgl
Commits
fe96f11f
Unverified
Commit
fe96f11f
authored
Sep 15, 2023
by
Rhett Ying
Committed by
GitHub
Sep 15, 2023
Browse files
[GraphBolt] enable to download built-in dataset from s3 (#6329)
parent
c036222b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
1 deletion
+49
-1
python/dgl/graphbolt/impl/ondisk_dataset.py
python/dgl/graphbolt/impl/ondisk_dataset.py
+30
-1
tests/python/pytorch/graphbolt/impl/test_ondisk_dataset.py
tests/python/pytorch/graphbolt/impl/test_ondisk_dataset.py
+19
-0
No files found.
python/dgl/graphbolt/impl/ondisk_dataset.py
View file @
fe96f11f
...
@@ -11,6 +11,7 @@ import yaml
...
@@ -11,6 +11,7 @@ import yaml
import
dgl
import
dgl
from
...data.utils
import
download
,
extract_archive
from
..base
import
etype_str_to_tuple
from
..base
import
etype_str_to_tuple
from
..dataset
import
Dataset
,
Task
from
..dataset
import
Dataset
,
Task
from
..itemset
import
ItemSet
,
ItemSetDict
from
..itemset
import
ItemSet
,
ItemSetDict
...
@@ -29,7 +30,7 @@ from .ondisk_metadata import (
...
@@ -29,7 +30,7 @@ from .ondisk_metadata import (
)
)
from
.torch_based_feature_store
import
TorchBasedFeatureStore
from
.torch_based_feature_store
import
TorchBasedFeatureStore
__all__
=
[
"OnDiskDataset"
,
"preprocess_ondisk_dataset"
]
__all__
=
[
"OnDiskDataset"
,
"preprocess_ondisk_dataset"
,
"BuiltinDataset"
]
def
_copy_or_convert_data
(
def
_copy_or_convert_data
(
...
@@ -473,3 +474,31 @@ class OnDiskDataset(Dataset):
...
@@ -473,3 +474,31 @@ class OnDiskDataset(Dataset):
)
)
ret
=
ItemSetDict
(
data
)
ret
=
ItemSetDict
(
data
)
return
ret
return
ret
class
BuiltinDataset
(
OnDiskDataset
):
"""GraphBolt builtin on-disk dataset.
This class is used to help download datasets from DGL S3 storage and load
them as ``OnDiskDataset``.
Parameters
----------
name : str
The name of the builtin dataset.
root : str, optional
The root directory of the dataset. Default ot ``datasets``.
"""
_base_url
=
"https://data.dgl.ai/dataset/graphbolt/"
def
__init__
(
self
,
name
:
str
,
root
:
str
=
"datasets"
)
->
OnDiskDataset
:
dataset_dir
=
os
.
path
.
join
(
root
,
name
)
if
not
os
.
path
.
exists
(
dataset_dir
):
url
=
self
.
_base_url
+
name
+
".zip"
os
.
makedirs
(
root
,
exist_ok
=
True
)
zip_file_path
=
os
.
path
.
join
(
root
,
name
+
".zip"
)
download
(
url
,
path
=
zip_file_path
)
extract_archive
(
zip_file_path
,
root
,
overwrite
=
True
)
os
.
remove
(
zip_file_path
)
super
().
__init__
(
dataset_dir
)
tests/python/pytorch/graphbolt/impl/test_ondisk_dataset.py
View file @
fe96f11f
...
@@ -1694,3 +1694,22 @@ def test_OnDiskDataset_load_tasks():
...
@@ -1694,3 +1694,22 @@ def test_OnDiskDataset_load_tasks():
original_train_set
=
None
original_train_set
=
None
modify_train_set
=
None
modify_train_set
=
None
dataset
=
None
dataset
=
None
def
test_BuiltinDataset
():
"""Test BuiltinDataset."""
with
tempfile
.
TemporaryDirectory
()
as
test_dir
:
# Case 1: download from DGL S3 storage.
dataset_name
=
"test-only"
dataset
=
gb
.
BuiltinDataset
(
name
=
dataset_name
,
root
=
test_dir
).
load
()
assert
dataset
.
graph
is
not
None
assert
dataset
.
feature
is
not
None
assert
dataset
.
tasks
is
not
None
assert
dataset
.
dataset_name
==
dataset_name
# Case 2: dataset is already downloaded.
dataset
=
gb
.
BuiltinDataset
(
name
=
dataset_name
,
root
=
test_dir
).
load
()
assert
dataset
.
graph
is
not
None
assert
dataset
.
feature
is
not
None
assert
dataset
.
tasks
is
not
None
assert
dataset
.
dataset_name
==
dataset_name
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment