caffe2::Transform Class Reference

The Transform Base Object. More...

`#include <transform.h>`

Inheritance diagram for caffe2::Transform:

## Public Types | |

enum | PatternMatchType { CONNECTED_SUBGRAPH,
SORTED_WRT_EXECUTION_ORDER,
GENERAL
} |

Determines the type of subgraphs that PatternMatch will find. More... | |

## Public Member Functions | |

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 | |

virtual bool | PatternRule (const transform::Graph &g, const std::vector< int > &subgraph, int) |

The PatternRule essentially answers: Given the current subgraph (ordered), should we append the new node at idx? | |

virtual bool | ValidatorRule (const transform::Graph &g, const std::vector< int > &subgraph) |

The ValidatorRule essentially answers: Given a subgraph, can we accept it? | |

virtual bool | ReplaceRule (const std::vector< int > &subgraph, transform::Graph *g_ptr) |

The ReplaceRule actually mutates the graph, and applies the transformation upon the subgraph. | |

void | SetPatternMatchType (PatternMatchType type) |

The Transform Base Object.

A Transform is an operation which manipulates a Caffe2 NetDef. You can consider it as a function: Transform.ApplyTo(NetDef) -> NetDef

A Transform Operation does 4 things: 1) Creates a Graph object from a NetDef, which stores connections. 2) Pattern Matches on the Graph, to find subgraphs it wants to change. 3) Replaces the subgraphs that it's matched with new operators. 4) Creates a NetDef from the changed Graph, and returns it.

The effect of a Transform is defined by its 3 protected virtual functions. 1) PatternRule determines for an ordered subgraph and a node, whether to consider adding the node to the subgraph. 2) ValidatorRule determines, for an ordered subgraph, whether it is a match. 3) ReplaceRule mutates the graph, based on a matched subgraph.

This is the base class for all derived classes to base off. To create your own transform, write your implementations for PatternRule, ValidatorRule, and ReplaceRule.

Definition at line 34 of file transform.h.

Determines the type of subgraphs that PatternMatch will find.

CONNECTED_SUBGRAPH will only match subgraphs that are connected. These subgraphs satisfy that every node of the match is connected to the subgraph of the nodes that come before it. For example, in the graph (1) –> (2) –> (3) –> (4), This is capable of matching the subgraph [2, 3] and [4, 3] This is not capable of matching the subgraph [2, 4].

SORTED_WRT_EXECUTION_ORDER will match subgraphs that guarantee sorted execution order. The nodes don't have to be connected. It is faster than General. For example, in the graph (1) –> (2) –> (3) –> (4), This is capable of matching the subgraph [2, 4], [3, 4]. This is not capable of matching the subgraph [3, 1], [4, 3].

GENERAL can match any subgraph. For example, in the graph (1) –> (2) –> (3) –> (4), This is capable of matching subgraphs [2, 4], [3, 4], [4, 2, 1]. There is no ordered subgraph of G that cannot be matched by this.

Definition at line 70 of file transform.h.

NetDef caffe2::Transform::ApplyTo | ( | const NetDef & | orig_net_def | ) |

Apply a Transform onto a NetDef.

Returns the transformed NetDef.

Definition at line 175 of file transform.cc.

std::vector< std::vector< int > > caffe2::Transform::PatternMatch | ( | const transform::Graph & | graph | ) |

Generates all matches (stored as ordered subgraphs) and returns them.

A match is stored as vector<int>, which is a mapping to OperatorDefs in Graph. The order matters.

Definition at line 15 of file transform.cc.

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

- caffe2/core/transform.h
- caffe2/core/transform.cc

Generated on Thu Apr 19 2018 13:04:01 for Caffe2 - C++ API by 1.8.11