def build_model(self, height, width, num_channels):
        self.config.height = height
        self.config.width = width
        self.config.num_channels = num_channels

        self.graph = tf.Graph()
        with self.graph.as_default():
            self.model_graph = Factory(self.config)
            print(self.model_graph)

            self.trainable_count = np.sum([
                np.prod(v.get_shape().as_list())
                for v in tf.trainable_variables()
            ])
            print('\nNumber of trainable paramters', self.trainable_count)
            self.test_graph()
        ''' 
         -------------------------------------------------------------------------------
                        GOOGLE COLAB 
        ------------------------------------------------------------------------------------- 
        '''
        if self.config.colab:
            self.push_colab()
            self.config.push_colab = self.push_colab

        self.config.isBuilt = True
        file_utils.save_args(self.config.dict(), self.config.model_name,
                             self.config.config_dir,
                             ['latent_mean', 'latent_std', 'push_colab'])
Exemplo n.º 2
0
 def save_model(self):
     self.save(self.session, self.saver,
               self.model_graph.global_step_tensor.eval(self.session))
     self.compute_distribution(self.data_train.x)
     file_utils.save_args(self.config.dict(), self.config.model_name,
                          self.config.config_dir,
                          ['latent_mean', 'latent_std'])
     gc.collect()
    def __init__(self, **kwrds):
        self.config = copy.deepcopy(config())
        for key in kwrds.keys():
            assert key in self.config.keys(), '{} is not a keyword, \n acceptable keywords: {}'. \
                format(key, self.config.keys())

            self.config[key] = kwrds[key]

        self.latent_data = None
        self.experiments_root_dir = 'experiments'
        file_utils.create_dirs([self.experiments_root_dir])
        self.config.model_name = get_model_name(self.config.graph_type, self.config)

        if self.config.colab:
            self.google2colab()

        self.config.checkpoint_dir = os.path.join(self.experiments_root_dir + '/' + self.config.checkpoint_dir + '/',
                                                  self.config.model_name)
        self.config.config_dir = os.path.join(self.experiments_root_dir + '/' + self.config.config_dir + '/',
                                              self.config.model_name)
        self.config.log_dir = os.path.join(self.experiments_root_dir + '/' + self.config.log_dir + '/',
                                           self.config.model_name)

        log_dir_subfolders = ['reconst', 'latent2d', 'latent3d', 'samples', 'total_random', 'pretoss_random', 'interpolate']
        config_dir_subfolders = ['extra']


        file_utils.create_dirs([self.config.checkpoint_dir, self.config.config_dir, self.config.log_dir])
        file_utils.create_dirs([self.config.log_dir + '/' + dir_ + '/' for dir_ in log_dir_subfolders])
        file_utils.create_dirs([self.config.config_dir + '/' + dir_ + '/' for dir_ in config_dir_subfolders])

        load_config = {}
        try:
            load_config = file_utils.load_args(self.config.model_name, self.config.config_dir, ['latent_mean', 'latent_std', 'samples', 'y_uniqs'])
            self.config.update(load_config)
            print('Loading previous configuration ...')
        except:
            print('Unable to load previous configuration ...')
            file_utils.save_args(self.config.dict(), self.config.model_name, self.config.config_dir,
                                 ['latent_mean', 'latent_std', 'samples', 'y_uniqs'])


        if hasattr(self.config, 'height'):
            try:
                self.config.restore = True
                self.build_model(self.config.height, self.config.width, self.config.num_channels)
            except:
                self.config.isBuilt = False
        else:
            self.config.isBuilt = False