|
from scripts.generate import MetashiftFactory, MetashiftData, get_dataset_name |
|
from omegaconf import OmegaConf |
|
import random |
|
|
|
CONFIG_PATH = "configs/generate.yaml" |
|
CANDIDATE_SUBSETS_PATH = "scripts/artifacts/csp.pkl" |
|
|
|
def test_generate(): |
|
config = OmegaConf.load(CONFIG_PATH) |
|
metashift_factory = MetashiftFactory( |
|
full_candidate_subsets_path=CANDIDATE_SUBSETS_PATH, |
|
visual_genome_images_dir=".", |
|
) |
|
info: dict[str, MetashiftData] = dict() |
|
for task_config in config.tasks: |
|
for experiment_config in task_config.experiments: |
|
data = metashift_factory.create( |
|
seed=task_config.seed, |
|
selected_classes=task_config.selected_classes, |
|
spurious_class=experiment_config.spurious_class, |
|
train_spurious_context=experiment_config.train_context, |
|
test_spurious_context=experiment_config.test_context, |
|
num_test_images_per_class=task_config.num_images_per_class_test, |
|
num_train_images_per_class=task_config.num_images_per_class_train, |
|
) |
|
dataset_name = get_dataset_name(task_config.name, experiment_config.name) |
|
assert dataset_name not in info |
|
info[dataset_name] = data |
|
|
|
random.seed(2) |
|
unique_ids = metashift_factory._get_unique_ids_from_info(info) |
|
random.seed(10000) |
|
unique_ids_2 = metashift_factory._get_unique_ids_from_info(info) |
|
|
|
assert unique_ids == unique_ids_2 |
|
|
|
|
|
|