Caffe2 - C++ API
A deep learning, cross platform ML framework
Public Member Functions | Protected Member Functions
caffe2::PatternNetTransform Class Reference

PatternNetTransform allows you to create transforms using a simple interface. More...

#include <pattern_net_transform.h>

Inheritance diagram for caffe2::PatternNetTransform:
caffe2::Transform

Public Member Functions

 PatternNetTransform (const NetDef &pattern_net, const NetDef &replace_net)
 
void EnableArgumentMatching ()
 
void DisableArgumentMatching ()
 
- Public Member Functions inherited from caffe2::Transform
NetDef ApplyTo (const NetDef &orig_net_def)
 Apply a Transform onto a NetDef. More...
 
std::vector< std::vector< int > > PatternMatch (const transform::Graph &graph)
 Generates all matches (stored as ordered subgraphs) and returns them. More...
 
void ReplacePattern (const std::vector< std::vector< int >> &matches, transform::Graph *graph)
 Applies the replace rule onto each of the matches found.
 

Protected Member Functions

bool PatternRule (const transform::Graph &g, const std::vector< int > &subgraph, int idx) override
 We want to the final result of subgraph to match the PatternNet in the order of ordered_ops, operator by operator. More...
 
bool ValidatorRule (const transform::Graph &g, const std::vector< int > &subgraph) override
 ValidatorRule for PatternNetTransform does the following: More...
 
bool ReplaceRule (const std::vector< int > &subgraph, transform::Graph *g_ptr) override
 ReplaceRule for PatternNet Transform does the following: More...
 
- Protected Member Functions inherited from caffe2::Transform
void SetPatternMatchType (PatternMatchType type)
 

Additional Inherited Members

- Public Types inherited from caffe2::Transform
enum  PatternMatchType { CONNECTED_SUBGRAPH, SORTED_WRT_EXECUTION_ORDER, GENERAL }
 Determines the type of subgraphs that PatternMatch will find. More...
 

Detailed Description

PatternNetTransform allows you to create transforms using a simple interface.

Simply provide a Pattern NetDef and a Replace NetDef, and this Transform will find subgraphs which fit the pattern net, and replace it with the replace net.

Definition at line 18 of file pattern_net_transform.h.

Member Function Documentation

bool caffe2::PatternNetTransform::PatternRule ( const transform::Graph g,
const std::vector< int > &  subgraph,
int  idx 
)
overrideprotectedvirtual

We want to the final result of subgraph to match the PatternNet in the order of ordered_ops, operator by operator.

[[[ ie. g.node(subgraph[i]) should match p.node(ordered_ops[i]) ]]]

PatternRule for PatternNetTransform does the following:

When trying to insert node idx into subgraph[p_idx], we need to see if the edges between index and the subgraph match the edges between p[ordered_ops[idx]] and p[ordered_ops[0]...ordered_ops[p_idx-1]].

Reimplemented from caffe2::Transform.

Definition at line 91 of file pattern_net_transform.cc.

bool caffe2::PatternNetTransform::ReplaceRule ( const std::vector< int > &  subgraph,
transform::Graph g_ptr 
)
overrideprotectedvirtual

ReplaceRule for PatternNet Transform does the following:

1) Figure out edge renamings for edges going into/out of the subgraph. That is, for each blob in the pattern graph, what is it called in the matched subgraph?

2) Remove the matched subgraph.

3) Append the replace graph's operators to the graph's operators, and use the renamings to rename the blob names.

4) Create all the children/parent relationships within the replaced graph, and stitch together the inputs and outputs into the rest of the graph, matching the removed subgraph.

Reimplemented from caffe2::Transform.

Definition at line 140 of file pattern_net_transform.cc.

bool caffe2::PatternNetTransform::ValidatorRule ( const transform::Graph g,
const std::vector< int > &  subgraph 
)
overrideprotectedvirtual

ValidatorRule for PatternNetTransform does the following:

Checks if the size of subgraph and p.size() are the same. That's it!

Reimplemented from caffe2::Transform.

Definition at line 133 of file pattern_net_transform.cc.


The documentation for this class was generated from the following files: