Exemplo n.º 1
0
    def pretreatment(self, data, test=False):
        '''
        将从dataloader加载出来的data转化为可以传入神经网络的数据
        '''
        import torch
        from torch.autograd import Variable
        from utils.loadData import loadData

        image = torch.FloatTensor(self.opt.MODEL.BATCH_SIZE,
                                  self.opt.IMAGE.IMG_CHANNEL,
                                  self.opt.IMAGE.IMG_H, self.opt.IMAGE.IMG_H)
        text = torch.LongTensor(self.opt.MODEL.BATCH_SIZE * 5)
        text_rev = torch.LongTensor(self.opt.MODEL.BATCH_SIZE * 5)
        length = torch.IntTensor(self.opt.MODEL.BATCH_SIZE)

        if self.opt.BASE.CUDA:
            # self.model = torch.nn.DataParallel(self.model, device_ids=range(self.opt.ngpu))
            image = image.cuda()
            text = text.cuda()
            text_rev = text_rev.cuda()
            self.criterion = self.criterion.cuda()

        image = Variable(image)
        text = Variable(text)
        text_rev = Variable(text_rev)
        length = Variable(length)

        cpu_images, cpu_texts = data
        loadData(image, cpu_images)
        t, l = self.converter.encode(cpu_texts, scanned=True)
        loadData(text, t)
        loadData(length, l)
        return image, length, text, text_rev, test
Exemplo n.º 2
0
# 网络训练网络文件名
trainName = "bitcoinAlpha"  # bitcoinAlpha bitcoinOTC epinions_truncated slashdot_truncated
# 网络经过tsvd分解的特征大小 默认为64
int_features = 64
# 模型
modelName = "GCN"  # GCN or HGCN
# 网络卷积后的特征大小 默认为64
out_features = 64
# 卷积层大小,即1次邻居卷积 加num_layers-1层间接邻居卷积
num_layers = 2
# loss 参数
lambda_structure = 5
# 学习率
lr = 0.01

pos_edge_index, neg_edge_index = loadData(trainFiles, trainName)
train_pos_edge_index, test_pos_edge_index = split_edges(pos_edge_index)
train_neg_edge_index, test_neg_edge_index = split_edges(neg_edge_index)
# 自训练向量大小
posAtt = train_pos_edge_index.shape[1]
negAtt = train_neg_edge_index.shape[1]

model = None
if modelName == "HGCN":
    model = SignHGCN(int_features,
                     out_features,
                     num_layers=num_layers,
                     lambda_structure=lambda_structure)
if modelName == "GCN":
    model = SignGCN(int_features,
                    out_features,