Skip to content

Commit 2d1fc7a

Browse files
committed
Merge pull request #391 from rokm:dnn_fix
2 parents c5a273f + fcedee0 commit 2d1fc7a

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

modules/dnn/include/opencv2/dnn/layer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class CV_EXPORTS LayerFactory
7777
LayerFactory();
7878

7979
struct Impl;
80-
static Ptr<Impl> impl;
80+
static Ptr<Impl> impl();
8181
};
8282

8383
/** @brief Registers layer constructor in runtime.

modules/dnn/src/dnn.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -561,34 +561,38 @@ struct LayerFactory::Impl : public std::map<String, LayerFactory::Constuctor>
561561
{
562562
};
563563

564-
//allocates on load and cleans on exit
565-
Ptr<LayerFactory::Impl> LayerFactory::impl(new LayerFactory::Impl());
564+
Ptr<LayerFactory::Impl> LayerFactory::impl ()
565+
{
566+
// allocate on first use
567+
static Ptr<LayerFactory::Impl> impl_(new LayerFactory::Impl());
568+
return impl_;
569+
}
566570

567571
void LayerFactory::registerLayer(const String &_type, Constuctor constructor)
568572
{
569573
String type = _type.toLowerCase();
570-
Impl::iterator it = impl->find(type);
574+
Impl::iterator it = impl()->find(type);
571575

572-
if (it != impl->end() && it->second != constructor)
576+
if (it != impl()->end() && it->second != constructor)
573577
{
574578
CV_Error(cv::Error::StsBadArg, "Layer \"" + type + "\" already was registered");
575579
}
576580

577-
impl->insert(std::make_pair(type, constructor));
581+
impl()->insert(std::make_pair(type, constructor));
578582
}
579583

580584
void LayerFactory::unregisterLayer(const String &_type)
581585
{
582586
String type = _type.toLowerCase();
583-
impl->erase(type);
587+
impl()->erase(type);
584588
}
585589

586590
Ptr<Layer> LayerFactory::createLayerInstance(const String &_type, LayerParams& params)
587591
{
588592
String type = _type.toLowerCase();
589-
Impl::const_iterator it = LayerFactory::impl->find(type);
593+
Impl::const_iterator it = LayerFactory::impl()->find(type);
590594

591-
if (it != impl->end())
595+
if (it != impl()->end())
592596
{
593597
return it->second(params);
594598
}

0 commit comments

Comments
 (0)