--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Reshape.h"
+#include "Convert.h"
+
+#include <cassert>
+#include <vector>
+
+namespace
+{
+
+std::vector<int32_t> vector_new_shape(const tflchef::ReshapeOptions &options)
+{
+ std::vector<int32_t> shapes;
+
+ for (int i = 0; i < options.new_shape_size(); ++i)
+ {
+ shapes.push_back(options.new_shape(i));
+ }
+
+ return shapes;
+}
+
+} // namespace
+
+flatbuffers::Offset<void> ReshapeChef::value(flatbuffers::FlatBufferBuilder &fbb) const
+{
+ auto &operation = (*_operation);
+
+ assert(operation.has_reshape_options());
+
+ auto options = operation.reshape_options();
+ auto shapes = vector_new_shape(options);
+ // Note: 'CreateVector' should be placed before 'options_builder'
+ // Read flatbuffers.h 'void NotNested()' for more information
+ auto fb_new_shape = fbb.CreateVector(shapes);
+
+ tflite::ReshapeOptionsBuilder options_builder{fbb};
+
+ options_builder.add_new_shape(fb_new_shape);
+
+ return options_builder.Finish().Union();
+}
+
+std::unique_ptr<OpChef> ReshapeChefFactory::create(const tflchef::Operation *operation) const
+{
+ return std::unique_ptr<OpChef>{new ReshapeChef{operation}};
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __OP_RESHAPE_H__
+#define __OP_RESHAPE_H__
+
+#include "OpChef.h"
+
+class ReshapeChef final : public OpChef
+{
+public:
+ explicit ReshapeChef(const tflchef::Operation *operation) : _operation{operation}
+ {
+ // DO NOTHING
+ }
+
+public:
+ tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_RESHAPE; }
+
+ tflite::BuiltinOptions type(void) const override { return tflite::BuiltinOptions_ReshapeOptions; }
+
+ flatbuffers::Offset<void> value(flatbuffers::FlatBufferBuilder &fbb) const override;
+
+private:
+ const tflchef::Operation *_operation;
+};
+
+struct ReshapeChefFactory final : public OpChefFactory
+{
+ std::unique_ptr<OpChef> create(const tflchef::Operation *operation) const override;
+};
+
+#endif // __OP_RESHAPE_H__
OP_CHEF(Conv2D, Conv2DChefFactory)
OP_CHEF(MaxPool2D, MaxPool2DChefFactory)
OP_CHEF(ReLU6, ReLU6ChefFactory)
+OP_CHEF(Reshape, ReshapeChefFactory)
#include "Op/Conv2D.h"
#include "Op/MaxPool2D.h"
#include "Op/ReLU6.h"
+#include "Op/Reshape.h"
#endif // __OP_CHEFS_H__
optional Activation activation = 2 [default = NONE];
}
+message ReshapeOptions {
+ repeated int32 new_shape = 1;
+}
+
message Operation {
optional string type = 1;
repeated string input = 2;
optional Pool2DOptions averagepool2d_options = 101;
optional ConcatenationOptions concatenation_options = 102;
optional Pool2DOptions maxpool2d_options = 103;
+ optional ReshapeOptions reshape_options = 104;
}
message ModelRecipe {
--- /dev/null
+operand {
+ name: "ifm"
+ type: FLOAT32
+ shape { dim: 1 dim: 1 dim: 1 dim: 10 }
+}
+operand {
+ name: "ofm"
+ type: FLOAT32
+ shape { dim: 10 }
+}
+operation {
+ type: "Reshape"
+ reshape_options {
+ new_shape: 10
+ }
+ input: "ifm"
+ output: "ofm"
+}
+input: "ifm"
+output: "ofm"