Esempio n. 1
0
    def on_epoch_end(self, data: Data):
        for _ in range(self.trials):
            img_path = self.dataset.one_shot_trial(self.N)
            input_img = (
                np.array([
                    np.expand_dims(cv2.imread(i, cv2.IMREAD_GRAYSCALE), -1) /
                    255. for i in img_path[0]
                ],
                         dtype=np.float32),
                np.array([
                    np.expand_dims(cv2.imread(i, cv2.IMREAD_GRAYSCALE), -1) /
                    255. for i in img_path[1]
                ],
                         dtype=np.float32))
            prediction_score = feed_forward(self.model,
                                            input_img,
                                            training=False).numpy()

            if np.argmax(
                    prediction_score) == 0 and prediction_score.std() > 0.01:
                self.correct += 1

            self.total += 1

        data.write_with_log(self.outputs[0], self.correct / self.total)
Esempio n. 2
0
    def on_epoch_end(self, data: Data):
        device = next(self.model.parameters()).device
        for _ in range(self.trials):
            img_path = self.dataset.one_shot_trial(self.N)
            input_img = (
                np.array([
                    np.expand_dims(cv2.imread(i, cv2.IMREAD_GRAYSCALE),
                                   -1).reshape((1, 105, 105)) / 255.
                    for i in img_path[0]
                ],
                         dtype=np.float32),
                np.array([
                    np.expand_dims(cv2.imread(i, cv2.IMREAD_GRAYSCALE),
                                   -1).reshape((1, 105, 105)) / 255.
                    for i in img_path[1]
                ],
                         dtype=np.float32))

            input_img = (to_tensor(input_img[0], "torch").to(device),
                         to_tensor(input_img[1], "torch").to(device))
            model = self.model.module if torch.cuda.device_count(
            ) > 1 else self.model
            prediction_score = feed_forward(
                model, input_img, training=False).cpu().detach().numpy()

            if np.argmax(
                    prediction_score) == 0 and prediction_score.std() > 0.01:
                self.correct += 1

            self.total += 1

        data.write_with_log(self.outputs[0], self.correct / self.total)
Esempio n. 3
0
 def on_epoch_end(self, data: Data) -> None:
     data.write_with_log(self.outputs[0], np.mean(self.dice))