Esempio n. 1
0
 def transform(self, x):
     '''
     x is a pytorch Variable tensor, this works for combine
     x is the output of previous trainer.transform
     '''
     x = to_np(x)
     clusters = self.clf.predict(x)
     clusters = onehotize(to_var(torch.from_numpy(clusters)).view(-1, 1), self.k)
     return clusters
Esempio n. 2
0
    def forward(self, x):
        if self.mtl:  # the last one is task number
            if len(x.size()) == 1:
                t = np.zeros(self.input_size)
                t[int(to_np(x[-1])[0])] = 1
                x = to_var(torch.from_numpy(t).float()).view(1, -1)
            else:
                x = x[:, -1:]
                x = onehotize(x, self.input_size)

        o = self.i2o(x)
        return self.logsoftmax(o)