| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | //
 | 
					
						
							|  |  |  | //  ShapeExpandDims.cpp
 | 
					
						
							|  |  |  | //  MNN
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  Created by MNN on 2019/01/10.
 | 
					
						
							|  |  |  | //  Copyright © 2018, Alibaba Group Holding Limited
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-27 22:16:57 +08:00
										 |  |  | #include "core/Macro.h"
 | 
					
						
							|  |  |  | #include "core/SizeComputer.hpp"
 | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace MNN { | 
					
						
							|  |  |  | class ExpandDimsComputer : public SizeComputer { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     virtual bool onComputeSize(const MNN::Op* op, const std::vector<Tensor*>& inputs, | 
					
						
							|  |  |  |                                const std::vector<Tensor*>& outputs) const override { | 
					
						
							| 
									
										
										
											
												- dynamic computation graph (beta)
	- add supports (/express)
	- add tests
	- add benchmarks with it (/benchmark/exprModels)
- Python
	- MNN engine and tools were submitted to pip
	- available on Windows/macOS/Linux
- Engine/Converter
	- add supports for each op benchmarking
	- refactor optimizer by separating steps
- CPU
	- add supports for Conv3D, Pool3D, ELU, ReverseSequence
	- fix ArgMax, Permute, Scale, BinaryOp, Slice, SliceTf
- OpenCL
	- add half transform in CPU
	- add broadcast supports for binary
	- optimize Conv2D, Reshape, Eltwise, Gemm, etc.
- OpenGL
	- add sub, real div supports for binary
	- add supports for unary
	- optimize Conv2D, Reshape
- Vulkan
	- add max supports for eltwise
- Metal
	- fix metallib missing problem
- Train/Quantization
	- use express to refactor training codes
											
										 
											2019-09-26 21:02:07 +08:00
										 |  |  |         const int inputSize = (int)inputs.size(); | 
					
						
							| 
									
										
										
										
											2019-09-01 19:25:26 +08:00
										 |  |  |         MNN_ASSERT(2 == inputSize || 1 == inputSize); | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  |         MNN_ASSERT(1 == outputs.size()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         auto input  = inputs[0]; | 
					
						
							|  |  |  |         auto output = outputs[0]; | 
					
						
							| 
									
										
										
										
											2019-09-01 19:25:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // default -1
 | 
					
						
							|  |  |  |         int dim = -1; | 
					
						
							|  |  |  |         if (inputSize == 2) { | 
					
						
							|  |  |  |             // read dim from the second input
 | 
					
						
							|  |  |  |             auto dims = inputs[1]; | 
					
						
							|  |  |  |             dim       = dims->host<int32_t>()[0]; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             // get dim from expand_dims parameter(axis)
 | 
					
						
							|  |  |  |             auto param = op->main_as_ExpandDims(); | 
					
						
							|  |  |  |             dim        = param->axis(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  |         if (dim == -1) { | 
					
						
							|  |  |  |             dim = input->dimensions() + 1 + dim; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         std::vector<int> outputShape; | 
					
						
							|  |  |  |         for (int i = 0; i < input->buffer().dimensions; i++) { | 
					
						
							|  |  |  |             if (i == dim) { | 
					
						
							|  |  |  |                 outputShape.push_back(1); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             outputShape.push_back(input->buffer().dim[i].extent); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (dim == input->buffer().dimensions) { | 
					
						
							|  |  |  |             outputShape.push_back(1); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         output->buffer().dimensions = (int)outputShape.size(); | 
					
						
							|  |  |  |         output->buffer().type       = input->buffer().type; | 
					
						
							|  |  |  |         int previousStride          = 1; | 
					
						
							|  |  |  |         for (int i = output->buffer().dimensions - 1; i >= 0; i--) { | 
					
						
							|  |  |  |             output->buffer().dim[i].stride = previousStride; | 
					
						
							|  |  |  |             output->buffer().dim[i].extent = outputShape[i]; | 
					
						
							|  |  |  |             previousStride *= output->buffer().dim[i].extent; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-08-22 20:13:46 +08:00
										 |  |  |         TensorUtils::getDescribe(output)->dimensionFormat = TensorUtils::getDescribe(input)->dimensionFormat; | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-22 20:13:46 +08:00
										 |  |  | REGISTER_SHAPE_INPUTS(ExpandDimsComputer, OpType_ExpandDims, {1}); | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | } // namespace MNN
 |