File size: 1,233 Bytes
13e95c8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
import torch
import os
# from model_interface import MInterface_base
from omegaconf import OmegaConf
import pytorch_lightning as pl
class MInterface(pl.LightningModule):
def __init__(self, model_name=None, loss=None, lr=None, **kargs):
super().__init__()
self.save_hyperparameters()
self.load_model()
self.cross_entropy = torch.nn.NLLLoss(reduction='none')
def forward(self, batch):
batch = self.model._get_features(batch)
results = self.model(batch)
log_probs, mask = results['log_probs'], batch['mask']
cmp = log_probs.argmax(dim=-1) == batch['S']
recovery = (cmp * mask).sum() / (mask.sum())
return recovery
def load_model(self):
params = self.hparams.configs
params.update(self.hparams)
if params.dataset == 'ligand':
from src.model.modules.invfold.src.models.odesign_ligand import ODesign_Ligand_Model
self.model = ODesign_Ligand_Model(params)
else:
from src.model.modules.invfold.src.models.odesign_model import ODesign_Model
self.model = ODesign_Model(params)
|