@@ -2413,14 +2413,42 @@ struct Net::Impl : public detail::NetImplBase
2413
2413
}
2414
2414
2415
2415
// fuse convolution layer followed by eltwise + relu
2416
- if ( IS_DNN_OPENCL_TARGET (preferableTarget) && ld.layerInstance ->type == " Convolution" )
2416
+ while (nextData && IS_DNN_OPENCL_TARGET (preferableTarget) && ld.layerInstance ->type == " Convolution" ) // semantic of 'if'
2417
2417
{
2418
- Ptr<EltwiseLayer> nextEltwiseLayer;
2419
- if ( nextData )
2420
- nextEltwiseLayer = nextData->layerInstance .dynamicCast <EltwiseLayer>();
2418
+ Ptr<EltwiseLayer> nextEltwiseLayer = nextData->layerInstance .dynamicCast <EltwiseLayer>();
2419
+ if (nextEltwiseLayer.empty ())
2420
+ break ;
2421
+
2422
+ if (pinsToKeep.count (lpNext) != 0 )
2423
+ break ;
2424
+ if (nextData->inputBlobsId .size () != 2 )
2425
+ break ;
2426
+
2427
+ if (!nextData->params .has (" operation" ) || nextData->params .get <String>(" operation" ).toLowerCase () == " sum" )
2428
+ {
2429
+ if (nextData->params .has (" coeff" ))
2430
+ {
2431
+ DictValue paramCoeff = nextData->params .get (" coeff" );
2432
+ int n = paramCoeff.size ();
2433
+ bool isCoeffOneOne = (n == 2 );
2434
+ for (int i = 0 ; isCoeffOneOne && i < n; i++)
2435
+ {
2436
+ float c = paramCoeff.get <float >(i);
2437
+ isCoeffOneOne &= (c == 1 .0f );
2438
+ }
2439
+ if (!isCoeffOneOne)
2440
+ {
2441
+ CV_LOG_DEBUG (NULL , " DNN/OpenCL: fusion of 'Sum' without coeffs (or {1.0, 1.0}) is supported only" );
2442
+ break ;
2443
+ }
2444
+ }
2445
+ }
2446
+ else
2447
+ {
2448
+ CV_LOG_DEBUG (NULL , " DNN/OpenCL: fusion with eltwise operation is not supported: " << nextData->params .get <String>(" operation" ));
2449
+ break ;
2450
+ }
2421
2451
2422
- if ( !nextEltwiseLayer.empty () && pinsToKeep.count (lpNext) == 0 &&
2423
- nextData && nextData->inputBlobsId .size () == 2 )
2424
2452
{
2425
2453
LayerData *eltwiseData = nextData;
2426
2454
@@ -2517,6 +2545,8 @@ struct Net::Impl : public detail::NetImplBase
2517
2545
}
2518
2546
}
2519
2547
}
2548
+
2549
+ break ;
2520
2550
}
2521
2551
}
2522
2552
@@ -2698,11 +2728,11 @@ struct Net::Impl : public detail::NetImplBase
2698
2728
2699
2729
Ptr<Layer> layer = ld.layerInstance ;
2700
2730
2701
- TickMeter tm;
2702
- tm.start ();
2703
-
2704
2731
if ( !ld.skip )
2705
2732
{
2733
+ TickMeter tm;
2734
+ tm.start ();
2735
+
2706
2736
std::map<int , Ptr<BackendNode> >::iterator it = ld.backendNodes .find (preferableBackend);
2707
2737
if (preferableBackend == DNN_BACKEND_OPENCV || it == ld.backendNodes .end () || it->second .empty ())
2708
2738
{
@@ -2881,12 +2911,15 @@ struct Net::Impl : public detail::NetImplBase
2881
2911
CV_Error (Error::StsNotImplemented, " Unknown backend identifier" );
2882
2912
}
2883
2913
}
2914
+
2915
+ tm.stop ();
2916
+ int64 t = tm.getTimeTicks ();
2917
+ layersTimings[ld.id ] = (t > 0 ) ? t : t + 1 ; // zero for skipped layers only
2884
2918
}
2885
2919
else
2886
- tm.reset ();
2887
-
2888
- tm.stop ();
2889
- layersTimings[ld.id ] = tm.getTimeTicks ();
2920
+ {
2921
+ layersTimings[ld.id ] = 0 ;
2922
+ }
2890
2923
2891
2924
ld.flag = 1 ;
2892
2925
}
0 commit comments