| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | //
 | 
					
						
							|  |  |  | //  ShapeSqueeze.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"
 | 
					
						
							|  |  |  | #include "core/TensorUtils.hpp"
 | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace MNN { | 
					
						
							| 
									
										
										
										
											2019-06-05 10:45:59 +08:00
										 |  |  | class UnSqueezeSizeComputer : public SizeComputer { | 
					
						
							|  |  |  |     virtual bool onComputeSize(const MNN::Op* op, const std::vector<Tensor*>& inputs, | 
					
						
							|  |  |  |                                const std::vector<Tensor*>& outputs) const override { | 
					
						
							|  |  |  |         MNN_ASSERT(1 == inputs.size()); | 
					
						
							|  |  |  |         MNN_ASSERT(1 == outputs.size()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												- 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* squeezeDim = nullptr; | 
					
						
							|  |  |  |         int squeezeDimSize    = 0; | 
					
						
							|  |  |  |         if (nullptr != op->main_as_SqueezeParam()->squeezeDims()) { | 
					
						
							|  |  |  |             squeezeDim     = op->main_as_SqueezeParam()->squeezeDims()->data(); | 
					
						
							|  |  |  |             squeezeDimSize = op->main_as_SqueezeParam()->squeezeDims()->size(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-06-05 10:45:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         std::set<int> dimSet; | 
					
						
							|  |  |  |         for (int i = 0; i < squeezeDimSize; i++) { | 
					
						
							|  |  |  |             dimSet.insert(squeezeDim[i]); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-05 10:45:59 +08:00
										 |  |  |         auto& ob = outputs[0]->buffer(); | 
					
						
							|  |  |  |         auto ib  = inputs[0]->buffer(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ob.dimensions = ib.dimensions + squeezeDimSize; | 
					
						
							|  |  |  |         int oDim      = 0; | 
					
						
							|  |  |  |         for (int i = 0; i < ob.dimensions; i++) { | 
					
						
							|  |  |  |             ob.dim[i].extent = 1; | 
					
						
							|  |  |  |             if (dimSet.find(i) == dimSet.end()) { | 
					
						
							|  |  |  |                 ob.dim[i].extent = ib.dim[oDim].extent; | 
					
						
							| 
									
										
										
										
											2019-07-19 17:09:09 +08:00
										 |  |  |                 oDim++; | 
					
						
							| 
									
										
										
										
											2019-06-05 10:45:59 +08:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         ob.type                                               = inputs[0]->buffer().type; | 
					
						
							|  |  |  |         TensorUtils::getDescribe(outputs[0])->dimensionFormat = TensorUtils::getDescribe(inputs[0])->dimensionFormat; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | class SqueezeSizeComputer : public SizeComputer { | 
					
						
							|  |  |  |     virtual bool onComputeSize(const MNN::Op* op, const std::vector<Tensor*>& inputs, | 
					
						
							|  |  |  |                                const std::vector<Tensor*>& outputs) const override { | 
					
						
							|  |  |  |         MNN_ASSERT(1 == inputs.size()); | 
					
						
							|  |  |  |         MNN_ASSERT(1 == outputs.size()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												- 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* squeezeDim = nullptr; | 
					
						
							|  |  |  |         int squeezeDimSize    = 0; | 
					
						
							|  |  |  |         if (nullptr != op->main_as_SqueezeParam()->squeezeDims()) { | 
					
						
							|  |  |  |             squeezeDim     = op->main_as_SqueezeParam()->squeezeDims()->data(); | 
					
						
							|  |  |  |             squeezeDimSize = op->main_as_SqueezeParam()->squeezeDims()->size(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         std::set<int> dimSet; | 
					
						
							|  |  |  |         for (int i = 0; i < squeezeDimSize; i++) { | 
					
						
							|  |  |  |             dimSet.insert(squeezeDim[i]); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         auto& ob = outputs[0]->buffer(); | 
					
						
							|  |  |  |         auto ib  = inputs[0]->buffer(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-01 17:08:47 +08:00
										 |  |  |         if (squeezeDimSize == 0) { | 
					
						
							|  |  |  |             for (int i = 0; i < ib.dimensions; ++i) { | 
					
						
							|  |  |  |                 if (ib.dim[i].extent == 1) { | 
					
						
							|  |  |  |                     dimSet.insert(i); | 
					
						
							|  |  |  |                     ++squeezeDimSize; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  |         MNN_ASSERT(squeezeDimSize < ib.dimensions); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ob.dimensions = ib.dimensions - squeezeDimSize; | 
					
						
							|  |  |  |         int oDim      = 0; | 
					
						
							|  |  |  |         for (int i = 0; i < ib.dimensions; i++) { | 
					
						
							|  |  |  |             if (dimSet.find(i) == dimSet.end()) { | 
					
						
							|  |  |  |                 ob.dim[oDim].extent = ib.dim[i].extent; | 
					
						
							|  |  |  |                 oDim++; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-06-05 10:45:59 +08:00
										 |  |  |         ob.type                                               = inputs[0]->buffer().type; | 
					
						
							|  |  |  |         TensorUtils::getDescribe(outputs[0])->dimensionFormat = TensorUtils::getDescribe(inputs[0])->dimensionFormat; | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | REGISTER_SHAPE(SqueezeSizeComputer, OpType_Squeeze); | 
					
						
							| 
									
										
										
										
											2019-06-05 10:45:59 +08:00
										 |  |  | REGISTER_SHAPE(UnSqueezeSizeComputer, OpType_Unsqueeze); | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | } // namespace MNN
 |