def get_named_ground_truth_data(name): """Returns ground truth data set based on name. Args: name: String with the name of the dataset. Raises: ValueError: if an invalid data set name is provided. """ if name == "dsprites_full": return dsprites.DSprites([1, 2, 3, 4, 5]) elif name == "dsprites_noshape": return dsprites.DSprites([2, 3, 4, 5]) elif name == "color_dsprites": return dsprites.ColorDSprites([1, 2, 3, 4, 5]) elif name == "noisy_dsprites": return dsprites.NoisyDSprites([1, 2, 3, 4, 5]) elif name == "scream_dsprites": return dsprites.ScreamDSprites([1, 2, 3, 4, 5]) elif name == "smallnorb": return norb.SmallNORB() elif name == "cars3d": return cars3d.Cars3D() elif name == "mpi3d_toy": return mpi3d.MPI3D(mode="mpi3d_toy") elif name == "mpi3d_realistic": return mpi3d.MPI3D(mode="mpi3d_realistic") elif name == "mpi3d_real": return mpi3d.MPI3D(mode="mpi3d_real") elif name == "shapes3d": return shapes3d.Shapes3D() elif name == "dummy_data": return dummy_data.DummyData() elif name == "modelnet": return DisLibGroundTruthData(**MODELNET_PARAMS) elif name == "arrow": return DisLibGroundTruthData(**ARROW_PARAMS) elif name == "pixel4": return DisLibGroundTruthData(**WRAPPED_PIXEL4_PARAMS) elif name == "pixel8": return DisLibGroundTruthData(**WRAPPED_PIXEL8_PARAMS) else: raise ValueError("Invalid data set name.")
def get_named_ground_truth_data(name): """Returns ground truth data set based on name. Args: name: String with the name of the dataset. Raises: ValueError: if an invalid data set name is provided. """ if name == "threeDotsCache": # a large random sample from ThreeDots return threeDots.ThreeDotsTrainingCache() elif name == "threeDots": return threeDots.ThreeDots() elif name == "dsprites_full": return dsprites.DSprites([1, 2, 3, 4, 5]) elif name == "dsprites_noshape": return dsprites.DSprites([2, 3, 4, 5]) elif name == "color_dsprites": return dsprites.ColorDSprites([1, 2, 3, 4, 5]) elif name == "noisy_dsprites": return dsprites.NoisyDSprites([1, 2, 3, 4, 5]) elif name == "scream_dsprites": return dsprites.ScreamDSprites([1, 2, 3, 4, 5]) elif name == "smallnorb": return norb.SmallNORB() elif name == "cars3d": return cars3d.Cars3D() elif name == "mpi3d_toy": return mpi3d.MPI3D(mode="mpi3d_toy") elif name == "mpi3d_realistic": return mpi3d.MPI3D(mode="mpi3d_realistic") elif name == "mpi3d_real": return mpi3d.MPI3D(mode="mpi3d_real") elif name == "mpi3d_multi_real": return mpi3d_multi.MPI3DMulti(mode="mpi3d_real") elif name == "shapes3d": return shapes3d.Shapes3D() elif name == "dummy_data": return dummy_data.DummyData() else: raise ValueError("Invalid data set name.")
def get_named_ground_truth_data(name): """Returns ground truth data set based on name. Args: name: String with the name of the dataset. Raises: ValueError: if an invalid data set name is provided. """ if name == "dsprites_full": return dsprites.DSprites([1, 2, 3, 4, 5]) elif name == "dsprites_noshape": return dsprites.DSprites([2, 3, 4, 5]) elif name == "color_dsprites": return dsprites.ColorDSprites([1, 2, 3, 4, 5]) elif name == "noisy_dsprites": return dsprites.NoisyDSprites([1, 2, 3, 4, 5]) elif name == "scream_dsprites": return dsprites.ScreamDSprites([1, 2, 3, 4, 5]) elif name == "smallnorb": return norb.SmallNORB() elif name == "cars3d": return cars3d.Cars3D() elif name == "mpi3d_toy": return mpi3d.MPI3D(mode="mpi3d_toy") elif name == "mpi3d_realistic": return mpi3d.MPI3D(mode="mpi3d_realistic") elif name == "mpi3d_real": return mpi3d.MPI3D(mode="mpi3d_real") elif name == "3dshapes": return shapes3d.Shapes3D() elif name == "3dshapes_holdout" or name == "3dshapes_pca_holdout_s5000": return shapes3d_partial.Shapes3DPartial(name) elif name == "3dshapes_model_all": return shapes3d_partial.Shapes3DPartial(name), None elif name[:8] == "3dshapes": return shapes3d_partial.Shapes3DPartial( name + '_train'), shapes3d_partial.Shapes3DPartial(name + '_valid') elif name == "dummy_data": return dummy_data.DummyData() else: raise ValueError("Invalid data set name.")
def get_dlib_data(task): ut.log("Loading {}".format(task)) if task == "dsprites": # 5 factors return dsprites.DSprites(list(range(1, 6))) elif task == "shapes3d": # 6 factors return shapes3d.Shapes3D() elif task == "norb": # 4 factors + 1 nuisance (which we'll handle via n_dim=2) return norb.SmallNORB() elif task == "cars3d": # 3 factors return cars3d.Cars3D() elif task == "mpi3d": # 7 factors return mpi3d.MPI3D() elif task == "scream": # 5 factors + 2 nuisance (handled as n_dim=2) return dsprites.ScreamDSprites(list(range(1, 6)))
from disentanglement_lib.data.ground_truth import mpi3d from disentanglement_lib.evaluation.metrics import dci, factor_vae, sap_score, mig, irs, utils def representation_fn(x): main_net.eval() with torch.no_grad(): images = preprocess(x).cuda() transformed_codes = main_net(images, 1, 1, encoding_only=True) comp_loss, z_factors = compress_net(transformed_codes) repr_code = torch.cat([z for k, z in z_factors.items()], 1).cpu().numpy() return repr_code ground_truth_data = mpi3d.MPI3D() print('representation_fn') scores = factor_vae.compute_factor_vae(ground_truth_data, representation_fn, np.random.RandomState(0), 64, 10000, 5000, 10000) print(' factor_vae: %.6f' % scores['eval_accuracy']) scores = dci.compute_dci(ground_truth_data, representation_fn, np.random.RandomState(0), 10000, 5000) print(' dci: %.6f' % scores['disentanglement']) scores = sap_score.compute_sap(ground_truth_data, representation_fn, np.random.RandomState(0), 10000,