parse layer and network
This commit is contained in:
@@ -5,9 +5,10 @@
|
||||
namespace tk { namespace dnn {
|
||||
|
||||
struct darknetFields_t{
|
||||
std::string type = "";
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
|
||||
int channels = 3;
|
||||
};
|
||||
|
||||
std::string darknetParseType(const std::string& line){
|
||||
@@ -20,21 +21,37 @@ namespace tk { namespace dnn {
|
||||
return type;
|
||||
}
|
||||
|
||||
darknetFields_t parseFields(const std::string& line){
|
||||
|
||||
bool darknetParseFields(const std::string& line, darknetFields_t &fields){
|
||||
return true;
|
||||
}
|
||||
|
||||
tk::dnn::Network *darknetAddNet(darknetFields_t &fields) {
|
||||
std::cout<<"Add Net: "<<fields.type<<"\n";
|
||||
dataDim_t dim(1, fields.channels, fields.height, fields.width);
|
||||
return new tk::dnn::Network(dim);
|
||||
}
|
||||
|
||||
void darknetAddLayer(tk::dnn::Network *net, darknetFields_t &fields) {
|
||||
if(net == nullptr)
|
||||
FatalError("Cant add a layer without a Net\n");
|
||||
|
||||
tk::dnn::Network* DarknetParser(std::string cfg_file) {
|
||||
std::cout<<"Add layer: "<<fields.type<<"\n";
|
||||
if(fields.type == "convolutional") {
|
||||
|
||||
tk::dnn::dataDim_t dim;
|
||||
tk::dnn::Network *net = new tk::dnn::Network(dim);
|
||||
} else{
|
||||
FatalError("layer not supported: " + fields.type);
|
||||
}
|
||||
}
|
||||
|
||||
tk::dnn::Network* darknetParser(std::string cfg_file) {
|
||||
|
||||
tk::dnn::Network *net = nullptr;
|
||||
|
||||
std::ifstream if_cfg(cfg_file);
|
||||
if(!if_cfg.is_open())
|
||||
FatalError("cloud not open cfg file: " + cfg_file);
|
||||
|
||||
darknetFields_t fields; // will be filled with layers fields
|
||||
std::string line;
|
||||
while(std::getline(if_cfg, line)) {
|
||||
// remove comments
|
||||
@@ -49,8 +66,35 @@ namespace tk { namespace dnn {
|
||||
|
||||
std::string type = darknetParseType(line);
|
||||
if(type.size() > 0) {
|
||||
std::cout<<"type: "<<type<<"\n";
|
||||
// end of filled type
|
||||
if(fields.type != "") {
|
||||
if(fields.type == "net")
|
||||
net = darknetAddNet(fields);
|
||||
else
|
||||
darknetAddLayer(net, fields);
|
||||
}
|
||||
|
||||
// new type
|
||||
//std::cout<<"type: "<<type<<"\n";
|
||||
fields = darknetFields_t();
|
||||
fields.type = type;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(darknetParseFields(line, fields)) {
|
||||
// already parsed do nothing
|
||||
} else {
|
||||
FatalError("could not parse line: " + line);
|
||||
}
|
||||
}
|
||||
|
||||
// end of filled type
|
||||
if(fields.type != "") {
|
||||
darknetAddLayer(net, fields);
|
||||
}
|
||||
|
||||
if(net == nullptr) {
|
||||
FatalError("net not found\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
int main() {
|
||||
|
||||
tk::dnn::Network *net = tk::dnn::DarknetParser("../tests/yolo3/yolov3.cfg");
|
||||
tk::dnn::Network *net = tk::dnn::darknetParser("../tests/yolo3/yolov3.cfg");
|
||||
|
||||
// Network layout
|
||||
//tk::dnn::dataDim_t dim(1, 3, 416, 416, 1);
|
||||
|
||||
Reference in New Issue
Block a user