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

Method add_conv

src/gopt/test/network.cpp:6–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4using namespace mgb;
5
6SymbolVar Network::add_conv(
7 SymbolVar f, size_t output_channels, KernSize kern_size, DType out_dtype,
8 bool has_relu, Stride stride, Padding padding) {
9 static int weight_idx = 0;
10 static int bias_idx = 0;
11
12 size_t input_channels = f.node()->shape()[1];
13 auto weight = add_cvar(
14 ssprintf("w%d", weight_idx).c_str(),
15 {output_channels, input_channels, kern_size[0], kern_size[1]});
16 auto bias = add_cvar(ssprintf("b%d", bias_idx).c_str(), {1, output_channels, 1, 1});
17 if (out_dtype.category() == DTypeCategory::QUANTIZED) {
18 weight = add_type_cvt(weight, out_dtype);
19 bias = add_type_cvt(bias, dtype::QuantizedS32{1.f});
20 }
21 opr::ConvBias::Param param;
22 param.stride_h = stride[0], param.stride_w = stride[1];
23 param.pad_h = padding[0], param.pad_w = padding[1];
24 if (has_relu) {
25 param.nonlineMode = opr::ConvBias::Param::NonlineMode::RELU;
26 } else {
27 param.nonlineMode = opr::ConvBias::Param::NonlineMode::IDENTITY;
28 }
29
30 SymbolVar conv;
31 if (out_dtype.category() == DTypeCategory::QUANTIZED) {
32 conv = opr::ConvBias::make(
33 f, weight, bias, param, {}, OperatorNodeConfig{out_dtype});
34 } else {
35 conv = opr::ConvBias::make(f, weight, bias, param, {});
36 }
37 weight_idx++;
38 bias_idx++;
39 return conv;
40}
41
42SymbolVar Network::add_group_conv(
43 SymbolVar f, size_t output_channels, size_t groups, KernSize kern_size,

Callers 12

create_graphMethod · 0.80
create_blockMethod · 0.80
make_resnet18Method · 0.80
make_pyramidsFunction · 0.80
fusion_pyramids_featureFunction · 0.80
bottleneckMethod · 0.80
make_mobilenet_v2Method · 0.80
TESTFunction · 0.80

Calls 4

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

Tested by

no test coverage detected