@@ -3486,11 +3486,16 @@ void Net::connect(String _outPin, String _inPin)
3486
3486
Mat Net::forward (const String& outputName)
3487
3487
{
3488
3488
CV_TRACE_FUNCTION ();
3489
+ CV_Assert (!empty ());
3489
3490
3490
3491
String layerName = outputName;
3491
3492
3492
3493
if (layerName.empty ())
3493
- layerName = getLayerNames ().back ();
3494
+ {
3495
+ std::vector<String> layerNames = getLayerNames ();
3496
+ CV_Assert (!layerNames.empty ());
3497
+ layerName = layerNames.back ();
3498
+ }
3494
3499
3495
3500
std::vector<LayerPin> pins (1 , impl->getPinByAlias (layerName));
3496
3501
impl->setUpNet (pins);
@@ -3502,11 +3507,17 @@ Mat Net::forward(const String& outputName)
3502
3507
AsyncArray Net::forwardAsync (const String& outputName)
3503
3508
{
3504
3509
CV_TRACE_FUNCTION ();
3510
+ CV_Assert (!empty ());
3511
+
3505
3512
#ifdef CV_CXX11
3506
3513
String layerName = outputName;
3507
3514
3508
3515
if (layerName.empty ())
3509
- layerName = getLayerNames ().back ();
3516
+ {
3517
+ std::vector<String> layerNames = getLayerNames ();
3518
+ CV_Assert (!layerNames.empty ());
3519
+ layerName = layerNames.back ();
3520
+ }
3510
3521
3511
3522
std::vector<LayerPin> pins (1 , impl->getPinByAlias (layerName));
3512
3523
impl->setUpNet (pins);
@@ -3527,11 +3538,16 @@ AsyncArray Net::forwardAsync(const String& outputName)
3527
3538
void Net::forward (OutputArrayOfArrays outputBlobs, const String& outputName)
3528
3539
{
3529
3540
CV_TRACE_FUNCTION ();
3541
+ CV_Assert (!empty ());
3530
3542
3531
3543
String layerName = outputName;
3532
3544
3533
3545
if (layerName.empty ())
3534
- layerName = getLayerNames ().back ();
3546
+ {
3547
+ std::vector<String> layerNames = getLayerNames ();
3548
+ CV_Assert (!layerNames.empty ());
3549
+ layerName = layerNames.back ();
3550
+ }
3535
3551
3536
3552
std::vector<LayerPin> pins (1 , impl->getPinByAlias (layerName));
3537
3553
impl->setUpNet (pins);
@@ -4118,6 +4134,8 @@ std::vector<Ptr<Layer> > Net::getLayerInputs(LayerId layerId)
4118
4134
4119
4135
std::vector<String> Net::getLayerNames () const
4120
4136
{
4137
+ CV_TRACE_FUNCTION ();
4138
+
4121
4139
std::vector<String> res;
4122
4140
res.reserve (impl->layers .size ());
4123
4141
0 commit comments