| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | //
 | 
					
						
							|  |  |  | //  ShapeUnpack.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 UnpackComputer : public SizeComputer { | 
					
						
							|  |  |  |     virtual bool onComputeSize(const MNN::Op *op, const std::vector<Tensor *> &inputs, | 
					
						
							|  |  |  |                                const std::vector<Tensor *> &outputs) const override { | 
					
						
							| 
									
										
										
										
											2020-04-11 20:37:20 +08:00
										 |  |  |         if (nullptr == op || inputs.empty()) { | 
					
						
							|  |  |  |             // Avoid crash for special model
 | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  |         auto unpack    = op->main_as_Axis(); | 
					
						
							|  |  |  |         const int axis = unpack->axis(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         auto &input = inputs[0]->buffer(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const int inputDimensions = input.dimensions; | 
					
						
							|  |  |  |         MNN_ASSERT(1 <= inputDimensions); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         std::vector<int> outDims; | 
					
						
							|  |  |  |         for (int i = 0; i < inputDimensions; i++) { | 
					
						
							|  |  |  |             if (axis == i) { | 
					
						
							|  |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             outDims.push_back(input.dim[i].extent); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         const int outputDimensions = inputDimensions - 1; | 
					
						
							|  |  |  |         MNN_ASSERT(outDims.size() == outputDimensions); | 
					
						
							|  |  |  |         for (int i = 0; i < outputs.size(); i++) { | 
					
						
							|  |  |  |             auto &output      = outputs[i]->buffer(); | 
					
						
							|  |  |  |             output.dimensions = outputDimensions; | 
					
						
							|  |  |  |             output.type       = input.type; | 
					
						
							|  |  |  |             for (int j = 0; j < outputDimensions; j++) { | 
					
						
							|  |  |  |                 output.dim[j].extent = outDims[j]; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-08-22 20:13:46 +08:00
										 |  |  |             TensorUtils::getDescribe(outputs[i])->dimensionFormat = TensorUtils::getDescribe(inputs[0])->dimensionFormat; | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | REGISTER_SHAPE(UnpackComputer, OpType_Unpack); | 
					
						
							|  |  |  | } // namespace MNN
 |