-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Update Unsup_Graphsage (#379)
- Loading branch information
Showing
10 changed files
with
219 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
cogdl/wrappers/data_wrapper/node_classification/unsup_graphsage_dw.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from .. import DataWrapper | ||
from cogdl.data.sampler import UnsupNeighborSamplerDataset,UnsupNeighborSampler | ||
|
||
|
||
class UnsupGraphSAGEDataWrapper(DataWrapper): | ||
@staticmethod | ||
def add_args(parser): | ||
# fmt: off | ||
parser.add_argument("--batch-size", type=int, default=128) | ||
parser.add_argument("--sample-size", type=int, nargs='+', default=[10, 10]) | ||
# fmt: on | ||
|
||
def __init__(self, dataset, batch_size: int, sample_size: list): | ||
super(UnsupGraphSAGEDataWrapper, self).__init__(dataset) | ||
self.dataset = dataset | ||
self.train_dataset = UnsupNeighborSamplerDataset( | ||
dataset, sizes=sample_size, batch_size=batch_size, mask=dataset.data.train_mask | ||
) | ||
self.val_dataset = UnsupNeighborSamplerDataset( | ||
dataset, sizes=sample_size, batch_size=batch_size * 2, mask=dataset.data.val_mask | ||
) | ||
self.test_dataset = UnsupNeighborSamplerDataset( | ||
dataset=self.dataset, | ||
mask=None, | ||
sizes=[-1], | ||
batch_size=batch_size * 2, | ||
) | ||
self.x = self.dataset.data.x | ||
self.y = self.dataset.data.y | ||
self.batch_size = batch_size | ||
self.sample_size = sample_size | ||
|
||
def train_wrapper(self): | ||
self.dataset.data.train() | ||
return UnsupNeighborSampler( | ||
dataset=self.train_dataset, | ||
mask=self.dataset.data.train_mask, | ||
sizes=self.sample_size, | ||
num_workers=4, | ||
shuffle=False, | ||
batch_size=self.batch_size, | ||
) | ||
|
||
def test_wrapper(self): | ||
return ( | ||
self.dataset, | ||
UnsupNeighborSampler( | ||
dataset=self.test_dataset, | ||
mask=None, | ||
sizes=[-1], | ||
batch_size=self.batch_size * 2, | ||
shuffle=False, | ||
num_workers=4, | ||
), | ||
) | ||
|
||
def train_transform(self, batch): | ||
target_id, n_id, adjs = batch | ||
x_src = self.x[n_id] | ||
|
||
return x_src, adjs | ||
|
||
|
||
def get_train_dataset(self): | ||
return self.train_dataset | ||
|
||
def pre_transform(self): | ||
self.dataset.data.add_remaining_self_loops() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.