def test_init_from_datastore(self): # populate datastore adv_batches = image_batches.AversarialBatches( datastore_client=self.datastore_client) adv_batches.init_from_dataset_and_submissions_write_to_datastore( dataset_batches=self.dataset_batches, attack_submission_ids=self.submissions.get_all_attack_ids()) # init AversarialBatches from datastore adv_batches = image_batches.AversarialBatches( datastore_client=self.datastore_client) adv_batches.init_from_datastore() self.verify_adversarial_batches_without_images(adv_batches)
def setUp(self): self.storage_client = fake_cloud_client.FakeStorageClient() self.datastore_client = fake_cloud_client.FakeDatastoreClient() self.submissions = submissions.CompetitionSubmissions( datastore_client=self.datastore_client, storage_client=self.storage_client, round_name=ROUND_NAME) # we only need list of submissin ids in CompetitionSubmissions for this test self.submissions._defenses = { 'SUBD000': {}, 'SUBD001': {}, } self.adv_batches = image_batches.AversarialBatches( datastore_client=self.datastore_client) self.adv_batches._data = { 'ADVBATCH000': {'dataset_batch_id': 'BATCH000', 'images': {}, 'submission_id': 'SUBA000'}, 'ADVBATCH001': {'dataset_batch_id': 'BATCH000', 'images': {}, 'submission_id': 'SUBA001'}, 'ADVBATCH002': {'dataset_batch_id': 'BATCH000', 'images': {}, 'submission_id': 'SUBT000'}, }
def setUp(self): self.storage_client = fake_cloud_client.FakeStorageClient() self.datastore_client = fake_cloud_client.FakeDatastoreClient() self.submissions = submissions.CompetitionSubmissions( datastore_client=self.datastore_client, storage_client=self.storage_client, round_name=ROUND_NAME, ) # we only need list of submissin ids in CompetitionSubmissions for this test self.submissions._defenses = { "SUBD000": {}, "SUBD001": {}, } self.adv_batches = image_batches.AversarialBatches( datastore_client=self.datastore_client) self.adv_batches._data = { "ADVBATCH000": { "dataset_batch_id": "BATCH000", "images": {}, "submission_id": "SUBA000", }, "ADVBATCH001": { "dataset_batch_id": "BATCH000", "images": {}, "submission_id": "SUBA001", }, "ADVBATCH002": { "dataset_batch_id": "BATCH000", "images": {}, "submission_id": "SUBT000", }, }
def test_count_generated_adv_examples(self): adv_batches = image_batches.AversarialBatches( datastore_client=self.datastore_client ) adv_batches.init_from_dataset_and_submissions_write_to_datastore( dataset_batches=self.dataset_batches, attack_submission_ids=self.submissions.get_all_attack_ids(), ) self.assertDictEqual( {"SUBA000": 0, "SUBA001": 0, "SUBT000": 0, "SUBT001": 0}, adv_batches.count_generated_adv_examples(), )