diff --git a/CMakeLists.txt b/CMakeLists.txt index 16415f3..f0d2ec1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,6 +85,9 @@ target_link_libraries(test_yolo3_coco4 tkDNN) add_executable(test_yolo3 tests/yolo3/yolo3.cpp) target_link_libraries(test_yolo3 tkDNN) +add_executable(test_yolo3_512 tests/yolo3_512/yolo3_512.cpp) +target_link_libraries(test_yolo3_512 tkDNN) + add_executable(test_yolo3_tiny tests/yolo3_tiny/yolo3_tiny.cpp) target_link_libraries(test_yolo3_tiny tkDNN) diff --git a/tests/yolo3_512/yolo3_512.cpp b/tests/yolo3_512/yolo3_512.cpp new file mode 100644 index 0000000..1050990 --- /dev/null +++ b/tests/yolo3_512/yolo3_512.cpp @@ -0,0 +1,95 @@ +#include +#include +#include "tkdnn.h" + +int main() { + + // Network layout + tk::dnn::dataDim_t dim(1, 3, 512, 512, 1); + tk::dnn::Network net(dim); + + // create yolo3 model + std::string bin_path = "../tests/yolo3_512"; + downloadWeightsifDoNotExist("../tests/yolo3_512/layers/input.bin", bin_path, "https://cloud.hipert.unimore.it/s/39XbxMxaX7zwFKQ/download"); + int classes = 80; + tk::dnn::Yolo *yolo [3]; + #include "models/Yolo3.h" + + + + // 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"}; + } + + // Load input + dnnType *data; + dnnType *input_h; + readBinaryFile(input_bin, dim.tot(), &input_h, &data); + + //print network model + net.print(); + + //convert network to tensorRT + tk::dnn::NetworkRT netRT(&net, "yolo3_512.rt"); + + // the network have 3 outputs + tk::dnn::dataDim_t out_dim[3]; + for(int i=0; i<3; i++) out_dim[i] = yolo[i]->output_dim; + dnnType *cudnn_out[3], *rt_out[3]; + + tk::dnn::dataDim_t dim1 = dim; //input dim + printCenteredTitle(" CUDNN inference ", '=', 30); { + dim1.print(); + TIMER_START + net.infer(dim1, data); + TIMER_STOP + dim1.print(); + } + for(int i=0; i<3; i++) cudnn_out[i] = yolo[i]->dstData; + + printCenteredTitle(" compute detections ", '=', 30); + TIMER_START + int ndets = 0; + tk::dnn::Yolo::detection *dets = tk::dnn::Yolo::allocateDetections(tk::dnn::Yolo::MAX_DETECTIONS, classes); + for(int i=0; i<3; i++) yolo[i]->computeDetections(dets, ndets, net.input_dim.w, net.input_dim.h, 0.5); + tk::dnn::Yolo::mergeDetections(dets, ndets, classes); + + for(int j=0; j 0) + cl = c; + } + std::cout<