本文整理汇总了Python中Dataset.Dataset.index_shape_for_batches方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.index_shape_for_batches方法的具体用法?Python Dataset.index_shape_for_batches怎么用?Python Dataset.index_shape_for_batches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dataset.Dataset
的用法示例。
在下文中一共展示了Dataset.index_shape_for_batches方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: train_set_loss_vars_for_cur_batches
# 需要导入模块: from Dataset import Dataset [as 别名]
# 或者: from Dataset.Dataset import index_shape_for_batches [as 别名]
def train_set_loss_vars_for_cur_batches(self):
"""
Called via Engine.SeqTrainParallelControl.
"""
assert self.train_have_loss_for_cur_batches()
# See EngineUtil.assign_dev_data for reference.
from Dataset import Dataset
n_time, n_batch = Dataset.index_shape_for_batches(self.train_batches)
n_output_dim = self.output_layer.attrs['n_out']
output_loss = numpy.zeros((n_batch,), "float32")
output_hat_y = numpy.zeros((n_time, n_batch, n_output_dim), "float32")
offset_slice = 0
for batch in self.train_batches:
for seq in batch.seqs:
o = seq.batch_frame_offset
q = seq.batch_slice + offset_slice
l = seq.frame_length
# input-data, input-index will also be set in this loop. That is data-key "data".
for k in [self.output_target]:
if l[k] == 0: continue
loss, hat_y = self.get_loss_and_hat_y(seq.seq_idx)
assert seq.seq_start_frame[k] < hat_y.shape[0]
assert seq.seq_end_frame[k] <= hat_y.shape[0]
output_loss[q] += loss * float(l[k]) / hat_y.shape[0]
output_hat_y[o[k]:o[k] + l[k], q] = hat_y[seq.seq_start_frame[k]:seq.seq_end_frame[k]]
self.output_var_loss.set_value(output_loss)
self.output_var_hat_y.set_value(output_hat_y)