# Path: disentanglement_lib/data/ground_truth/ground_truth_data.py
# class GroundTruthData(object):
#   def num_factors(self):
#   def factors_num_values(self):
#   def observation_shape(self):
#   def sample_factors(self, num, random_state):
#   def sample_observations_from_factors(self, factors, random_state):
#   def sample(self, num, random_state):
#   def sample_observations(self, num, random_state):
# 
# Path: disentanglement_lib/data/ground_truth/util.py
# def tf_data_set_from_ground_truth_data(ground_truth_data, random_seed):
#   def generator():
#   def __init__(self, factor_sizes, latent_factor_indices):
#   def num_latent_factors(self):
#   def sample_latent_factors(self, num, random_state):
#   def sample_all_factors(self, latent_factors, random_state):
#   def _sample_factor(self, i, num, random_state):
#   def __init__(self, factor_sizes, features):
#   def features_to_index(self, features):
#   def _features_to_state_space_index(self, features):
# class SplitDiscreteStateSpace(object):
# class StateSpaceAtomIndex(object):


import os
import numpy as np
import tensorflow.compat.v1 as tf
from disentanglement_lib.data.ground_truth import ground_truth_data
from disentanglement_lib.data.ground_truth import util
from six.moves import range



class Shapes3D(ground_truth_data.GroundTruthData):
  """Shapes3D dataset.

  The data set was originally introduced in "Disentangling by Factorising".

  The ground-truth factors of variation are:
  0 - floor color (10 different values)
  1 - wall color (10 different values)
  2 - object color (10 different values)
  3 - object size (8 different values)
  4 - object type (4 different values)
  5 - azimuth (15 different values)
  """

  def __init__(self):
    with tf.gfile.GFile(SHAPES3D_PATH, "rb") as f:
      # Data was saved originally using python2, so we need to set the encoding.
      data = np.load(f, encoding="latin1")
    images = data["images"]
    labels = data["labels"]
    n_samples = np.prod(images.shape[0:6])
    self.images = (
        images.reshape([n_samples, 64, 64, 3]).astype(np.float32) / 255.)
    features = labels.reshape([n_samples, 6])
    self.factor_sizes = [10, 10, 10, 8, 4, 15]
    self.latent_factor_indices = list(range(6))
    self.num_total_factors = features.shape[1]

# Path: disentanglement_lib/data/ground_truth/ground_truth_data.py
# class GroundTruthData(object):
#   def num_factors(self):
#   def factors_num_values(self):
#   def observation_shape(self):
#   def sample_factors(self, num, random_state):
#   def sample_observations_from_factors(self, factors, random_state):
#   def sample(self, num, random_state):
#   def sample_observations(self, num, random_state):
# 
# Path: disentanglement_lib/data/ground_truth/util.py
# def tf_data_set_from_ground_truth_data(ground_truth_data, random_seed):
#   def generator():
#   def __init__(self, factor_sizes, latent_factor_indices):
#   def num_latent_factors(self):
#   def sample_latent_factors(self, num, random_state):
#   def sample_all_factors(self, latent_factors, random_state):
#   def _sample_factor(self, i, num, random_state):
#   def __init__(self, factor_sizes, features):
#   def features_to_index(self, features):
#   def _features_to_state_space_index(self, features):
# class SplitDiscreteStateSpace(object):
# class StateSpaceAtomIndex(object):


# Path: disentanglement_lib/data/ground_truth/shapes3d.py
import os
import numpy as np
import tensorflow.compat.v1 as tf
from disentanglement_lib.data.ground_truth import ground_truth_data
from disentanglement_lib.data.ground_truth import util
from six.moves import range




class Shapes3D(ground_truth_data.GroundTruthData):
  """Shapes3D dataset.

  The data set was originally introduced in "Disentangling by Factorising".

  The ground-truth factors of variation are:
  0 - floor color (10 different values)
  1 - wall color (10 different values)
  2 - object color (10 different values)
  3 - object size (8 different values)
  4 - object type (4 different values)
  5 - azimuth (15 different values)
  """

  def __init__(self):
    with tf.gfile.GFile(SHAPES3D_PATH, "rb") as f:
      # Data was saved originally using python2, so we need to set the encoding.
      data = np.load(f, encoding="latin1")
    images = data["images"]
    labels = data["labels"]
    n_samples = np.prod(images.shape[0:6])
    self.images = (
        images.reshape([n_samples, 64, 64, 3]).astype(np.float32) / 255.)
    features = labels.reshape([n_samples, 6])
    self.factor_sizes = [10, 10, 10, 8, 4, 15]
    self.latent_factor_indices = list(range(6))
    self.num_total_factors = features.shape[1]

    self.state_space = util.SplitDiscreteStateSpace(self.factor_sizes,