def initialize_set_shape(self): parname, parshape = unpack(self.parent.items()) # Shape should be (batch_size, num_channels, x, y) pool_size = totuple(self.pool_size) pool_stride = totuple(self.pool_stride) if self.ignore_border: newx = (parshape[2] - pool_size[0]) // pool_stride[0] + 1 newy = (parshape[3] - pool_size[1]) // pool_stride[1] + 1 else: if pool_stride[0] > pool_size[0]: newx = (parshape[2] - 1) // pool_stride[0] + 1 else: newx = max( 0, (parshape[2] - 1 - pool_size[0]) // pool_stride[0] + 1) + 1 if pool_stride[1] > pool_size[1]: newy = (parshape[3] - 1) // pool_stride[1] + 1 else: newy = max( 0, (parshape[3] - 1 - pool_size[1]) // pool_stride[1] + 1) + 1 outshape = (parshape[0], parshape[1], newx, newy) self.outshape = outshape
def slices(self, start, end): batches = [mat[start:end] for mat in self.data ] #len(self.data[0])=100 I imagine because of [X] label_batches = [mat[start:end] for mat in self.labels] #mask = self.create_mask(batches[0].swapaxes(0, 1)) len_batches = len(batches[0].shape) # 1 because (20,) if (len_batches <= 1): mask = self.create_mask(batches[0]) else: mask = self.create_mask(batches[0].swapaxes(0, 1)) batches = [self.zero_pad(batch) for batch in batches] #label_mask = self.create_mask(label_batches[0].swapaxes(0, 1)) len_label_batches = len(label_batches[0].shape) if (len_label_batches <= 1): label_mask = self.create_mask(label_batches[0]) else: label_mask = self.create_mask(label_batches[0].swapaxes(0, 1)) label_batches = [self.zero_pad(batch) for batch in label_batches] if self.cond: return totuple([batches[0], mask, label_batches[0], label_mask]) else: return totuple([batches[0], mask]) '''
def initialize_set_shape(self): parname, parshape = unpack(self.parent.items()) # Shape should be (batch_size, num_channels, x, y) pool_size = totuple(self.pool_size) pool_stride = totuple(self.pool_stride) if self.ignore_border: newx = (parshape[2] - pool_size[0]) // pool_stride[0] + 1 newy = (parshape[3] - pool_size[1]) // pool_stride[1] + 1 else: if pool_stride[0] > pool_size[0]: newx = (parshape[2] - 1) // pool_stride[0] + 1 else: newx = max(0, (parshape[2] - 1 - pool_size[0]) // pool_stride[0] + 1) + 1 if pool_stride[1] > pool_size[1]: newy = (parshape[3] - 1) // pool_stride[1] + 1 else: newy = max(0, (parshape[3] - 1 - pool_size[1]) // pool_stride[1] + 1) + 1 outshape = (parshape[0], parshape[1], newx, newy) self.outshape = outshape
def slices(self, start, end): batches = [mat[start:end] for mat in self.data] mask = self.create_mask(batches[0].swapaxes(0, 1)) if self.load_spk_info: batches = [self.zero_pad(batch) for batch in batches[:-1]] spk = batches[-1] return totuple(batches + [spk, mask]) else: batches = [self.zero_pad(batch) for batch in batches] return totuple(batches + [mask])
def slices(self, start, end): batches = [mat[start:end] for mat in self.data] label_batches = [mat[start:end] for mat in self.labels] mask = self.create_mask(batches[0].swapaxes(0, 1)) batches = [self.zero_pad(batch) for batch in batches] label_mask = self.create_mask(label_batches[0].swapaxes(0, 1)) label_batches = [self.zero_pad(batch) for batch in label_batches] if self.cond: return totuple([batches[0], mask, label_batches[0], label_mask]) else: return totuple([batches[0], mask])
def slices(self, start, end): batch = np.array(self.data[self.idx[start:end]], dtype=theano.config.floatX) batch -= self.X_mean batch /= self.X_std batch = np.asarray([segment_axis(x, self.inpsz, 0) for x in batch]) batch = batch.transpose(1, 0, 2) return totuple(batch)
def slices(self, start, end): batches = [mat[start:end] for mat in self.data] #mask = tolist(self.create_mask(batches[0]).swapaxes(0, 1)) #batches = [self.zero_pad(batch) for batch in batches] x, x_mask = self.create_mask_and_zero_pad(batches[0]) y, y_mask = self.create_mask_and_zero_pad(batches[1]) #return totuple(batches + mask) return totuple([x, y, y_mask])
def slices(self, start, end): batch = np.array(self.data[start:end], dtype=theano.config.floatX) batch -= self.X_mean batch /= self.X_std batch = np.asarray([segment_axis(x, self.frame_size, 0) for x in batch]) ipdb.set_trace() batch = batch.transpose(1, 0, 2) return totuple(batch)
def slices(self, start, end): batches = [mat[start:end] for mat in self.data] if self.use_spec: batches[0] = self._use_spec(batches[0]) batches[0] = self._log_magnitude(batches[0]) batches[0] = self._concatenate(batches[0]) else: batches[0] -= self.X_mean batches[0] /= self.X_std if self.use_window: batches[0] = self._use_window(batches[0]) else: batches[0] = np.asarray([segment_axis(x, self.frame_size, 0) for x in batches[0]]) mask = self.create_mask(batches[0].swapaxes(0, 1)) if self.load_spk_info: batches = [self.zero_pad(batch) for batch in batches[:-1]] spk = batches[-1] return totuple(batches + [spk, mask]) else: batches = [self.zero_pad(batch) for batch in batches] return totuple(batches + [mask])
def slices(self, start, end): batch = np.array(self.data[start:end], dtype=theano.config.floatX) if self.use_spec: batch = self._use_spec(batch) batch = self._log_magnitude(batch) batch = self._concatenate(batch) else: batch -= self.X_mean batch /= self.X_std if self.use_window: batch = self._use_window(batch) else: batch = np.asarray([segment_axis(x, self.frame_size, 0) for x in batch]) batch = batch.transpose(1, 0, 2) return totuple(batch)
def slices(self, start, end): batch = np.array(self.data[start:end], dtype=theano.config.floatX) if self.use_spec: batch = self.apply_fft(batch) batch = self.log_magnitude(batch) batch = self.concatenate(batch) else: batch -= self.X_mean batch /= self.X_std if self.use_window: batch = self.apply_window(batch) else: batch = np.asarray( [segment_axis(x, self.frame_size, 0) for x in batch]) batch = batch.transpose(1, 0, 2) return totuple(batch)
def __init__(self, parshape=[], outshape=None, filtershape=None, tied_bias=True, step_size=(1, 1), border_mode='valid', **kwargs): super(Conv2DLayer, self).__init__(**kwargs) # Shape should be (batch_size, num_channels, x, y) if (outshape is None and filtershape is None) or\ (outshape is not None and filtershape is not None): raise ValueError("Either outshape or filtershape should be given,\ but don't provide both of them.") self.outshape = outshape self.filtershape = filtershape self.tied_bias = tied_bias self.step_size = totuple(step_size) self.border_mode = border_mode for i, par in enumerate(tolist(self.parent.keys())): if len(parshape) != 0: self.parent[par] = parshape[i]
def slices(self, start, end): batches = [mat[start:end] for mat in self.data] mask = tolist(self.create_mask(batches[0].swapaxes(0, 1))) batches = [self.zero_pad(batch) for batch in batches] return totuple(batches + mask)
def slices(self, start, end): batches = [mat[start:end] for mat in self.data] mask = self.create_mask(batches[0].swapaxes(0, 1)) batches = [self.zero_pad(batch) for batch in batches] return totuple([batches[0], mask])
def slices(self, start, end): batches = [mat[start:end] for mat in self.data] return totuple(batches)