From 8c629ebe7b5a845cc8b1cc6f1661d043ebe7b4a8 Mon Sep 17 00:00:00 2001 From: mbosi <205839@studenti.unimore.it> Date: Sat, 14 Sep 2019 19:03:13 +0200 Subject: [PATCH] string input and flir test --- include/Layer.h | 10 +- include/models/Yolo3.h | 289 +++++++++ include/utils.h | 2 +- src/Conv2d.cpp | 2 +- src/Dense.cpp | 2 +- src/LayerWgs.cpp | 2 +- src/Region.cpp | 2 +- src/Yolo.cpp | 4 +- src/Yolo3Detection.cpp | 2 +- src/utils.cpp | 2 +- tests/yolo3_berkeley/yolo3_berkeley.cpp | 308 +--------- tests/yolo3_coco4/yolo3_coco4.cpp | 308 +--------- tests/yolo3_flir/yolo3_flir.cfg | 785 ++++++++++++++++++++++++ tests/yolo3_flir/yolo3_flir.cpp | 88 +++ 14 files changed, 1198 insertions(+), 608 deletions(-) create mode 100644 include/models/Yolo3.h create mode 100644 tests/yolo3_flir/yolo3_flir.cfg create mode 100644 tests/yolo3_flir/yolo3_flir.cpp diff --git a/include/Layer.h b/include/Layer.h index c7871b5..55729ce 100644 --- a/include/Layer.h +++ b/include/Layer.h @@ -75,7 +75,7 @@ class LayerWgs : public Layer { public: LayerWgs(Network *net, int inputs, int outputs, int kh, int kw, int kt, - const char* fname_weights, bool batchnorm = false); + std::string fname_weights, bool batchnorm = false); virtual ~LayerWgs(); int inputs, outputs; @@ -108,7 +108,7 @@ public: class Dense : public LayerWgs { public: - Dense(Network *net, int out_ch, const char* fname_weights); + Dense(Network *net, int out_ch, std::string fname_weights); virtual ~Dense(); virtual layerType_t getLayerType() { return LAYER_DENSE; }; @@ -151,7 +151,7 @@ class Conv2d : public LayerWgs { public: Conv2d( Network *net, int out_ch, int kernelH, int kernelW, int strideH, int strideW, int paddingH, int paddingW, - const char* fname_weights, bool batchnorm = false); + std::string fname_weights, bool batchnorm = false); virtual ~Conv2d(); virtual layerType_t getLayerType() { return LAYER_CONV2D; }; @@ -352,7 +352,7 @@ public: int sort_class; }; - Yolo(Network *net, int classes, int num, const char* fname_weights); + Yolo(Network *net, int classes, int num, std::string fname_weights); virtual ~Yolo(); virtual layerType_t getLayerType() { return LAYER_YOLO; }; @@ -389,7 +389,7 @@ class RegionInterpret { public: RegionInterpret(dataDim_t input_dim, dataDim_t output_dim, - int classes, int coords, int num, float thresh, const char* fname_weights); + int classes, int coords, int num, float thresh, std::string fname_weights); ~RegionInterpret(); dataDim_t input_dim, output_dim; diff --git a/include/models/Yolo3.h b/include/models/Yolo3.h new file mode 100644 index 0000000..cd69b32 --- /dev/null +++ b/include/models/Yolo3.h @@ -0,0 +1,289 @@ +int preYoloFilters = (classes+5)*3; + +std::string input_bin = bin_path + "/layers/input.bin"; +std::vector output_bins = { + bin_path + "/debug/layer82_out.bin", + bin_path + "/debug/layer94_out.bin", + bin_path + "/debug/layer106_out.bin" +}; +std::string c0_bin = bin_path + "/layers/c0.bin"; +std::string c1_bin = bin_path + "/layers/c1.bin"; +std::string c2_bin = bin_path + "/layers/c2.bin"; +std::string c3_bin = bin_path + "/layers/c3.bin"; +std::string c5_bin = bin_path + "/layers/c5.bin"; +std::string c6_bin = bin_path + "/layers/c6.bin"; +std::string c7_bin = bin_path + "/layers/c7.bin"; +std::string c9_bin = bin_path + "/layers/c9.bin"; +std::string c10_bin = bin_path + "/layers/c10.bin"; +std::string c12_bin = bin_path + "/layers/c12.bin"; +std::string c13_bin = bin_path + "/layers/c13.bin"; +std::string c14_bin = bin_path + "/layers/c14.bin"; +std::string c16_bin = bin_path + "/layers/c16.bin"; +std::string c17_bin = bin_path + "/layers/c17.bin"; +std::string c19_bin = bin_path + "/layers/c19.bin"; +std::string c20_bin = bin_path + "/layers/c20.bin"; +std::string c22_bin = bin_path + "/layers/c22.bin"; +std::string c23_bin = bin_path + "/layers/c23.bin"; +std::string c25_bin = bin_path + "/layers/c25.bin"; +std::string c26_bin = bin_path + "/layers/c26.bin"; +std::string c28_bin = bin_path + "/layers/c28.bin"; +std::string c29_bin = bin_path + "/layers/c29.bin"; +std::string c31_bin = bin_path + "/layers/c31.bin"; +std::string c32_bin = bin_path + "/layers/c32.bin"; +std::string c34_bin = bin_path + "/layers/c34.bin"; +std::string c35_bin = bin_path + "/layers/c35.bin"; +std::string c37_bin = bin_path + "/layers/c37.bin"; +std::string c38_bin = bin_path + "/layers/c38.bin"; +std::string c39_bin = bin_path + "/layers/c39.bin"; +std::string c41_bin = bin_path + "/layers/c41.bin"; +std::string c42_bin = bin_path + "/layers/c42.bin"; +std::string c44_bin = bin_path + "/layers/c44.bin"; +std::string c45_bin = bin_path + "/layers/c45.bin"; +std::string c47_bin = bin_path + "/layers/c47.bin"; +std::string c48_bin = bin_path + "/layers/c48.bin"; +std::string c50_bin = bin_path + "/layers/c50.bin"; +std::string c51_bin = bin_path + "/layers/c51.bin"; +std::string c53_bin = bin_path + "/layers/c53.bin"; +std::string c54_bin = bin_path + "/layers/c54.bin"; +std::string c56_bin = bin_path + "/layers/c56.bin"; +std::string c57_bin = bin_path + "/layers/c57.bin"; +std::string c59_bin = bin_path + "/layers/c59.bin"; +std::string c60_bin = bin_path + "/layers/c60.bin"; +std::string c62_bin = bin_path + "/layers/c62.bin"; +std::string c63_bin = bin_path + "/layers/c63.bin"; +std::string c64_bin = bin_path + "/layers/c64.bin"; +std::string c66_bin = bin_path + "/layers/c66.bin"; +std::string c67_bin = bin_path + "/layers/c67.bin"; +std::string c69_bin = bin_path + "/layers/c69.bin"; +std::string c70_bin = bin_path + "/layers/c70.bin"; +std::string c72_bin = bin_path + "/layers/c72.bin"; +std::string c73_bin = bin_path + "/layers/c73.bin"; +std::string c75_bin = bin_path + "/layers/c75.bin"; +std::string c76_bin = bin_path + "/layers/c76.bin"; +std::string c77_bin = bin_path + "/layers/c77.bin"; +std::string c78_bin = bin_path + "/layers/c78.bin"; +std::string c79_bin = bin_path + "/layers/c79.bin"; +std::string c80_bin = bin_path + "/layers/c80.bin"; +std::string c81_bin = bin_path + "/layers/c81.bin"; +std::string g82_bin = bin_path + "/layers/g82.bin"; +std::string c84_bin = bin_path + "/layers/c84.bin"; +std::string c87_bin = bin_path + "/layers/c87.bin"; +std::string c88_bin = bin_path + "/layers/c88.bin"; +std::string c89_bin = bin_path + "/layers/c89.bin"; +std::string c90_bin = bin_path + "/layers/c90.bin"; +std::string c91_bin = bin_path + "/layers/c91.bin"; +std::string c92_bin = bin_path + "/layers/c92.bin"; +std::string c93_bin = bin_path + "/layers/c93.bin"; +std::string g94_bin = bin_path + "/layers/g94.bin"; +std::string c96_bin = bin_path + "/layers/c96.bin"; +std::string c99_bin = bin_path + "/layers/c99.bin"; +std::string c100_bin = bin_path + "/layers/c100.bin"; +std::string c101_bin = bin_path + "/layers/c101.bin"; +std::string c102_bin = bin_path + "/layers/c102.bin"; +std::string c103_bin = bin_path + "/layers/c103.bin"; +std::string c104_bin = bin_path + "/layers/c104.bin"; +std::string c105_bin = bin_path + "/layers/c105.bin"; +std::string g106_bin = bin_path + "/layers/g106.bin"; + +tk::dnn::Conv2d c0 (&net, 32, 3, 3, 1, 1, 1, 1, c0_bin, true); +tk::dnn::Activation a0 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c1 (&net, 64, 3, 3, 2, 2, 1, 1, c1_bin, true); +tk::dnn::Activation a1 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c2 (&net, 32, 1, 1, 1, 1, 0, 0, c2_bin, true); +tk::dnn::Activation a2 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c3 (&net, 64, 3, 3, 1, 1, 1, 1, c3_bin, true); +tk::dnn::Activation a3 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s4 (&net, &a1); +tk::dnn::Conv2d c5 (&net, 128, 3, 3, 2, 2, 1, 1, c5_bin, true); +tk::dnn::Activation a5 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c6 (&net, 64, 1, 1, 1, 1, 0, 0, c6_bin, true); +tk::dnn::Activation a6 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c7 (&net, 128, 3, 3, 1, 1, 1, 1, c7_bin, true); +tk::dnn::Activation a7 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s8 (&net, &a5); +tk::dnn::Conv2d c9 (&net, 64, 1, 1, 1, 1, 0, 0, c9_bin, true); +tk::dnn::Activation a9 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c10 (&net, 128, 3, 3, 1, 1, 1, 1, c10_bin, true); +tk::dnn::Activation a10 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s11 (&net, &s8); + +tk::dnn::Conv2d c12 (&net, 256, 3, 3, 2, 2, 1, 1, c12_bin, true); +tk::dnn::Activation a12 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c13 (&net, 128, 1, 1, 1, 1, 0, 0, c13_bin, true); +tk::dnn::Activation a13 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c14 (&net, 256, 3, 3, 1, 1, 1, 1, c14_bin, true); +tk::dnn::Activation a14 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s15 (&net, &a12); + +tk::dnn::Conv2d c16 (&net, 128, 1, 1, 1, 1, 0, 0, c16_bin, true); +tk::dnn::Activation a16 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c17 (&net, 256, 3, 3, 1, 1, 1, 1, c17_bin, true); +tk::dnn::Activation a17 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s18 (&net, &s15); +tk::dnn::Conv2d c19 (&net, 128, 1, 1, 1, 1, 0, 0, c19_bin, true); +tk::dnn::Activation a19 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c20 (&net, 256, 3, 3, 1, 1, 1, 1, c20_bin, true); +tk::dnn::Activation a20 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s21 (&net, &s18); +tk::dnn::Conv2d c22 (&net, 128, 1, 1, 1, 1, 0, 0, c22_bin, true); +tk::dnn::Activation a22 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c23 (&net, 256, 3, 3, 1, 1, 1, 1, c23_bin, true); +tk::dnn::Activation a23 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s24 (&net, &s21); +tk::dnn::Conv2d c25 (&net, 128, 1, 1, 1, 1, 0, 0, c25_bin, true); +tk::dnn::Activation a25 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c26 (&net, 256, 3, 3, 1, 1, 1, 1, c26_bin, true); +tk::dnn::Activation a26 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s27 (&net, &s24); +tk::dnn::Conv2d c28 (&net, 128, 1, 1, 1, 1, 0, 0, c28_bin, true); +tk::dnn::Activation a28 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c29 (&net, 256, 3, 3, 1, 1, 1, 1, c29_bin, true); +tk::dnn::Activation a29 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s30 (&net, &s27); +tk::dnn::Conv2d c31 (&net, 128, 1, 1, 1, 1, 0, 0, c31_bin, true); +tk::dnn::Activation a31 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c32 (&net, 256, 3, 3, 1, 1, 1, 1, c32_bin, true); +tk::dnn::Activation a32 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s33 (&net, &s30); +tk::dnn::Conv2d c34 (&net, 128, 1, 1, 1, 1, 0, 0, c34_bin, true); +tk::dnn::Activation a34 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c35 (&net, 256, 3, 3, 1, 1, 1, 1, c35_bin, true); +tk::dnn::Activation a35 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s36 (&net, &s33); + +tk::dnn::Conv2d c37 (&net, 512, 3, 3, 2, 2, 1, 1, c37_bin, true); +tk::dnn::Activation a37 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c38 (&net, 256, 1, 1, 1, 1, 0, 0, c38_bin, true); +tk::dnn::Activation a38 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c39 (&net, 512, 3, 3, 1, 1, 1, 1, c39_bin, true); +tk::dnn::Activation a39 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s40 (&net, &a37); + +tk::dnn::Conv2d c41 (&net, 256, 1, 1, 1, 1, 0, 0, c41_bin, true); +tk::dnn::Activation a41 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c42 (&net, 512, 3, 3, 1, 1, 1, 1, c42_bin, true); +tk::dnn::Activation a42 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s43 (&net, &s40); +tk::dnn::Conv2d c44 (&net, 256, 1, 1, 1, 1, 0, 0, c44_bin, true); +tk::dnn::Activation a44 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c45 (&net, 512, 3, 3, 1, 1, 1, 1, c45_bin, true); +tk::dnn::Activation a45 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s46 (&net, &s43); +tk::dnn::Conv2d c47 (&net, 256, 1, 1, 1, 1, 0, 0, c47_bin, true); +tk::dnn::Activation a47 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c48 (&net, 512, 3, 3, 1, 1, 1, 1, c48_bin, true); +tk::dnn::Activation a48 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s49 (&net, &s46); +tk::dnn::Conv2d c50 (&net, 256, 1, 1, 1, 1, 0, 0, c50_bin, true); +tk::dnn::Activation a50 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c51 (&net, 512, 3, 3, 1, 1, 1, 1, c51_bin, true); +tk::dnn::Activation a51 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s52 (&net, &s49); +tk::dnn::Conv2d c53 (&net, 256, 1, 1, 1, 1, 0, 0, c53_bin, true); +tk::dnn::Activation a53 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c54 (&net, 512, 3, 3, 1, 1, 1, 1, c54_bin, true); +tk::dnn::Activation a54 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s55 (&net, &s52); +tk::dnn::Conv2d c56 (&net, 256, 1, 1, 1, 1, 0, 0, c56_bin, true); +tk::dnn::Activation a56 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c57 (&net, 512, 3, 3, 1, 1, 1, 1, c57_bin, true); +tk::dnn::Activation a57 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s58 (&net, &s55); +tk::dnn::Conv2d c59 (&net, 256, 1, 1, 1, 1, 0, 0, c59_bin, true); +tk::dnn::Activation a59 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c60 (&net, 512, 3, 3, 1, 1, 1, 1, c60_bin, true); +tk::dnn::Activation a60 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s61 (&net, &s58); + +tk::dnn::Conv2d c62 (&net,1024, 3, 3, 2, 2, 1, 1, c62_bin, true); +tk::dnn::Activation a62 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c63 (&net, 512, 1, 1, 1, 1, 0, 0, c63_bin, true); +tk::dnn::Activation a63 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c64 (&net,1024, 3, 3, 1, 1, 1, 1, c64_bin, true); +tk::dnn::Activation a64 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s65 (&net, &a62); + +tk::dnn::Conv2d c66 (&net, 512, 1, 1, 1, 1, 0, 0, c66_bin, true); +tk::dnn::Activation a66 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c67 (&net,1024, 3, 3, 1, 1, 1, 1, c67_bin, true); +tk::dnn::Activation a67 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s68 (&net, &s65); + +tk::dnn::Conv2d c69 (&net, 512, 1, 1, 1, 1, 0, 0, c69_bin, true); +tk::dnn::Activation a69 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c70 (&net,1024, 3, 3, 1, 1, 1, 1, c70_bin, true); +tk::dnn::Activation a70 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s71 (&net, &s68); + +tk::dnn::Conv2d c72 (&net, 512, 1, 1, 1, 1, 0, 0, c72_bin, true); +tk::dnn::Activation a72 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c73 (&net,1024, 3, 3, 1, 1, 1, 1, c73_bin, true); +tk::dnn::Activation a73 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Shortcut s74 (&net, &s71); + +tk::dnn::Conv2d c75 (&net, 512, 1, 1, 1, 1, 0, 0, c75_bin, true); +tk::dnn::Activation a75 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c76 (&net,1024, 3, 3, 1, 1, 1, 1, c76_bin, true); +tk::dnn::Activation a76 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c77 (&net, 512, 1, 1, 1, 1, 0, 0, c77_bin, true); +tk::dnn::Activation a77 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c78 (&net,1024, 3, 3, 1, 1, 1, 1, c78_bin, true); +tk::dnn::Activation a78 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c79 (&net, 512, 1, 1, 1, 1, 0, 0, c79_bin, true); +tk::dnn::Activation a79 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c80 (&net,1024, 3, 3, 1, 1, 1, 1, c80_bin, true); +tk::dnn::Activation a80 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c81 (&net, preYoloFilters, 1, 1, 1, 1, 0, 0, c81_bin, false); +tk::dnn::Yolo yolo0 (&net, classes, 3, g82_bin); + +tk::dnn::Layer *m83_layers[1] = { &a79 }; +tk::dnn::Route m83 (&net, m83_layers, 1); +tk::dnn::Conv2d c84 (&net, 256, 1, 1, 1, 1, 0, 0, c84_bin, true); +tk::dnn::Activation a84 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Upsample u85 (&net, 2); + +tk::dnn::Layer *m86_layers[2] = { &u85, &s61 }; +tk::dnn::Route m86 (&net, m86_layers, 2); +tk::dnn::Conv2d c87 (&net, 256, 1, 1, 1, 1, 0, 0, c87_bin, true); +tk::dnn::Activation a87 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c88 (&net, 512, 3, 3, 1, 1, 1, 1, c88_bin, true); +tk::dnn::Activation a88 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c89 (&net, 256, 1, 1, 1, 1, 0, 0, c89_bin, true); +tk::dnn::Activation a89 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c90 (&net, 512, 3, 3, 1, 1, 1, 1, c90_bin, true); +tk::dnn::Activation a90 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c91 (&net, 256, 1, 1, 1, 1, 0, 0, c91_bin, true); +tk::dnn::Activation a91 (&net, tk::dnn::ACTIVATION_LEAKY); + +tk::dnn::Conv2d c92 (&net, 512, 3, 3, 1, 1, 1, 1, c92_bin, true); +tk::dnn::Activation a92 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c93 (&net, preYoloFilters, 1, 1, 1, 1, 0, 0, c93_bin, false); +tk::dnn::Yolo yolo1 (&net, classes, 3, g94_bin); + +tk::dnn::Layer *m95_layers[1] = { &a91 }; +tk::dnn::Route m95 (&net, m95_layers, 1); +tk::dnn::Conv2d c96 (&net, 128, 1, 1, 1, 1, 0, 0, c96_bin, true); +tk::dnn::Activation a96 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Upsample u97 (&net, 2); + +tk::dnn::Layer *m98_layers[2] = { &u97, &s36 }; +tk::dnn::Route m98 (&net, m98_layers, 2); +tk::dnn::Conv2d c99 (&net, 128, 1, 1, 1, 1, 0, 0, c99_bin, true); +tk::dnn::Activation a99 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c100 (&net, 256, 3, 3, 1, 1, 1, 1, c100_bin, true); +tk::dnn::Activation a100 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c101 (&net, 128, 1, 1, 1, 1, 0, 0, c101_bin, true); +tk::dnn::Activation a101 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c102 (&net, 256, 3, 3, 1, 1, 1, 1, c102_bin, true); +tk::dnn::Activation a102 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c103 (&net, 128, 1, 1, 1, 1, 0, 0, c103_bin, true); +tk::dnn::Activation a103 (&net, tk::dnn::ACTIVATION_LEAKY); + +tk::dnn::Conv2d c104 (&net, 256, 3, 3, 1, 1, 1, 1, c104_bin, true); +tk::dnn::Activation a104 (&net, tk::dnn::ACTIVATION_LEAKY); +tk::dnn::Conv2d c105 (&net, preYoloFilters, 1, 1, 1, 1, 0, 0, c105_bin, false); +tk::dnn::Yolo yolo2 (&net, classes, 3, g106_bin); + +yolo[0] = &yolo0; +yolo[1] = &yolo1; +yolo[2] = &yolo2; \ No newline at end of file diff --git a/include/utils.h b/include/utils.h index a46b2c4..dc34a31 100644 --- a/include/utils.h +++ b/include/utils.h @@ -90,7 +90,7 @@ void printCenteredTitle(const char *title, char fill, int dim); bool fileExist(const char *fname); -void readBinaryFile(const char* fname, int size, dnnType** data_h, dnnType** data_d, int seek = 0); +void readBinaryFile(std::string fname, int size, dnnType** data_h, dnnType** data_d, int seek = 0); int checkResult(int size, dnnType *data_d, dnnType *correct_d, bool device = true); void printDeviceVector(int size, dnnType* vec_d, bool device = true); void resize(int size, dnnType **data); diff --git a/src/Conv2d.cpp b/src/Conv2d.cpp index bfb8316..3dfdce6 100644 --- a/src/Conv2d.cpp +++ b/src/Conv2d.cpp @@ -6,7 +6,7 @@ namespace tk { namespace dnn { Conv2d::Conv2d( Network *net, int out_ch, int kernelH, int kernelW, int strideH, int strideW, int paddingH, int paddingW, - const char* fname_weights, bool batchnorm) : + std::string fname_weights, bool batchnorm) : LayerWgs(net, net->getOutputDim().c, out_ch, kernelH, kernelW, 1, fname_weights, batchnorm) { diff --git a/src/Dense.cpp b/src/Dense.cpp index f86aa4a..b6a9af2 100644 --- a/src/Dense.cpp +++ b/src/Dense.cpp @@ -4,7 +4,7 @@ namespace tk { namespace dnn { -Dense::Dense(Network *net, int out_ch, const char* fname_weights) : +Dense::Dense(Network *net, int out_ch, std::string fname_weights) : LayerWgs(net, net->getOutputDim().tot(), out_ch, 1, 1, 1, fname_weights) { output_dim.n = 1; diff --git a/src/LayerWgs.cpp b/src/LayerWgs.cpp index d8bb881..f27da0f 100644 --- a/src/LayerWgs.cpp +++ b/src/LayerWgs.cpp @@ -8,7 +8,7 @@ namespace tk { namespace dnn { LayerWgs::LayerWgs(Network *net, int inputs, int outputs, int kh, int kw, int kl, - const char* fname_weights, bool batchnorm) : Layer(net) { + std::string fname_weights, bool batchnorm) : Layer(net) { this->inputs = inputs; this->outputs = outputs; diff --git a/src/Region.cpp b/src/Region.cpp index 56010dd..1b52375 100644 --- a/src/Region.cpp +++ b/src/Region.cpp @@ -66,7 +66,7 @@ dnnType* Region::infer(dataDim_t &dim, dnnType* srcData) { /* Intepret class */ RegionInterpret::RegionInterpret(dataDim_t input_dim, dataDim_t output_dim, - int classes, int coords, int num, float thresh, const char* fname_weights) { + int classes, int coords, int num, float thresh, std::string fname_weights) { this->input_dim = input_dim; this->output_dim = output_dim; diff --git a/src/Yolo.cpp b/src/Yolo.cpp index 0dcea7e..f2ec53c 100644 --- a/src/Yolo.cpp +++ b/src/Yolo.cpp @@ -11,14 +11,14 @@ namespace tk { namespace dnn { -Yolo::Yolo(Network *net, int classes, int num, const char* fname_weights) : +Yolo::Yolo(Network *net, int classes, int num, std::string fname_weights) : Layer(net) { this->classes = classes; this->num = num; // load anchors - if(fname_weights != nullptr) { + if(fname_weights != "") { int seek = 0; readBinaryFile(fname_weights, num, &mask_h, &mask_d, seek); seek += num; diff --git a/src/Yolo3Detection.cpp b/src/Yolo3Detection.cpp index e121503..ce9fd6a 100644 --- a/src/Yolo3Detection.cpp +++ b/src/Yolo3Detection.cpp @@ -32,7 +32,7 @@ bool Yolo3Detection::init(std::string tensor_path) { num = yRT->num; // make a yolo layer for interpret predictions - yolo[i] = new tk::dnn::Yolo(nullptr, classes, num, nullptr); // yolo without input and bias + yolo[i] = new tk::dnn::Yolo(nullptr, classes, num, ""); // yolo without input and bias yolo[i]->mask_h = new dnnType[num]; yolo[i]->bias_h = new dnnType[num*3*2]; memcpy(yolo[i]->mask_h, yRT->mask, sizeof(dnnType)*num); diff --git a/src/utils.cpp b/src/utils.cpp index 7955d15..e6f71f8 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -21,7 +21,7 @@ bool fileExist(const char *fname) { } -void readBinaryFile(const char* fname, int size, dnnType** data_h, dnnType** data_d, int seek) +void readBinaryFile(std::string fname, int size, dnnType** data_h, dnnType** data_d, int seek) { std::ifstream dataFile (fname, std::ios::in | std::ios::binary); std::stringstream error_s; diff --git a/tests/yolo3_berkeley/yolo3_berkeley.cpp b/tests/yolo3_berkeley/yolo3_berkeley.cpp index 3a69e32..43f5da5 100644 --- a/tests/yolo3_berkeley/yolo3_berkeley.cpp +++ b/tests/yolo3_berkeley/yolo3_berkeley.cpp @@ -1,295 +1,18 @@ #include +#include #include "tkdnn.h" -const char *input_bin = "../tests/yolo3_berkeley/layers/input.bin"; -const char *c0_bin = "../tests/yolo3_berkeley/layers/c0.bin"; -const char *c1_bin = "../tests/yolo3_berkeley/layers/c1.bin"; -const char *c2_bin = "../tests/yolo3_berkeley/layers/c2.bin"; -const char *c3_bin = "../tests/yolo3_berkeley/layers/c3.bin"; -const char *c5_bin = "../tests/yolo3_berkeley/layers/c5.bin"; -const char *c6_bin = "../tests/yolo3_berkeley/layers/c6.bin"; -const char *c7_bin = "../tests/yolo3_berkeley/layers/c7.bin"; -const char *c9_bin = "../tests/yolo3_berkeley/layers/c9.bin"; -const char *c10_bin = "../tests/yolo3_berkeley/layers/c10.bin"; -const char *c12_bin = "../tests/yolo3_berkeley/layers/c12.bin"; -const char *c13_bin = "../tests/yolo3_berkeley/layers/c13.bin"; -const char *c14_bin = "../tests/yolo3_berkeley/layers/c14.bin"; -const char *c16_bin = "../tests/yolo3_berkeley/layers/c16.bin"; -const char *c17_bin = "../tests/yolo3_berkeley/layers/c17.bin"; -const char *c19_bin = "../tests/yolo3_berkeley/layers/c19.bin"; -const char *c20_bin = "../tests/yolo3_berkeley/layers/c20.bin"; -const char *c22_bin = "../tests/yolo3_berkeley/layers/c22.bin"; -const char *c23_bin = "../tests/yolo3_berkeley/layers/c23.bin"; -const char *c25_bin = "../tests/yolo3_berkeley/layers/c25.bin"; -const char *c26_bin = "../tests/yolo3_berkeley/layers/c26.bin"; -const char *c28_bin = "../tests/yolo3_berkeley/layers/c28.bin"; -const char *c29_bin = "../tests/yolo3_berkeley/layers/c29.bin"; -const char *c31_bin = "../tests/yolo3_berkeley/layers/c31.bin"; -const char *c32_bin = "../tests/yolo3_berkeley/layers/c32.bin"; -const char *c34_bin = "../tests/yolo3_berkeley/layers/c34.bin"; -const char *c35_bin = "../tests/yolo3_berkeley/layers/c35.bin"; -const char *c37_bin = "../tests/yolo3_berkeley/layers/c37.bin"; -const char *c38_bin = "../tests/yolo3_berkeley/layers/c38.bin"; -const char *c39_bin = "../tests/yolo3_berkeley/layers/c39.bin"; -const char *c41_bin = "../tests/yolo3_berkeley/layers/c41.bin"; -const char *c42_bin = "../tests/yolo3_berkeley/layers/c42.bin"; -const char *c44_bin = "../tests/yolo3_berkeley/layers/c44.bin"; -const char *c45_bin = "../tests/yolo3_berkeley/layers/c45.bin"; -const char *c47_bin = "../tests/yolo3_berkeley/layers/c47.bin"; -const char *c48_bin = "../tests/yolo3_berkeley/layers/c48.bin"; -const char *c50_bin = "../tests/yolo3_berkeley/layers/c50.bin"; -const char *c51_bin = "../tests/yolo3_berkeley/layers/c51.bin"; -const char *c53_bin = "../tests/yolo3_berkeley/layers/c53.bin"; -const char *c54_bin = "../tests/yolo3_berkeley/layers/c54.bin"; -const char *c56_bin = "../tests/yolo3_berkeley/layers/c56.bin"; -const char *c57_bin = "../tests/yolo3_berkeley/layers/c57.bin"; -const char *c59_bin = "../tests/yolo3_berkeley/layers/c59.bin"; -const char *c60_bin = "../tests/yolo3_berkeley/layers/c60.bin"; -const char *c62_bin = "../tests/yolo3_berkeley/layers/c62.bin"; -const char *c63_bin = "../tests/yolo3_berkeley/layers/c63.bin"; -const char *c64_bin = "../tests/yolo3_berkeley/layers/c64.bin"; -const char *c66_bin = "../tests/yolo3_berkeley/layers/c66.bin"; -const char *c67_bin = "../tests/yolo3_berkeley/layers/c67.bin"; -const char *c69_bin = "../tests/yolo3_berkeley/layers/c69.bin"; -const char *c70_bin = "../tests/yolo3_berkeley/layers/c70.bin"; -const char *c72_bin = "../tests/yolo3_berkeley/layers/c72.bin"; -const char *c73_bin = "../tests/yolo3_berkeley/layers/c73.bin"; -const char *c75_bin = "../tests/yolo3_berkeley/layers/c75.bin"; -const char *c76_bin = "../tests/yolo3_berkeley/layers/c76.bin"; -const char *c77_bin = "../tests/yolo3_berkeley/layers/c77.bin"; -const char *c78_bin = "../tests/yolo3_berkeley/layers/c78.bin"; -const char *c79_bin = "../tests/yolo3_berkeley/layers/c79.bin"; -const char *c80_bin = "../tests/yolo3_berkeley/layers/c80.bin"; -const char *c81_bin = "../tests/yolo3_berkeley/layers/c81.bin"; -const char *g82_bin = "../tests/yolo3_berkeley/layers/g82.bin"; -const char *c84_bin = "../tests/yolo3_berkeley/layers/c84.bin"; -const char *c87_bin = "../tests/yolo3_berkeley/layers/c87.bin"; -const char *c88_bin = "../tests/yolo3_berkeley/layers/c88.bin"; -const char *c89_bin = "../tests/yolo3_berkeley/layers/c89.bin"; -const char *c90_bin = "../tests/yolo3_berkeley/layers/c90.bin"; -const char *c91_bin = "../tests/yolo3_berkeley/layers/c91.bin"; -const char *c92_bin = "../tests/yolo3_berkeley/layers/c92.bin"; -const char *c93_bin = "../tests/yolo3_berkeley/layers/c93.bin"; -const char *g94_bin = "../tests/yolo3_berkeley/layers/g94.bin"; -const char *c96_bin = "../tests/yolo3_berkeley/layers/c96.bin"; -const char *c99_bin = "../tests/yolo3_berkeley/layers/c99.bin"; -const char *c100_bin = "../tests/yolo3_berkeley/layers/c100.bin"; -const char *c101_bin = "../tests/yolo3_berkeley/layers/c101.bin"; -const char *c102_bin = "../tests/yolo3_berkeley/layers/c102.bin"; -const char *c103_bin = "../tests/yolo3_berkeley/layers/c103.bin"; -const char *c104_bin = "../tests/yolo3_berkeley/layers/c104.bin"; -const char *c105_bin = "../tests/yolo3_berkeley/layers/c105.bin"; -const char *g106_bin = "../tests/yolo3_berkeley/layers/g106.bin"; -const char *output_bins[3] = { - "../tests/yolo3_berkeley/debug/layer82_out.bin", - "../tests/yolo3_berkeley/debug/layer94_out.bin", - "../tests/yolo3_berkeley/debug/layer106_out.bin" -}; - int main() { // Network layout tk::dnn::dataDim_t dim(1, 3, 320, 544, 1); tk::dnn::Network net(dim); - tk::dnn::Conv2d c0 (&net, 32, 3, 3, 1, 1, 1, 1, c0_bin, true); - tk::dnn::Activation a0 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c1 (&net, 64, 3, 3, 2, 2, 1, 1, c1_bin, true); - tk::dnn::Activation a1 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c2 (&net, 32, 1, 1, 1, 1, 0, 0, c2_bin, true); - tk::dnn::Activation a2 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c3 (&net, 64, 3, 3, 1, 1, 1, 1, c3_bin, true); - tk::dnn::Activation a3 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s4 (&net, &a1); - tk::dnn::Conv2d c5 (&net, 128, 3, 3, 2, 2, 1, 1, c5_bin, true); - tk::dnn::Activation a5 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c6 (&net, 64, 1, 1, 1, 1, 0, 0, c6_bin, true); - tk::dnn::Activation a6 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c7 (&net, 128, 3, 3, 1, 1, 1, 1, c7_bin, true); - tk::dnn::Activation a7 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s8 (&net, &a5); - tk::dnn::Conv2d c9 (&net, 64, 1, 1, 1, 1, 0, 0, c9_bin, true); - tk::dnn::Activation a9 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c10 (&net, 128, 3, 3, 1, 1, 1, 1, c10_bin, true); - tk::dnn::Activation a10 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s11 (&net, &s8); - - tk::dnn::Conv2d c12 (&net, 256, 3, 3, 2, 2, 1, 1, c12_bin, true); - tk::dnn::Activation a12 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c13 (&net, 128, 1, 1, 1, 1, 0, 0, c13_bin, true); - tk::dnn::Activation a13 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c14 (&net, 256, 3, 3, 1, 1, 1, 1, c14_bin, true); - tk::dnn::Activation a14 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s15 (&net, &a12); - - tk::dnn::Conv2d c16 (&net, 128, 1, 1, 1, 1, 0, 0, c16_bin, true); - tk::dnn::Activation a16 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c17 (&net, 256, 3, 3, 1, 1, 1, 1, c17_bin, true); - tk::dnn::Activation a17 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s18 (&net, &s15); - tk::dnn::Conv2d c19 (&net, 128, 1, 1, 1, 1, 0, 0, c19_bin, true); - tk::dnn::Activation a19 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c20 (&net, 256, 3, 3, 1, 1, 1, 1, c20_bin, true); - tk::dnn::Activation a20 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s21 (&net, &s18); - tk::dnn::Conv2d c22 (&net, 128, 1, 1, 1, 1, 0, 0, c22_bin, true); - tk::dnn::Activation a22 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c23 (&net, 256, 3, 3, 1, 1, 1, 1, c23_bin, true); - tk::dnn::Activation a23 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s24 (&net, &s21); - tk::dnn::Conv2d c25 (&net, 128, 1, 1, 1, 1, 0, 0, c25_bin, true); - tk::dnn::Activation a25 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c26 (&net, 256, 3, 3, 1, 1, 1, 1, c26_bin, true); - tk::dnn::Activation a26 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s27 (&net, &s24); - tk::dnn::Conv2d c28 (&net, 128, 1, 1, 1, 1, 0, 0, c28_bin, true); - tk::dnn::Activation a28 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c29 (&net, 256, 3, 3, 1, 1, 1, 1, c29_bin, true); - tk::dnn::Activation a29 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s30 (&net, &s27); - tk::dnn::Conv2d c31 (&net, 128, 1, 1, 1, 1, 0, 0, c31_bin, true); - tk::dnn::Activation a31 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c32 (&net, 256, 3, 3, 1, 1, 1, 1, c32_bin, true); - tk::dnn::Activation a32 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s33 (&net, &s30); - tk::dnn::Conv2d c34 (&net, 128, 1, 1, 1, 1, 0, 0, c34_bin, true); - tk::dnn::Activation a34 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c35 (&net, 256, 3, 3, 1, 1, 1, 1, c35_bin, true); - tk::dnn::Activation a35 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s36 (&net, &s33); - - tk::dnn::Conv2d c37 (&net, 512, 3, 3, 2, 2, 1, 1, c37_bin, true); - tk::dnn::Activation a37 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c38 (&net, 256, 1, 1, 1, 1, 0, 0, c38_bin, true); - tk::dnn::Activation a38 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c39 (&net, 512, 3, 3, 1, 1, 1, 1, c39_bin, true); - tk::dnn::Activation a39 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s40 (&net, &a37); - - tk::dnn::Conv2d c41 (&net, 256, 1, 1, 1, 1, 0, 0, c41_bin, true); - tk::dnn::Activation a41 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c42 (&net, 512, 3, 3, 1, 1, 1, 1, c42_bin, true); - tk::dnn::Activation a42 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s43 (&net, &s40); - tk::dnn::Conv2d c44 (&net, 256, 1, 1, 1, 1, 0, 0, c44_bin, true); - tk::dnn::Activation a44 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c45 (&net, 512, 3, 3, 1, 1, 1, 1, c45_bin, true); - tk::dnn::Activation a45 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s46 (&net, &s43); - tk::dnn::Conv2d c47 (&net, 256, 1, 1, 1, 1, 0, 0, c47_bin, true); - tk::dnn::Activation a47 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c48 (&net, 512, 3, 3, 1, 1, 1, 1, c48_bin, true); - tk::dnn::Activation a48 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s49 (&net, &s46); - tk::dnn::Conv2d c50 (&net, 256, 1, 1, 1, 1, 0, 0, c50_bin, true); - tk::dnn::Activation a50 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c51 (&net, 512, 3, 3, 1, 1, 1, 1, c51_bin, true); - tk::dnn::Activation a51 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s52 (&net, &s49); - tk::dnn::Conv2d c53 (&net, 256, 1, 1, 1, 1, 0, 0, c53_bin, true); - tk::dnn::Activation a53 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c54 (&net, 512, 3, 3, 1, 1, 1, 1, c54_bin, true); - tk::dnn::Activation a54 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s55 (&net, &s52); - tk::dnn::Conv2d c56 (&net, 256, 1, 1, 1, 1, 0, 0, c56_bin, true); - tk::dnn::Activation a56 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c57 (&net, 512, 3, 3, 1, 1, 1, 1, c57_bin, true); - tk::dnn::Activation a57 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s58 (&net, &s55); - tk::dnn::Conv2d c59 (&net, 256, 1, 1, 1, 1, 0, 0, c59_bin, true); - tk::dnn::Activation a59 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c60 (&net, 512, 3, 3, 1, 1, 1, 1, c60_bin, true); - tk::dnn::Activation a60 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s61 (&net, &s58); - - tk::dnn::Conv2d c62 (&net,1024, 3, 3, 2, 2, 1, 1, c62_bin, true); - tk::dnn::Activation a62 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c63 (&net, 512, 1, 1, 1, 1, 0, 0, c63_bin, true); - tk::dnn::Activation a63 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c64 (&net,1024, 3, 3, 1, 1, 1, 1, c64_bin, true); - tk::dnn::Activation a64 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s65 (&net, &a62); - - tk::dnn::Conv2d c66 (&net, 512, 1, 1, 1, 1, 0, 0, c66_bin, true); - tk::dnn::Activation a66 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c67 (&net,1024, 3, 3, 1, 1, 1, 1, c67_bin, true); - tk::dnn::Activation a67 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s68 (&net, &s65); - - tk::dnn::Conv2d c69 (&net, 512, 1, 1, 1, 1, 0, 0, c69_bin, true); - tk::dnn::Activation a69 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c70 (&net,1024, 3, 3, 1, 1, 1, 1, c70_bin, true); - tk::dnn::Activation a70 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s71 (&net, &s68); - - tk::dnn::Conv2d c72 (&net, 512, 1, 1, 1, 1, 0, 0, c72_bin, true); - tk::dnn::Activation a72 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c73 (&net,1024, 3, 3, 1, 1, 1, 1, c73_bin, true); - tk::dnn::Activation a73 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Shortcut s74 (&net, &s71); - - tk::dnn::Conv2d c75 (&net, 512, 1, 1, 1, 1, 0, 0, c75_bin, true); - tk::dnn::Activation a75 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c76 (&net,1024, 3, 3, 1, 1, 1, 1, c76_bin, true); - tk::dnn::Activation a76 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c77 (&net, 512, 1, 1, 1, 1, 0, 0, c77_bin, true); - tk::dnn::Activation a77 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c78 (&net,1024, 3, 3, 1, 1, 1, 1, c78_bin, true); - tk::dnn::Activation a78 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c79 (&net, 512, 1, 1, 1, 1, 0, 0, c79_bin, true); - tk::dnn::Activation a79 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c80 (&net,1024, 3, 3, 1, 1, 1, 1, c80_bin, true); - tk::dnn::Activation a80 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c81 (&net, 45, 1, 1, 1, 1, 0, 0, c81_bin, false); - tk::dnn::Yolo yolo0 (&net, 10, 3, g82_bin); - - tk::dnn::Layer *m83_layers[1] = { &a79 }; - tk::dnn::Route m83 (&net, m83_layers, 1); - tk::dnn::Conv2d c84 (&net, 256, 1, 1, 1, 1, 0, 0, c84_bin, true); - tk::dnn::Activation a84 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Upsample u85 (&net, 2); - - tk::dnn::Layer *m86_layers[2] = { &u85, &s61 }; - tk::dnn::Route m86 (&net, m86_layers, 2); - tk::dnn::Conv2d c87 (&net, 256, 1, 1, 1, 1, 0, 0, c87_bin, true); - tk::dnn::Activation a87 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c88 (&net, 512, 3, 3, 1, 1, 1, 1, c88_bin, true); - tk::dnn::Activation a88 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c89 (&net, 256, 1, 1, 1, 1, 0, 0, c89_bin, true); - tk::dnn::Activation a89 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c90 (&net, 512, 3, 3, 1, 1, 1, 1, c90_bin, true); - tk::dnn::Activation a90 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c91 (&net, 256, 1, 1, 1, 1, 0, 0, c91_bin, true); - tk::dnn::Activation a91 (&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Conv2d c92 (&net, 512, 3, 3, 1, 1, 1, 1, c92_bin, true); - tk::dnn::Activation a92 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c93 (&net, 45, 1, 1, 1, 1, 0, 0, c93_bin, false); - tk::dnn::Yolo yolo1 (&net, 10, 3, g94_bin); - - tk::dnn::Layer *m95_layers[1] = { &a91 }; - tk::dnn::Route m95 (&net, m95_layers, 1); - tk::dnn::Conv2d c96 (&net, 128, 1, 1, 1, 1, 0, 0, c96_bin, true); - tk::dnn::Activation a96 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Upsample u97 (&net, 2); - - tk::dnn::Layer *m98_layers[2] = { &u97, &s36 }; - tk::dnn::Route m98 (&net, m98_layers, 2); - tk::dnn::Conv2d c99 (&net, 128, 1, 1, 1, 1, 0, 0, c99_bin, true); - tk::dnn::Activation a99 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c100 (&net, 256, 3, 3, 1, 1, 1, 1, c100_bin, true); - tk::dnn::Activation a100 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c101 (&net, 128, 1, 1, 1, 1, 0, 0, c101_bin, true); - tk::dnn::Activation a101 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c102 (&net, 256, 3, 3, 1, 1, 1, 1, c102_bin, true); - tk::dnn::Activation a102 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c103 (&net, 128, 1, 1, 1, 1, 0, 0, c103_bin, true); - tk::dnn::Activation a103 (&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Conv2d c104 (&net, 256, 3, 3, 1, 1, 1, 1, c104_bin, true); - tk::dnn::Activation a104 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c105 (&net, 45, 1, 1, 1, 1, 0, 0, c105_bin, false); - tk::dnn::Yolo yolo2 (&net, 10, 3, g106_bin); + // create yolo3 model + std::string bin_path = "../tests/yolo3_berkeley"; + int classes = 10; + tk::dnn::Yolo *yolo [3]; + #include "models/Yolo3.h" // Load input dnnType *data; @@ -304,9 +27,7 @@ int main() { // the network have 3 outputs tk::dnn::dataDim_t out_dim[3]; - out_dim[0] = yolo0.output_dim; - out_dim[1] = yolo1.output_dim; - out_dim[2] = yolo2.output_dim; + 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 @@ -317,18 +38,13 @@ int main() { TIMER_STOP dim1.print(); } - cudnn_out[0] = yolo0.dstData; - cudnn_out[1] = yolo1.dstData; - cudnn_out[2] = yolo2.dstData; - + for(int i=0; i<3; i++) cudnn_out[i] = yolo[i]->dstData; + printCenteredTitle(" compute detections ", '=', 30); TIMER_START int ndets = 0; - int classes = yolo0.classes; tk::dnn::Yolo::detection *dets = tk::dnn::Yolo::allocateDetections(tk::dnn::Yolo::MAX_DETECTIONS, classes); - yolo0.computeDetections(dets, ndets, net.input_dim.w, net.input_dim.h, 0.5); - yolo1.computeDetections(dets, ndets, net.input_dim.w, net.input_dim.h, 0.5); - yolo2.computeDetections(dets, ndets, net.input_dim.w, net.input_dim.h, 0.5); + 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; jcomputeDetections(dets, ndets, net.input_dim.w, net.input_dim.h, 0.5); tk::dnn::Yolo::mergeDetections(dets, ndets, classes); for(int j=0; jdstData; + + 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<