|
|
|
@ -339,25 +339,17 @@ struct Net::Impl |
|
|
|
|
std::cout << layers[netOutputs[i]].name << std::endl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void allocateOutputBlobs() |
|
|
|
|
void allocateLayer(int lid) |
|
|
|
|
{ |
|
|
|
|
MapIdToLayerData::iterator it; |
|
|
|
|
for (it = layers.begin(); it != layers.end(); it++) |
|
|
|
|
{ |
|
|
|
|
LayerData &ld = it->second; |
|
|
|
|
ld.outputBlobs.resize(ld.outputNames.size()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
LayerData &ld = layers[lid]; |
|
|
|
|
|
|
|
|
|
void allocateLayers() |
|
|
|
|
{ |
|
|
|
|
allocateOutputBlobs(); |
|
|
|
|
//already allocated
|
|
|
|
|
if (ld.flag) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
MapIdToLayerData::iterator it; |
|
|
|
|
for (it = layers.begin(); it != layers.end(); it++) |
|
|
|
|
{ |
|
|
|
|
int lid = it->first; |
|
|
|
|
LayerData &ld = it->second; |
|
|
|
|
//allocate parents
|
|
|
|
|
for (set<int>::iterator i = ld.inputLayersId.begin(); i != ld.inputLayersId.end(); i++) |
|
|
|
|
allocateLayer(*i); |
|
|
|
|
|
|
|
|
|
//create instance
|
|
|
|
|
if (ld.layerInstance == NULL && lid != 0) |
|
|
|
@ -379,8 +371,25 @@ struct Net::Impl |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//allocate layer
|
|
|
|
|
ld.outputBlobs.resize(ld.outputNames.size()); |
|
|
|
|
if (ld.layerInstance) |
|
|
|
|
ld.layerInstance->allocate(ld.inputBlobs, ld.outputBlobs); |
|
|
|
|
|
|
|
|
|
//std::cout << ld.name << " shape:" << ld.outputBlobs[0].shape() << std::endl;
|
|
|
|
|
|
|
|
|
|
ld.flag = 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void allocateLayers() |
|
|
|
|
{ |
|
|
|
|
MapIdToLayerData::iterator it; |
|
|
|
|
for (it = layers.begin(); it != layers.end(); it++) |
|
|
|
|
it->second.flag = 0; |
|
|
|
|
|
|
|
|
|
for (it = layers.begin(); it != layers.end(); it++) |
|
|
|
|
{ |
|
|
|
|
int lid = it->first; |
|
|
|
|
allocateLayer(lid); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -395,27 +404,24 @@ struct Net::Impl |
|
|
|
|
|
|
|
|
|
LayerData &ld = layers[layerId]; |
|
|
|
|
|
|
|
|
|
//already was forwarded
|
|
|
|
|
if (ld.flag) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
//forward parents
|
|
|
|
|
for (set<int>::iterator i = ld.inputLayersId.begin(); i != ld.inputLayersId.end(); i++) |
|
|
|
|
{ |
|
|
|
|
LayerData &ild = layers[*i]; |
|
|
|
|
|
|
|
|
|
if (!ild.flag) |
|
|
|
|
{ |
|
|
|
|
if (ild.layerInstance) |
|
|
|
|
ild.layerInstance->forward(ild.inputBlobs, ild.outputBlobs); |
|
|
|
|
ild.flag = 1; |
|
|
|
|
} |
|
|
|
|
forwardLayer(*i, false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//forward itself
|
|
|
|
|
if (!ld.flag) |
|
|
|
|
{ |
|
|
|
|
if (ld.layerInstance) |
|
|
|
|
if (ld.layerInstance && layerId != 0) |
|
|
|
|
ld.layerInstance->forward(ld.inputBlobs, ld.outputBlobs); |
|
|
|
|
|
|
|
|
|
//std::cout << ld.name << " shape:" << ld.outputBlobs[0].shape() << std::endl;
|
|
|
|
|
|
|
|
|
|
ld.flag = 1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void forwardAll() |
|
|
|
|
{ |
|
|
|
@ -496,8 +502,9 @@ void Net::setBlob(BlobId outputName, const Blob &blob) |
|
|
|
|
if (!impl->findOutputsByName(name, &found, 1)) |
|
|
|
|
CV_Error(cv::Error::StsObjectNotFound, "Request blob \"" + name + "\" not found"); |
|
|
|
|
|
|
|
|
|
impl->allocateOutputBlobs(); |
|
|
|
|
impl->layers[found.lid].outputBlobs[found.oid] = blob; |
|
|
|
|
LayerData &ld = impl->layers[found.lid]; |
|
|
|
|
ld.outputBlobs.resize(ld.outputNames.size()); |
|
|
|
|
ld.outputBlobs[found.oid] = blob; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Blob Net::getBlob(BlobId outputName) |
|
|
|
@ -508,8 +515,8 @@ Blob Net::getBlob(BlobId outputName) |
|
|
|
|
if (!impl->findOutputsByName(name, &found, 1)) |
|
|
|
|
CV_Error(cv::Error::StsObjectNotFound, "Request blob \"" + name + "\" not found"); |
|
|
|
|
|
|
|
|
|
impl->allocateOutputBlobs(); |
|
|
|
|
return impl->layers[found.lid].outputBlobs[found.oid]; |
|
|
|
|
LayerData &ld = impl->layers[found.lid]; |
|
|
|
|
return ld.outputBlobs[found.oid]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Importer::~Importer() |
|
|
|
|