def build_model(class_num): model = layer.Sequential() model.add(layer.Reshape([1, 28, 28])) model.add(layer.SpatialConvolution(1, 6, 5, 5)) model.add(layer.Tanh()) model.add(layer.SpatialMaxPooling(2, 2, 2, 2)) model.add(layer.Tanh()) model.add(layer.SpatialConvolution(6, 12, 5, 5)) model.add(layer.SpatialMaxPooling(2, 2, 2, 2)) model.add(layer.Reshape([12 * 4 * 4])) model.add(layer.Linear(12 * 4 * 4, 100)) model.add(layer.Tanh()) model.add(layer.Linear(100, class_num)) model.add(layer.LogSoftMax()) return model
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
def create_maxpooling2d(self, klayer, kclayer): bigdl_order = self.get_bdim_order(kclayer) bpadW, bpadH = self.to_bigdl_2d_padding(klayer.border_mode) blayer = BLayer.SpatialMaxPooling(kw=klayer.pool_size[0], kh=klayer.pool_size[1], dw=klayer.strides[0], dh=klayer.strides[1], pad_w=bpadW, pad_h=bpadH, to_ceil=False, format=bigdl_order, bigdl_type="float") return blayer
def create_maxpooling1d(self, klayer, kclayer): input_shape = klayer.get_input_shape_at(0) # batch, steps, dim bpadW, bpadH = self.to_bigdl_2d_padding(klayer.border_mode) seq = BLayer.Sequential() seq.add( BLayer.View([1, int(input_shape[1]), int(input_shape[2])], num_input_dims=3)) blayer = BLayer.SpatialMaxPooling(kw=klayer.pool_length, kh=1, dw=klayer.stride, dh=1, pad_w=bpadW, pad_h=bpadH, to_ceil=False, format="NHWC", bigdl_type="float") seq.add(blayer) return seq
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