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


Python Data.n_blocks方法代码示例

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


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

示例1: fill_files_buffer

# 需要导入模块: import Data [as 别名]
# 或者: from Data import n_blocks [as 别名]
 def fill_files_buffer(self):
     self.input_files = []
     self.output_files = []
     self.srcs = []
     buffer_size = 0
     index = 0
     if self.file_index >= len(self.files_order):
         raise StopIteration
     # Fill the buffer
     while buffer_size < self.max_buffer_size and self.file_index < len(self.files_order):  ##TODO add size in bytes
         # Get the output and output files
         inp = self.dataset.get_input_file(self.files_order[self.file_index])
         outp = self.dataset.get_output_values_file(self.files_order[self.file_index])
         self.input_files.append(inp)
         self.output_files.append(outp)
         buffer_size += inp.shape[0] * inp.ctypes.strides[0]
         buffer_size += outp.shape[0] * outp.ctypes.strides[0]
         inp_src = inp.ctypes.data
         outp_src = outp.ctypes.data
         times = self.dataset.get_output_times_file(self.files_order[self.file_index])
         if self.dataset.has_times:
             i = 0
             tb0 = 0.5 * (self.dataset.frame_duration + (self.n_frames - 1) * self.dataset.frame_time_shift)
             time_step = self.dataset.frame_time_shift * self.frame_shift
             for j in xrange(Data.n_blocks(inp.shape[0], self.n_frames, self.frame_shift)):
                 # Time for the center of the block of frames
                 t = tb0 + time_step * j
                 # i is the index in the label file corresponding to that time
                 while t > times[i][1] and i < len(times) - 1:
                     i += 1
                     outp_src += int(self.output_size)
                 self.srcs.append((inp_src, outp_src))
                 # Add an entry to the list of addresses
                 inp_src += int(self.frame_size * self.frame_shift)
         else:  # Has frame indexes instead of times
             i = 0
             #                for j in xrange(1+self.n_frames//2, Data.n_blocks(inp.shape[0], self.n_frames, self.frame_shift)):
             #                    while j > times[i][1] and i < len(times)-1:
             for j in xrange(Data.n_blocks(inp.shape[0], self.n_frames, self.frame_shift)):
                 # while (self.n_frames//2 + j) > times[i][1] and i < len(times)-1:
                 while (self.n_frames // 2 + j) >= times[i][1] and i < len(times) - 1:
                     i += 1
                     outp_src += int(self.output_size)
                 self.srcs.append((inp_src, outp_src))
                 # Add an entry to the list of addresses
                 inp_src += int(self.frame_size * self.frame_shift)
         # Next file and next buffer index
         index += 1
         self.file_index += 1
     if self.shuffle:
         random.shuffle(self.srcs)
     self.srcs_index = 0
开发者ID:Irene-Li,项目名称:susyML,代码行数:54,代码来源:SpeechDataset.py

示例2: next

# 需要导入模块: import Data [as 别名]
# 或者: from Data import n_blocks [as 别名]
 def next(self):
     if self.f_index >= self.dataset.get_n_files() or self.f_index > self.max_files:
         raise StopIteration
     else:
         self.f_index += 1
         f_number = self.file_order[self.f_index - 1]
         acoustics_file = self.dataset.get_input_file(f_number)
         acoustics = Data.expand_array_in_blocks(acoustics_file, self.dataset.n_frames, self.dataset.frame_shift)
         if self.dataset.has_output():
             i = 0
             output = []
             times = self.dataset.get_output_times_file(f_number)
             labels = self.dataset.get_output_values_file(f_number)
             for j in xrange(
                 Data.n_blocks(acoustics_file.shape[0], self.dataset.n_frames, self.dataset.frame_shift)
             ):
                 while (self.dataset.n_frames // 2 + j) >= times[i][1] and i < len(times) - 1:
                     i += 1
                 output.append(labels[i])
             x = [acoustics, np.array(output)]  # Get label for each t
         else:
             x = [acoustics]
         if self.return_path:
             x.append(self.dataset.get_file_path(f_number))
         return tuple(x)
开发者ID:Irene-Li,项目名称:susyML,代码行数:27,代码来源:SpeechDataset.py


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