def test_reshape_layer(self): block_expand = layer.block_expand( input=conv, num_channels=4, stride_x=1, block_x=1) expand = layer.expand( input=weight, expand_as=pixel, expand_level=layer.ExpandLevel.FROM_TIMESTEP) repeat = layer.repeat(input=pixel, num_repeats=4) reshape = layer.seq_reshape(input=pixel, reshape_size=4) rotate = layer.rotate(input=pixel, height=16, width=49) print layer.parse_network(block_expand, expand, repeat, reshape, rotate)
def test_reshape_layer(self): block_expand = layer.block_expand( input=conv, num_channels=4, stride_x=1, block_x=1) expand = layer.expand( input=weight, expand_as=pixel, expand_level=layer.ExpandLevel.FROM_NO_SEQUENCE) repeat = layer.repeat(input=pixel, num_repeats=4) reshape = layer.seq_reshape(input=pixel, reshape_size=4) rotate = layer.rotate(input=pixel, height=16, width=49) print layer.parse_network( [block_expand, expand, repeat, reshape, rotate])
def __build_nn__(self): ''' Build the network topology. ''' # Get the image features with CNN. conv_features = self.conv_groups(self.image, conf.filter_num, conf.with_bn) # Expand the output of CNN into a sequence of feature vectors. sliced_feature = layer.block_expand( input=conv_features, num_channels=conf.num_channels, stride_x=conf.stride_x, stride_y=conf.stride_y, block_x=conf.block_x, block_y=conf.block_y) # Use RNN to capture sequence information forwards and backwards. gru_forward = simple_gru( input=sliced_feature, size=conf.hidden_size, act=Relu()) gru_backward = simple_gru( input=sliced_feature, size=conf.hidden_size, act=Relu(), reverse=True) # Map the output of RNN to character distribution. self.output = layer.fc(input=[gru_forward, gru_backward], size=self.num_classes + 1, act=Linear()) self.log_probs = paddle.layer.mixed( input=paddle.layer.identity_projection(input=self.output), act=paddle.activation.Softmax()) # Use warp CTC to calculate cost for a CTC task. if not self.is_infer: self.cost = layer.warp_ctc( input=self.output, label=self.label, size=self.num_classes + 1, norm_by_times=conf.norm_by_times, blank=self.num_classes) self.eval = evaluator.ctc_error(input=self.output, label=self.label)
def __build_nn__(self): ''' 建立网络拓扑 ''' # 通过CNN获取图像特征 conv_features = self.conv_groups(self.image, conf.filter_num, conf.with_bn) # 将CNN的输出展开成一系列特征向量。 sliced_feature = layer.block_expand( input=conv_features, num_channels=conf.num_channels, stride_x=conf.stride_x, stride_y=conf.stride_y, block_x=conf.block_x, block_y=conf.block_y) # 使用RNN向前和向后捕获序列信息。 gru_forward = simple_gru( input=sliced_feature, size=conf.hidden_size, act=Relu()) gru_backward = simple_gru( input=sliced_feature, size=conf.hidden_size, act=Relu(), reverse=True) # 将RNN的输出映射到字符分布。 self.output = layer.fc(input=[gru_forward, gru_backward], size=self.num_classes + 1, act=Linear()) self.log_probs = paddle.layer.mixed( input=paddle.layer.identity_projection(input=self.output), act=paddle.activation.Softmax()) # 使用扭曲CTC来计算CTC任务的成本。 if not self.is_infer: self.cost = layer.warp_ctc( input=self.output, label=self.label, size=self.num_classes + 1, norm_by_times=conf.norm_by_times, blank=self.num_classes) self.eval = evaluator.ctc_error(input=self.output, label=self.label)