+++ /dev/null
-#include "caffe2/core/logging.h"
-#include "caffe2/opt/converter.h"
-#include "caffe2/opt/mobile.h"
-#include "caffe2/opt/passes.h"
-
-namespace caffe2 {
-namespace opt {
-
-using namespace nom;
-
-C10_EXPORT void sinkMaxPool(nom::repr::NNModule* nn) {
- for (auto max_pool_node :
- repr::nn::nodeIterator<repr::MaxPool>(nn->dataFlow)) {
- if (repr::nn::getInputs(max_pool_node).size() != 1) {
- continue;
- }
-
- auto max_pool_outputs = repr::nn::getOutputs(max_pool_node);
- if (max_pool_outputs.size() != 1) {
- continue;
- }
-
- auto consumers = repr::nn::getConsumers(max_pool_outputs.front());
- if (consumers.size() != 1) {
- continue;
- }
-
- // TODO Sink MaxPool in more cases.
- auto relu_node = consumers.front();
- if (!repr::nn::is<repr::Relu>(relu_node)) {
- continue;
- }
-
- if (repr::nn::getOutputs(relu_node).size() != 1) {
- continue;
- }
-
- // input -> MaxPool -> intermediate -> Relu -> output
- nn->dataFlow.swapNodes(max_pool_node, relu_node);
- // input -> Relu -> intermediate -> MaxPool -> output
- }
-}
-
-REGISTER_OPT_PASS_FROM_FUNC(SinkMaxPool, sinkMaxPool);
-
-} // namespace opt
-} // namespace caffe2
+++ /dev/null
-#ifndef CAFFE2_OPT_SINK_H_
-#define CAFFE2_OPT_SINK_H_
-
-#include "caffe2/core/common.h"
-#include "caffe2/proto/caffe2_pb.h"
-#include "nomnigraph/Representations/NeuralNet.h"
-
-namespace caffe2 {
-namespace opt {
-
-CAFFE2_API void sinkMaxPool(nom::repr::NNModule* nn);
-
-} // namespace opt
-} // namespace caffe2
-
-#endif // CAFFE2_OPT_SINK_H_
#include "caffe2/opt/onnxifi_transformer.h"
#include "caffe2/opt/optimize_ideep.h"
#include "caffe2/opt/passes.h"
-#include "caffe2/opt/sink.h"
#include "caffe2/predictor/predictor.h"
#include "caffe2/python/pybind_state_registry.h"
#include "caffe2/utils/cpuid.h"
return py::bytes(out);
});
- m.def("transform_sinkMaxPool", [](py::bytes def) {
- caffe2::NetDef proto;
- CAFFE_ENFORCE(ParseProtoFromLargeString(def.cast<std::string>(), &proto));
-
- auto nn = caffe2::convertToNNModule(proto);
- opt::sinkMaxPool(&nn);
- auto new_proto = caffe2::convertToCaffe2Proto(nn, proto);
-
- std::string out;
- new_proto.SerializeToString(&out);
- return py::bytes(out);
- });
-
auto initialize = [&]() {
// Initialization of the module
#ifdef USE_NUMPY
)
-def sinkMaxPool(net):
- net.Proto().ParseFromString(
- C.transform_sinkMaxPool(net.Proto().SerializeToString())
- )
-
-
def optimizeForIDEEP(net, training_mode = False):
net.Proto().ParseFromString(
C.transform_optimizeForIDEEP(net.Proto().SerializeToString(), training_mode)
assert net.Proto().op[0].output[0] != net.Proto().op[0].input[0]
assert net.Proto().op[1].output[0] != net.Proto().op[1].input[0]
- def test_transformer_SinkMaxPool(self):
- net = self._base_test_net()
- net.MaxPool(["Y"], ["Y1"], kernel=3)
- net.Relu(["Y1"], ["Y1"])
- transformer.SinkMaxPool(net)
- assert tu.str_compare(net.Proto().op[1].type, "Relu")
- assert tu.str_compare(net.Proto().op[2].type, "MaxPool")
-
@given(
size=st.integers(7, 10),
input_channels=st.integers(1, 10),