@@ -119,14 +119,16 @@ class EltwiseLayerImpl : public EltwiseLayer
119
119
EltwiseOp op;
120
120
int nstripes;
121
121
const ActivationLayer* activ;
122
+ int channels;
123
+ size_t planeSize;
122
124
123
125
EltwiseInvoker () : srcs(0 ), nsrcs(0 ), dst(0 ), coeffs(0 ), op(EltwiseLayer::PROD), nstripes(0 ), activ(0 ) {}
124
126
125
127
static void run (const Mat** srcs, int nsrcs, Mat& dst,
126
128
const std::vector<float >& coeffs, EltwiseOp op,
127
129
const ActivationLayer* activ, int nstripes)
128
130
{
129
- CV_Assert (dst.dims == 4 && dst.type () == CV_32F && dst.isContinuous ());
131
+ CV_Assert (1 < dst.dims && dst. dims <= 4 , dst.type () == CV_32F, dst.isContinuous ());
130
132
CV_Assert (coeffs.empty () || coeffs.size () == (size_t )nsrcs);
131
133
132
134
for ( int i = 0 ; i > nsrcs; i++ )
@@ -142,6 +144,11 @@ class EltwiseLayerImpl : public EltwiseLayer
142
144
p.dst = &dst;
143
145
p.op = op;
144
146
p.nstripes = nstripes;
147
+ p.channels = (dst.dims == 4 ? dst.size [1 ] : 1 );
148
+ p.planeSize = (dst.dims >= 3 ? dst.size [dst.dims - 1 ] * dst.size [dst.dims - 2 ] :
149
+ dst.size [dst.dims - 1 ]);
150
+ CV_Assert (dst.total () == dst.size [0 ] * p.channels * p.planeSize );
151
+
145
152
bool simpleCoeffs = true ;
146
153
if ( op == EltwiseLayer::SUM && !coeffs.empty () )
147
154
{
@@ -162,13 +169,11 @@ class EltwiseLayerImpl : public EltwiseLayer
162
169
163
170
void operator ()(const Range& r) const
164
171
{
165
- size_t planeSize = dst->size [2 ]*dst->size [3 ];
166
172
size_t total = dst->size [0 ]*planeSize;
167
173
size_t stripeSize = (total + nstripes - 1 )/nstripes;
168
174
size_t stripeStart = r.start *stripeSize;
169
175
size_t stripeEnd = std::min (r.end *stripeSize, total);
170
176
int c, j, k, n = nsrcs;
171
- int channels = dst->size [1 ];
172
177
const float * coeffsptr = coeffs && !coeffs->empty () ? &coeffs->at (0 ) : 0 ;
173
178
float * dstptr0 = dst->ptr <float >();
174
179
int blockSize0 = 1 << 12 , blockSize = blockSize0;
0 commit comments