本文整理匯總了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)])
示例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))
示例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)
示例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))