def forward(self, x: torch.Tensor, m: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]: """ Feed forward input data. Parameters ---------- x: torch.Tensor m: torch.Tensor Returns -------- Tuple with weights of conformers, and tensor of shape Nmol*1, where Nmol is the number of molecules. The tensor is final output y, but it needs to be passed to sigmoid to obtain final class probabilities in case of classification (this classs shouldnt be called directly, call regressor/classifier subclass to obtained final y). Examples ---------- >>> import torch >>> import numpy as np >>> from torch import randn >>> from miqsar.estimators.mi_nets import InstanceNet >>> x_train = randn((3, 3, 3)) >>> instance_net = InstanceNet(ndim=(x_train[0].shape[-1], 4, 6, 4), init_cuda=False) >>> _, m = instance_net.add_padding(x_train) >>> m = torch.from_numpy(m.astype('float32')) >>> _ = instance_net.forward(x_train, m) # (assign result to a variable to supress std output) """ out = self.main_net(x) if isinstance(self, BaseClassifier): out = Sigmoid()(out) w = Softmax(dim=1)(m * out) w = w.view(w.shape[0], w.shape[-1], w.shape[1]) out = self.pooling(out, m) return w, out
def forward(self, x, m): out = self.main_net(x) if isinstance(self, BaseClassifier): out = Sigmoid()(out) w = Softmax(dim=1)(m * out) w = w.view(w.shape[0], w.shape[-1], w.shape[1]) out = self.pooling(out, m) return w, out