def classify(self, x):
        features = utils.to_numpy(self.convnet(x)) # B x 128
        features /= np.sum(features**2,axis=1, keepdims=True)**.5

        r = np.tensordot(self.features[:,:,None],
                         features[:,None,:],
                         axes=([1,2], [2,1])).T # B x 50000

        ordered_preds = np.argsort(r, axis=1)
        preds = [scipy.stats.mode(self.labels[x[-self.NEAREST:]]).mode for x in ordered_preds]

        return np.array([np.eye(10)[x] for x in np.array(preds).flatten()])
Пример #2
0
 def classify(self, x):
     return utils.to_numpy(self.convnet(x))
Пример #3
0
 def fn(x):
     for layer in model.layers[:-n]:
         x = layer(x)
     h = utils.to_numpy(x)
     h = h.mean(axis)
     return h
 def detect(self, x):
     a, b, c = [
         utils.to_numpy(model(x)).argmax(1) for model in self.convnets
     ]
     has_majority = (a == b) | (a == c) | (b == c)
     return ~has_majority
 def classify(self, x):
     a, b, c = [
         utils.to_numpy(model(x)).argmax(1) for model in self.convnets
     ]
     majority_vote = ((a == b) * a) | ((a == c) * a) | ((b == c) * c)
     return np.array([np.eye(10)[i] for i in majority_vote])
Пример #6
0
 def classify(self, xs, training=False):
     xs = self.encode(xs)
     return utils.to_numpy(self.convnet(xs))
Пример #7
0
 def classify(self, x):
     predictions = [utils.to_numpy(net(x)) for net in self.class_nets]
     predictions = np.stack(predictions, axis=1)
     predictions = 5 * utils.sigmoid(
         5 * (predictions[:, :, 1] - predictions[:, :, 0]))
     return utils.softmax(predictions)
 def classify(self, x):
     preds = [
         utils.to_numpy(self.convnet(self.to_tensor(x))) for _ in range(10)
     ]
     return np.mean(preds, axis=0)
Пример #9
0
 def classify(self, x):
     x_pad = self.blur(x)
     return utils.to_numpy(self.convnet(x_pad))