MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / add_group_conv

Method add_group_conv

src/gopt/test/network.cpp:42–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41
42SymbolVar Network::add_group_conv(
43 SymbolVar f, size_t output_channels, size_t groups, KernSize kern_size,
44 DType out_dtype, bool has_relu, Stride stride, Padding padding) {
45 static int weight_idx = 0;
46 static int bias_idx = 0;
47
48 size_t input_channels = f.node()->shape()[1];
49 auto weight = add_cvar(
50 ssprintf("w%d", weight_idx).c_str(),
51 {groups, output_channels / groups, input_channels / groups, kern_size[0],
52 kern_size[1]});
53 auto bias = add_cvar(ssprintf("b%d", bias_idx).c_str(), {1, output_channels, 1, 1});
54 if (out_dtype.category() == DTypeCategory::QUANTIZED) {
55 weight = add_type_cvt(weight, out_dtype);
56 bias = add_type_cvt(bias, dtype::QuantizedS32{1.f});
57 }
58 opr::ConvBias::Param param;
59 param.sparse = opr::ConvBias::Param::Sparse::GROUP;
60 param.stride_h = stride[0], param.stride_w = stride[1];
61 param.pad_h = padding[0], param.pad_w = padding[1];
62 if (has_relu) {
63 param.nonlineMode = opr::ConvBias::Param::NonlineMode::RELU;
64 } else {
65 param.nonlineMode = opr::ConvBias::Param::NonlineMode::IDENTITY;
66 }
67
68 weight_idx++;
69 bias_idx++;
70 SymbolVar conv;
71 if (out_dtype.category() == DTypeCategory::QUANTIZED) {
72 conv = opr::ConvBias::make(
73 f, weight, bias, param, {}, OperatorNodeConfig{out_dtype});
74 } else {
75 conv = opr::ConvBias::make(f, weight, bias, param, {});
76 }
77 weight_idx++;
78 bias_idx++;
79 return conv;
80}
81
82SymbolVar Network::add_deconv(
83 SymbolVar f, size_t ratio, size_t output_channels, DType out_dtype) {

Callers 1

bottleneckMethod · 0.80

Calls 4

categoryMethod · 0.80
makeFunction · 0.50
shapeMethod · 0.45
nodeMethod · 0.45

Tested by

no test coverage detected