Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions tools/pnnx/src/pass_level5/fuse_static_prelu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,44 @@ pnnx.Output output 1 0 out
}
};

class convert_prelu_to_leakyrelu : public GraphRewriterPass
{
public:
const char* match_pattern_graph() const
{
return R"PNNXIR(7767517
3 2
pnnx.Input input 0 1 input
nn.PReLU op_0 1 1 input out num_parameters=1
pnnx.Output output 1 0 out
)PNNXIR";
}

const char* type_str() const
{
return "nn.LeakyReLU";
}

const char* name_str() const
{
return "leakyrelu";
}

void write(Operator* op, const std::map<std::string, Parameter>& captured_params, const std::map<std::string, Attribute>& captured_attrs) const
{
const Attribute& weight = captured_attrs.at("op_0.weight");
op->params["negative_slope"] = weight.get_float32_data()[0];
}
};

void fuse_static_prelu(Graph& graph)
{
fuse_static_Fprelu_pass a;
convert_prelu_to_leakyrelu b;
int opindex = 0;

pnnx_graph_rewrite(graph, &a, opindex);
pnnx_graph_rewrite(graph, &b, opindex);
}

} // namespace pnnx
Loading