kexinhuang12345 / DeepPurpose

A Deep Learning Toolkit for DTI, Drug Property, PPI, DDI, Protein Function Prediction (Bioinformatics)
https://doi.org/10.1093/bioinformatics/btaa1005
BSD 3-Clause "New" or "Revised" License
949 stars 271 forks source link

Cannot running GNN+Transformer model #152

Open yrq3027 opened 1 year ago

yrq3027 commented 1 year ago

Hi, This error happened only in GNN+Transformer model.

Let's use 1 GPU! --- Data Preparation --- --- Go for Training --- Traceback (most recent call last): File "Pharos_DeepPurpose_ATFP_clf_demo.py", line 103, in trainModel(coding) File "Pharos_DeepPurpose_ATFP_clf_demo.py", line 96, in trainModel model.train(train, val, test) File "/home/data/aidd/DeepPurpose/DeepPurpose/DTI.py", line 436, in train score = self.model(v_d, v_p) File "/home/AIDD/anaconda3/envs/DeepPurpose/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl return forward_call(*input, **kwargs) File "/home/data/aidd/DeepPurpose/DeepPurpose/DTI.py", line 52, in forward v_f = torch.cat((v_D, v_P), 1) RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 512 but got size 2 for tensor number 1 in the list.

kexinhuang12345 commented 1 year ago

Could you send code to reproduce error?

yrq3027 commented 1 year ago

Thank you for reply. I definited my own dataset, also ,the same error happened when I run the benchmark dataset. import os import pandas as pd import numpy as np os.environ['CUDA_VISIBLE_DEVICES'] = "1"

import DeepPurpose.DTI as models from DeepPurpose.utils import from DeepPurpose.dataset import from DeepPurpose import utils, DTI, dataset

CODING_TYPE = ["0"]

def dataLoader():

X_drugs, X_targets, y = dataset.load_Pharos(binary=True)
return X_drugs, X_targets, y

def createModel(coding):

X_drugs, X_targets, y = dataLoader()

if coding == "0":

    drug_encoding = 'DGL_GIN_AttrMasking'
    target_encoding = 'transformer'
    train, val, test = utils.data_process(X_drugs, X_targets, y, 
                            drug_encoding, target_encoding, 
                            split_method='random',frac=[0.7,0.1,0.2],
                            random_seed = 1)
    config = utils.generate_config(drug_encoding = drug_encoding, 
                     target_encoding = target_encoding, 
                     cls_hidden_dims = [1024,1024,512], 
                     train_epoch = 150, 
                     LR = 0.001, 
                     batch_size = 512,
                     hidden_dim_drug = 128,
                     mpnn_hidden_size = 128,
                     mpnn_depth = 3, 
                     cnn_target_filters = [32,64,96],
                     cnn_target_kernels = [4,8,12]
                    )
    model = models.model_initialize(**config)

return train, val, test, drug_encoding, target_encoding, model

def trainModel(coding):

train, val, test, drug_encoding, target_encoding, model = createModel(coding)
model.train(train, val, test)
model.save_model('./Pharos_model/'+drug_encoding+"-"+target_encoding+"_clf")

if name == "main":

for coding in CODING_TYPE:

    trainModel(coding)
kexinhuang12345 commented 1 year ago

Are you using multiple GPUs? could you try a single GPU? also, does other combination work?