Read classes' names from file
Signed-off-by: Micaela Verucchi <micaelaverucchi@gmail.com>
This commit is contained in:
@@ -12,3 +12,5 @@ build/
|
|||||||
*.hdf5
|
*.hdf5
|
||||||
*.pk
|
*.pk
|
||||||
*.table
|
*.table
|
||||||
|
demo/COCO_val2017
|
||||||
|
demo/BDD100k_val
|
||||||
@@ -127,7 +127,7 @@ namespace tk { namespace dnn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void darknetAddLayer(tk::dnn::Network *net, darknetFields_t &f, std::string wgs_path, std::vector<tk::dnn::Layer*> &netLayers) {
|
void darknetAddLayer(tk::dnn::Network *net, darknetFields_t &f, std::string wgs_path, std::vector<tk::dnn::Layer*> &netLayers, const std::vector<std::string>& names) {
|
||||||
if(net == nullptr)
|
if(net == nullptr)
|
||||||
FatalError("Cant add a layer without a Net\n");
|
FatalError("Cant add a layer without a Net\n");
|
||||||
|
|
||||||
@@ -180,14 +180,30 @@ namespace tk { namespace dnn {
|
|||||||
} else if(f.type == "yolo") {
|
} else if(f.type == "yolo") {
|
||||||
std::string wgs = wgs_path + "/g" + std::to_string(netLayers.size()) + ".bin";
|
std::string wgs = wgs_path + "/g" + std::to_string(netLayers.size()) + ".bin";
|
||||||
printf("%d %d %s %d %f\n", f.classes, f.num/f.n_mask, wgs.c_str(), f.n_mask, f.scale_xy);
|
printf("%d %d %s %d %f\n", f.classes, f.num/f.n_mask, wgs.c_str(), f.n_mask, f.scale_xy);
|
||||||
netLayers.push_back(new tk::dnn::Yolo(net, f.classes, f.num/f.n_mask, wgs, f.n_mask, f.scale_xy));
|
tk::dnn::Yolo *l = new tk::dnn::Yolo(net, f.classes, f.num/f.n_mask, wgs, f.n_mask, f.scale_xy);
|
||||||
|
l->classesNames = names;
|
||||||
|
netLayers.push_back(l);
|
||||||
|
|
||||||
} else{
|
} else{
|
||||||
FatalError("layer not supported: " + f.type);
|
FatalError("layer not supported: " + f.type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tk::dnn::Network* darknetParser(std::string cfg_file, std::string wgs_path) {
|
std::vector<std::string> darknetReadNames(const std::string& names_file){
|
||||||
|
std::ifstream if_names(names_file);
|
||||||
|
if(!if_names.is_open())
|
||||||
|
FatalError("cloud not open names file: " + names_file);
|
||||||
|
|
||||||
|
std::vector<std::string> names;
|
||||||
|
std::string line;
|
||||||
|
while(std::getline(if_names, line))
|
||||||
|
names.push_back(line);
|
||||||
|
|
||||||
|
if_names.close();
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
tk::dnn::Network* darknetParser(const std::string& cfg_file, const std::string& wgs_path, const std::string& names_file) {
|
||||||
|
|
||||||
tk::dnn::Network *net = nullptr;
|
tk::dnn::Network *net = nullptr;
|
||||||
|
|
||||||
@@ -198,6 +214,8 @@ namespace tk { namespace dnn {
|
|||||||
if(!if_cfg.is_open())
|
if(!if_cfg.is_open())
|
||||||
FatalError("cloud not open cfg file: " + cfg_file);
|
FatalError("cloud not open cfg file: " + cfg_file);
|
||||||
|
|
||||||
|
std::vector<std::string> names = darknetReadNames(names_file);
|
||||||
|
|
||||||
darknetFields_t fields; // will be filled with layers fields
|
darknetFields_t fields; // will be filled with layers fields
|
||||||
std::string line;
|
std::string line;
|
||||||
while(std::getline(if_cfg, line)) {
|
while(std::getline(if_cfg, line)) {
|
||||||
@@ -218,7 +236,7 @@ namespace tk { namespace dnn {
|
|||||||
if(fields.type == "net")
|
if(fields.type == "net")
|
||||||
net = darknetAddNet(fields);
|
net = darknetAddNet(fields);
|
||||||
else
|
else
|
||||||
darknetAddLayer(net, fields, wgs_path, netLayers);
|
darknetAddLayer(net, fields, wgs_path, netLayers, names);
|
||||||
}
|
}
|
||||||
|
|
||||||
// new type
|
// new type
|
||||||
@@ -237,7 +255,7 @@ namespace tk { namespace dnn {
|
|||||||
|
|
||||||
// end of filled type
|
// end of filled type
|
||||||
if(fields.type != "") {
|
if(fields.type != "") {
|
||||||
darknetAddLayer(net, fields, wgs_path, netLayers);
|
darknetAddLayer(net, fields, wgs_path, netLayers, names);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(net == nullptr) {
|
if(net == nullptr) {
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
person
|
||||||
|
bicycle
|
||||||
|
car
|
||||||
|
motorbike
|
||||||
|
aeroplane
|
||||||
|
bus
|
||||||
|
train
|
||||||
|
truck
|
||||||
|
boat
|
||||||
|
traffic light
|
||||||
|
fire hydrant
|
||||||
|
stop sign
|
||||||
|
parking meter
|
||||||
|
bench
|
||||||
|
bird
|
||||||
|
cat
|
||||||
|
dog
|
||||||
|
horse
|
||||||
|
sheep
|
||||||
|
cow
|
||||||
|
elephant
|
||||||
|
bear
|
||||||
|
zebra
|
||||||
|
giraffe
|
||||||
|
backpack
|
||||||
|
umbrella
|
||||||
|
handbag
|
||||||
|
tie
|
||||||
|
suitcase
|
||||||
|
frisbee
|
||||||
|
skis
|
||||||
|
snowboard
|
||||||
|
sports ball
|
||||||
|
kite
|
||||||
|
baseball bat
|
||||||
|
baseball glove
|
||||||
|
skateboard
|
||||||
|
surfboard
|
||||||
|
tennis racket
|
||||||
|
bottle
|
||||||
|
wine glass
|
||||||
|
cup
|
||||||
|
fork
|
||||||
|
knife
|
||||||
|
spoon
|
||||||
|
bowl
|
||||||
|
banana
|
||||||
|
apple
|
||||||
|
sandwich
|
||||||
|
orange
|
||||||
|
broccoli
|
||||||
|
carrot
|
||||||
|
hot dog
|
||||||
|
pizza
|
||||||
|
donut
|
||||||
|
cake
|
||||||
|
chair
|
||||||
|
sofa
|
||||||
|
pottedplant
|
||||||
|
bed
|
||||||
|
diningtable
|
||||||
|
toilet
|
||||||
|
tvmonitor
|
||||||
|
laptop
|
||||||
|
mouse
|
||||||
|
remote
|
||||||
|
keyboard
|
||||||
|
cell phone
|
||||||
|
microwave
|
||||||
|
oven
|
||||||
|
toaster
|
||||||
|
sink
|
||||||
|
refrigerator
|
||||||
|
book
|
||||||
|
clock
|
||||||
|
vase
|
||||||
|
scissors
|
||||||
|
teddy bear
|
||||||
|
hair drier
|
||||||
|
toothbrush
|
||||||
@@ -9,7 +9,7 @@ int main() {
|
|||||||
std::string bin_path = "yolo3";
|
std::string bin_path = "yolo3";
|
||||||
downloadWeightsifDoNotExist("yolo3/layers/input.bin", bin_path, "https://cloud.hipert.unimore.it/s/jPXmHyptpLoNdNR/download");
|
downloadWeightsifDoNotExist("yolo3/layers/input.bin", bin_path, "https://cloud.hipert.unimore.it/s/jPXmHyptpLoNdNR/download");
|
||||||
|
|
||||||
tk::dnn::Network *net = tk::dnn::darknetParser("../tests/yolo3/yolov3.cfg", "yolo3/layers");
|
tk::dnn::Network *net = tk::dnn::darknetParser("../tests/yolo3/yolov3.cfg", "yolo3/layers", "../tests/yolo3/coco.names");
|
||||||
net->print();
|
net->print();
|
||||||
|
|
||||||
std::vector<tk::dnn::Yolo*> yolo;
|
std::vector<tk::dnn::Yolo*> yolo;
|
||||||
@@ -18,11 +18,6 @@ int main() {
|
|||||||
yolo.push_back((tk::dnn::Yolo*)net->layers[i]);
|
yolo.push_back((tk::dnn::Yolo*)net->layers[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill classes names
|
|
||||||
for(int i=0; i<3; i++) {
|
|
||||||
yolo[i]->classesNames = {"person" , "bicycle" , "car" , "motorbike" , "aeroplane" , "bus" , "train" , "truck" , "boat" , "traffic light" , "fire hydrant" , "stop sign" , "parking meter" , "bench" , "bird" , "cat" , "dog" , "horse" , "sheep" , "cow" , "elephant" , "bear" , "zebra" , "giraffe" , "backpack" , "umbrella" , "handbag" , "tie" , "suitcase" , "frisbee" , "skis" , "snowboard" , "sports ball" , "kite" , "baseball bat" , "baseball glove" , "skateboard" , "surfboard" , "tennis racket" , "bottle" , "wine glass" , "cup" , "fork" , "knife" , "spoon" , "bowl" , "banana" , "apple" , "sandwich" , "orange" , "broccoli" , "carrot" , "hot dog" , "pizza" , "donut" , "cake" , "chair" , "sofa" , "pottedplant" , "bed" , "diningtable" , "toilet" , "tvmonitor" , "laptop" , "mouse" , "remote" , "keyboard" , "cell phone" , "microwave" , "oven" , "toaster" , "sink" , "refrigerator" , "book" , "clock" , "vase" , "scissors" , "teddy bear" , "hair drier" , "toothbrush"};
|
|
||||||
}
|
|
||||||
|
|
||||||
//convert network to tensorRT
|
//convert network to tensorRT
|
||||||
tk::dnn::NetworkRT netRT(net, net->getNetworkRTName("yolo3"));
|
tk::dnn::NetworkRT netRT(net, net->getNetworkRTName("yolo3"));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user