pytorch_geometric 源碼學習


項目地址:https://github.com/rusty1s/pytorch_geometric

作者大神真的太屌了,膜拜,工程實現能力太強了

本文希望能夠記錄學習其源碼的過程

data / dataset 部分(涉及優化?)

 

語法

 

 

@property 

一種Python內置裝飾器,可以將一個成員函數當成成員變量來訪問,

例如:

class Planetoid(InMemoryDataset):
    
    url = 'https://github.com/kimiyoung/planetoid/raw/master/data'

    def __init__(self, root, name, transform=None, pre_transform=None):
        self.name = name
        super(Planetoid, self).__init__(root, transform, pre_transform)
        self.data, self.slices = torch.load(self.processed_paths[0])

    @property
    def raw_dir(self):
        return osp.join(self.root, self.name, 'raw')

    @property
    def processed_dir(self):
        return osp.join(self.root, self.name, 'processed')

    @property
    def raw_file_names(self):
        names = ['x', 'tx', 'allx', 'y', 'ty', 'ally', 'graph', 'test.index']
        return ['ind.{}.{}'.format(self.name.lower(), name) for name in names]

    @property
    def processed_file_names(self):
        return 'data.pt'

    def __repr__(self):
        return '{}()'.format(self.name)

可以直接調用

dataset = Planetoid(path, dataset, T.NormalizeFeatures())
raw_file_names = dataset.raw_file_names

可參考:https://www.liaoxuefeng.com/wiki/897692888725344/923030547069856

 

__repr__(self)
Python內置函數,自定義輸出對象信息

可參考:http://c.biancheng.net/view/2367.html

 

(待更)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM