def test_scorer_generator_case(self):

        scorer = ScorerSemanticSegmentation(self.dummy_data_generator())
        scores = scorer.calculate_scores()

        for score_name, score_array in scores.items():
            self.assertTrue(isinstance(score_array, np.ndarray))
            self.assertEqual(score_array.shape, (self.N, ))
Exemplo n.º 2
0
    def test_agent_with_generator(self):
        self.api_workflow_client.embedding_id = "embedding_id_xyz"
        width = 32
        height = 32
        no_classes = 13

        agent = ActiveLearningAgent(
            self.api_workflow_client,
            preselected_tag_name="preselected_tag_name_xyz")
        method = SamplingMethod.CORAL
        n_samples = len(agent.labeled_set) + 2

        n_predictions = len(agent.query_set)
        predictions = np.random.rand(n_predictions, no_classes, width,
                                     height).astype(np.float32)
        predictions_normalized = predictions / np.sum(predictions,
                                                      axis=1)[:, np.newaxis]
        predictions_generator = (predictions_normalized[i]
                                 for i in range(n_predictions))
        al_scorer = ScorerSemanticSegmentation(predictions_generator)

        sampler_config = SamplerConfig(n_samples=n_samples, method=method)
        agent.query(sampler_config=sampler_config, al_scorer=al_scorer)

        # make sure we throw an error if generator is already consumed
        with self.assertRaises(ValueError):
            agent.upload_scores(al_scorer)
    def test_wrong_input_shape(self):

        scorer = ScorerSemanticSegmentation(self.dummy_data_valerr)

        with self.assertRaises(ValueError):
            scorer.calculate_scores()