@@ -146,13 +146,11 @@ static void computeShapeByReshapeMask(const MatShape &srcShape,
146
146
class ReshapeLayerImpl : public ReshapeLayer
147
147
{
148
148
public:
149
- ReshapeLayerImpl (const LayerParams& params):
150
- performReordering (false )
149
+ ReshapeLayerImpl (const LayerParams& params)
151
150
{
152
151
setParamsFrom (params);
153
152
int axis = params.get <int >(" axis" , 0 );
154
153
int numAxes = params.get <int >(" num_axes" , -1 );
155
- enableReordering = params.get <bool >(" reorder_dims" , false );
156
154
CV_Assert (numAxes >= -1 );
157
155
newShapeRange = (numAxes == -1 ) ? Range (axis, INT_MAX) : Range (axis, axis + numAxes);
158
156
@@ -184,25 +182,6 @@ class ReshapeLayerImpl : public ReshapeLayer
184
182
return true ;
185
183
}
186
184
187
- void finalize (const std::vector<Mat*> &inputs, std::vector<Mat> &outputs)
188
- {
189
- CV_Assert (inputs.size ());
190
- CV_Assert (outputs.size ());
191
- Mat srcBlob = *inputs[0 ];
192
- int dims = srcBlob.dims ;
193
- MatShape inputShape = shape (srcBlob), outShape = shape (outputs[0 ]);
194
-
195
- // input.total() == output.total(). So if reordering is require,
196
- // one of the sizes will be are not equal.
197
- // Example where reordering is require: from 1x128x4x4 to 1x2048
198
- // Example where reordering is NOT require: from 1x1024x1x1 to 1x1024.
199
- bool reorderingRequire = false ;
200
- const int minDims = min (dims, (int )outShape.size ());
201
- for (int i = 0 ; !reorderingRequire && i < minDims; ++i)
202
- reorderingRequire = inputShape[i] != outShape[i];
203
- performReordering = enableReordering && reorderingRequire;
204
- }
205
-
206
185
void forward (std::vector<Mat*> &inputs, std::vector<Mat> &outputs, std::vector<Mat> &internals)
207
186
{
208
187
CV_TRACE_FUNCTION ();
@@ -211,43 +190,10 @@ class ReshapeLayerImpl : public ReshapeLayer
211
190
for (size_t i = 0 ; i < inputs.size (); i++)
212
191
{
213
192
Mat srcBlob = *inputs[i];
214
- MatShape inputShape = shape (srcBlob), outShape = shape (outputs[i]);
215
-
216
- if (performReordering)
217
- {
218
- float *dstData = internals[i].ptr <float >();
219
- const float *srcData = srcBlob.ptr <float >();
220
-
221
- int num = inputShape[0 ], channels = inputShape[1 ], height = inputShape[2 ], width = inputShape[3 ];
222
- int total = num*channels*height*width;
223
- for (int i_n = 0 ; i_n < num; i_n++) {
224
- for (int i_c = 0 ; i_c < channels; i_c++) {
225
- for (int i_h = 0 ; i_h < height; i_h++) {
226
- for (int i_w = 0 ; i_w < width; i_w++) {
227
- int src_i = channels*height*width*i_n + height*width*i_c + width*i_h + i_w;
228
- int dst_i = channels*height*width*i_n + i_c + channels*width*i_h + channels*i_w;
229
-
230
- CV_Assert (dst_i < total);
231
- CV_Assert (src_i < total);
232
-
233
- dstData[dst_i] = srcData[src_i];
234
- }
235
- }
236
- }
237
- }
238
- internals[i].copyTo (outputs[i]);
239
- }
240
- else
241
- {
242
- if (outputs[i].data != srcBlob.data )
243
- srcBlob.reshape (1 , outShape).copyTo (outputs[i]);
244
- }
193
+ if (outputs[i].data != srcBlob.data )
194
+ srcBlob.reshape (1 , shape (outputs[i])).copyTo (outputs[i]);
245
195
}
246
196
}
247
-
248
- private:
249
- std::vector<std::vector<int > > outShapes;
250
- bool enableReordering, performReordering;
251
197
};
252
198
253
199
Ptr<ReshapeLayer> ReshapeLayer::create (const LayerParams& params)
0 commit comments