当前位置: 首页>>代码示例>>Python>>正文


Python utils.Progbar方法代码示例

本文整理汇总了Python中tensorflow.keras.utils.Progbar方法的典型用法代码示例。如果您正苦于以下问题:Python utils.Progbar方法的具体用法?Python utils.Progbar怎么用?Python utils.Progbar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow.keras.utils的用法示例。


在下文中一共展示了utils.Progbar方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: fit

# 需要导入模块: from tensorflow.keras import utils [as 别名]
# 或者: from tensorflow.keras.utils import Progbar [as 别名]
def fit(self, x, y, epochs=1, steps_per_epoch=1):
        """Trains the model for a given number of epochs
    (iterations on a dataset).

    Arguments:
      x: Private tensor of training data
      y: Private tensor of target (label) data
      epochs: Integer. Number of epochs to train the model.
      steps_per_epoch: Integer. Total number of steps (batches of samples)
        before declaring one epoch finished and starting the next epoch.
    """
        assert isinstance(x, PondPrivateTensor), type(x)
        assert isinstance(y, PondPrivateTensor), type(y)

        # Initialize variables before starting to train
        sess = KE.get_session()
        sess.run(tf.global_variables_initializer())

        for e in range(epochs):
            print("Epoch {}/{}".format(e + 1, epochs))
            batch_size = x.shape.as_list()[0]
            progbar = utils.Progbar(batch_size * steps_per_epoch)
            for _ in range(steps_per_epoch):
                self.fit_batch(x, y)
                progbar.add(batch_size, values=[("loss", self._current_loss)]) 
开发者ID:tf-encrypted,项目名称:tf-encrypted,代码行数:27,代码来源:sequential.py

示例2: run_train

# 需要导入模块: from tensorflow.keras import utils [as 别名]
# 或者: from tensorflow.keras.utils import Progbar [as 别名]
def run_train(self, x, y, epoches, batch_size, val_data):
        train_gen = BatchGenerator(x, y, batch_size=batch_size)
        steps_per_epoch = np.ceil(train_gen.length / batch_size).astype(int)
        
        self.sess.run(tf.global_variables_initializer())
        
        for i in range (1, epoches+1):
            print('Epoch {} / {}'.format(i, epoches))
            pbar = utils.Progbar(steps_per_epoch)
            
            for step, batch in enumerate(train_gen.next(), 1):
                users = batch[0][:, 0]
                items = batch[0][:, 1]
                ratings = batch[1]
                
                self.sess.run(self.optimizer,
                              feed_dict={
                                      self.users: users,
                                      self.items: items,
                                      self.ratings: ratings})
                pred = self.predict(batch[0])
                
                update_values = [
                        ('rmse', rmse(ratings, pred)),
                        ('mae', mae(ratings, pred))]
                
                
            if(val_data is not None and step == steps_per_epoch):
                valid_x, valid_y = val_data
                valid_pred = self.predict(valid_x)
                update_values += [
                        ('val_rmse', rmse(valid_y, valid_pred)),
                        ('val_mae', mae(valid_y, valid_pred))]
                pbar.update(step, value=update_values, force=(step==steps_per_epoch)) 
开发者ID:wyl6,项目名称:Recommender-Systems-Samples,代码行数:36,代码来源:svd.py

示例3: run_train

# 需要导入模块: from tensorflow.keras import utils [as 别名]
# 或者: from tensorflow.keras.utils import Progbar [as 别名]
def run_train(self, x, y, epoches, batch_size, val_data):
        train_gen = BatchGenerator(x, y, batch_size=batch_size)
        steps_per_epoch = np.ceil(train_gen.length / batch_size).astype(int)
        
        self.sess.run(tf.global_variables_initializer())
        
        for i in range (1, epoches+1):
            print('Epoch {} / {}'.format(i, epoches))
            pbar = utils.Progbar(steps_per_epoch)
            print('stpes_per_epoch', steps_per_epoch)
            for step, batch in enumerate(train_gen.next(), start=1):
                users = batch[0][:, 0]
                items = batch[0][:, 1]
                ratings = batch[1]
                
                self.sess.run(self.optimizer,
                              feed_dict={
                                      self.users: users,
                                      self.items: items,
                                      self.ratings: ratings})
                pred = self.predict(batch[0])
                
                update_values = [
                        ('rmse', rmse(ratings, pred)),
                        ('mae', mae(ratings, pred))]
                
                if(val_data is not None and step == steps_per_epoch):
                    valid_x, valid_y = val_data
                    valid_pred = self.predict(valid_x)
                    update_values += [
                            ('val_rmse', rmse(valid_y, valid_pred)),
                            ('val_mae', mae(valid_y, valid_pred))]
                    
                pbar.update(step, values=update_values) 
开发者ID:wyl6,项目名称:Recommender-Systems-Samples,代码行数:36,代码来源:svd.py

示例4: _run_train

# 需要导入模块: from tensorflow.keras import utils [as 别名]
# 或者: from tensorflow.keras.utils import Progbar [as 别名]
def _run_train(self, x, y, epochs, batch_size, validation_data):
        train_gen = BatchGenerator(x, y, batch_size)
        steps_per_epoch = np.ceil(train_gen.length / batch_size).astype(int)

        self._sess.run(tf.global_variables_initializer())

        for e in range(1, epochs + 1):
            print('Epoch {}/{}'.format(e, epochs))

            pbar = utils.Progbar(steps_per_epoch)

            for step, batch in enumerate(train_gen.next(), 1):
                users = batch[0][:, 0]
                items = batch[0][:, 1]
                ratings = batch[1]

                self._sess.run(
                    self._optimizer,
                    feed_dict={
                        self._users: users,
                        self._items: items,
                        self._ratings: ratings
                    })

                pred = self.predict(batch[0])

                update_values = [
                    ('rmse', rmse(ratings, pred)),
                    ('mae', mae(ratings, pred))
                ]

                if validation_data is not None and step == steps_per_epoch:
                    valid_x, valid_y = validation_data
                    valid_pred = self.predict(valid_x)

                    update_values += [
                        ('val_rmse', rmse(valid_y, valid_pred)),
                        ('val_mae', mae(valid_y, valid_pred))
                    ]

                pbar.update(step, values=update_values,
                            force=(step == steps_per_epoch)) 
开发者ID:WindQAQ,项目名称:tf-recsys,代码行数:44,代码来源:svd.py


注:本文中的tensorflow.keras.utils.Progbar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。