Exemplo n.º 1
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)
Exemplo n.º 2
0
    def test_agent_only_upload_scores(self):
        self.api_workflow_client.embedding_id = "embedding_id_xyz"
        agent = ActiveLearningAgent(
            self.api_workflow_client,
            preselected_tag_name="preselected_tag_name_xyz",
        )

        n_predictions = len(agent.query_set)
        predictions = np.random.rand(n_predictions, 10).astype(np.float32)
        predictions_normalized = predictions / np.sum(predictions,
                                                      axis=1)[:, np.newaxis]
        al_scorer = ScorerClassification(predictions_normalized)

        agent.upload_scores(al_scorer)