示例#1
0
    def create_globalaveragepooling1d(self, klayer, kclayer):
        input_shape = klayer.get_input_shape_at(0)  # batch, step, dim
        b_kw = 1
        b_kh = int(input_shape[1])

        seq = BLayer.Sequential()
        seq.add(
            BLayer.View([int(input_shape[1]), 1,
                         int(input_shape[2])],
                        num_input_dims=2))
        blayer = BLayer.SpatialAveragePooling(kw=b_kw,
                                              kh=b_kh,
                                              dw=0,
                                              dh=0,
                                              pad_w=0,
                                              pad_h=0,
                                              global_pooling=False,
                                              ceil_mode=False,
                                              count_include_pad=False,
                                              divide=True,
                                              format="NHWC",
                                              bigdl_type="float")
        seq.add(blayer)
        seq.add(BLayer.Squeeze(
            2, num_input_dims=2))  # the index start from one but without batch
        seq.add(BLayer.Squeeze(1, num_input_dims=1))

        return seq
示例#2
0
    def create_globalmaxpooling2d(self, klayer, kclayer):
        bigdl_order = self.get_bdim_order(kclayer)
        input_shape = klayer.get_input_shape_at(0)
        if bigdl_order == "NCHW":
            b_kw = int(input_shape[3])
            b_kh = int(input_shape[2])
        else:
            b_kw = int(input_shape[2])
            b_kh = int(input_shape[1])

        seq = BLayer.Sequential()
        blayer = BLayer.SpatialMaxPooling(kw=b_kw,
                                          kh=b_kh,
                                          dw=b_kw,
                                          dh=b_kh,
                                          pad_w=0,
                                          pad_h=0,
                                          to_ceil=False,
                                          format=bigdl_order,
                                          bigdl_type="float")
        seq.add(blayer)
        if bigdl_order == "NCHW":
            seq.add(BLayer.Squeeze(3, num_input_dims=3))
            seq.add(BLayer.Squeeze(2, num_input_dims=2))
        else:
            seq.add(BLayer.Squeeze(2, num_input_dims=3))
            seq.add(BLayer.Squeeze(1, num_input_dims=2))
        return seq
示例#3
0
    def create_globalaveragepooling2d(self, klayer, kclayer):
        bigdl_order = self.get_bdim_order(kclayer)
        input_shape = klayer.get_input_shape_at(0)
        if bigdl_order == "NCHW":
            b_kw = int(input_shape[3])
            b_kh = int(input_shape[2])
        else:
            b_kw = int(input_shape[2])
            b_kh = int(input_shape[1])

        seq = BLayer.Sequential()
        blayer = BLayer.SpatialAveragePooling(kw=b_kw,
                                              kh=b_kh,
                                              dw=b_kw,
                                              dh=b_kh,
                                              pad_w=0,
                                              pad_h=0,
                                              global_pooling=False,
                                              ceil_mode=False,
                                              count_include_pad=False,
                                              divide=True,
                                              format=bigdl_order,
                                              bigdl_type="float")
        seq.add(blayer)
        if bigdl_order == "NCHW":
            seq.add(BLayer.Squeeze(3, num_input_dims=3))
            seq.add(BLayer.Squeeze(2, num_input_dims=2))
        else:
            seq.add(BLayer.Squeeze(2, num_input_dims=3))
            seq.add(BLayer.Squeeze(1, num_input_dims=2))
        return seq
示例#4
0
    def create_convolution1d(self, klayer, kclayer):
        config = kclayer["config"]
        input_shape = klayer.get_input_shape_at(0)
        # batch, steps, dim, batch is None here, so you cannot use it directly.
        stack_size = int(input_shape[2])

        bpadW, bpadH = self.to_bigdl_2d_padding(klayer.border_mode)
        seq = BLayer.Sequential()
        seq.add(
            BLayer.Reshape([int(input_shape[1]), 1,
                            int(input_shape[2])], True))
        blayer = BLayer.SpatialConvolution(
            n_input_plane=stack_size,
            n_output_plane=klayer.nb_filter,
            kernel_w=1,
            kernel_h=klayer.filter_length,
            stride_w=1,
            stride_h=klayer.subsample_length,
            pad_w=bpadW,
            pad_h=bpadH,
            n_group=1,
            propagate_back=True,
            wRegularizer=self.to_bigdl_reg(config["W_regularizer"]),
            bRegularizer=self.to_bigdl_reg(config["b_regularizer"]),
            init_weight=None,
            init_bias=None,
            init_grad_weight=None,
            init_grad_bias=None,
            with_bias=config["bias"],
            data_format="NHWC",
            bigdl_type="float")
        seq.add(blayer)
        seq.add(BLayer.Squeeze(3))
        return self.combo_parameter_layer(seq, config)
示例#5
0
    def create_globalmaxpooling1d(self, klayer, kclayer):
        input_shape = klayer.get_input_shape_at(0)  # batch, step, dim
        b_kw = 1
        b_kh = int(input_shape[1])

        seq = BLayer.Sequential()
        seq.add(
            BLayer.View([int(input_shape[1]), 1,
                         int(input_shape[2])],
                        num_input_dims=2))
        blayer = BLayer.SpatialMaxPooling(kw=b_kw,
                                          kh=b_kh,
                                          dw=0,
                                          dh=0,
                                          pad_w=0,
                                          pad_h=0,
                                          to_ceil=False,
                                          format="NHWC",
                                          bigdl_type="float")
        seq.add(blayer)
        seq.add(BLayer.Squeeze(2, num_input_dims=2))
        seq.add(BLayer.Squeeze(1, num_input_dims=1))
        return seq