dects dont works
This commit is contained in:
+2
-1
@@ -361,9 +361,10 @@ public:
|
|||||||
dnnType *bias_h, *bias_d; //anchors
|
dnnType *bias_h, *bias_d; //anchors
|
||||||
|
|
||||||
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData);
|
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData);
|
||||||
int computeDetections(int w, int h, float thresh);
|
int computeDetections(int w, int h, int netw, int neth, float thresh);
|
||||||
|
|
||||||
const int MAX_DETECTIONS = 256;
|
const int MAX_DETECTIONS = 256;
|
||||||
|
dnnType *predictions;
|
||||||
Yolo::detection *dets;
|
Yolo::detection *dets;
|
||||||
int detected;
|
int detected;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ namespace tk { namespace dnn {
|
|||||||
Layer::Layer(Network *net) {
|
Layer::Layer(Network *net) {
|
||||||
|
|
||||||
this->net = net;
|
this->net = net;
|
||||||
|
|
||||||
|
if(net != nullptr) {
|
||||||
this->input_dim = net->getOutputDim();
|
this->input_dim = net->getOutputDim();
|
||||||
this->output_dim = input_dim;
|
this->output_dim = input_dim;
|
||||||
|
|
||||||
@@ -16,6 +18,7 @@ Layer::Layer(Network *net) {
|
|||||||
if(!net->addLayer(this))
|
if(!net->addLayer(this))
|
||||||
FatalError("Net reached max number of layers");
|
FatalError("Net reached max number of layers");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Layer::~Layer() {
|
Layer::~Layer() {
|
||||||
|
|
||||||
|
|||||||
+14
-7
@@ -29,9 +29,12 @@ Yolo::Yolo(Network *net, int classes, int num, const char* fname_weights) :
|
|||||||
|
|
||||||
// load anchors
|
// load anchors
|
||||||
int seek = 0;
|
int seek = 0;
|
||||||
readBinaryFile(fname_weights, num, &mask_h, &mask_d);
|
readBinaryFile(fname_weights, num, &mask_h, &mask_d, seek);
|
||||||
seek += num;
|
seek += num;
|
||||||
readBinaryFile(fname_weights, 3*num, &bias_h, &bias_d);
|
readBinaryFile(fname_weights, 3*num*2, &bias_h, &bias_d, seek);
|
||||||
|
|
||||||
|
printDeviceVector(num, mask_h, false);
|
||||||
|
printDeviceVector(3*num*2, bias_h, false);
|
||||||
|
|
||||||
// same
|
// same
|
||||||
output_dim.n = input_dim.n;
|
output_dim.n = input_dim.n;
|
||||||
@@ -40,7 +43,12 @@ Yolo::Yolo(Network *net, int classes, int num, const char* fname_weights) :
|
|||||||
output_dim.w = input_dim.w;
|
output_dim.w = input_dim.w;
|
||||||
output_dim.l = input_dim.l;
|
output_dim.l = input_dim.l;
|
||||||
|
|
||||||
|
std::cout<<"YOLO INPUT: ";
|
||||||
|
input_dim.print();
|
||||||
|
std::cout<<"\n";
|
||||||
|
|
||||||
checkCuda( cudaMalloc(&dstData, output_dim.tot()*sizeof(dnnType)) );
|
checkCuda( cudaMalloc(&dstData, output_dim.tot()*sizeof(dnnType)) );
|
||||||
|
predictions = nullptr;
|
||||||
|
|
||||||
dets = make_network_boxes(MAX_DETECTIONS, classes);
|
dets = make_network_boxes(MAX_DETECTIONS, classes);
|
||||||
detected = 0;
|
detected = 0;
|
||||||
@@ -114,17 +122,16 @@ dnnType* Yolo::infer(dataDim_t &dim, dnnType* srcData) {
|
|||||||
return dstData;
|
return dstData;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Yolo::computeDetections(int w, int h, float thresh) {
|
int Yolo::computeDetections(int w, int h, int netw, int neth, float thresh) {
|
||||||
|
|
||||||
dnnType *predictions = new dnnType[output_dim.tot()];
|
if(predictions == nullptr)
|
||||||
|
predictions = new dnnType[output_dim.tot()];
|
||||||
checkCuda( cudaMemcpy(predictions, dstData, output_dim.tot()*sizeof(dnnType), cudaMemcpyDeviceToHost));
|
checkCuda( cudaMemcpy(predictions, dstData, output_dim.tot()*sizeof(dnnType), cudaMemcpyDeviceToHost));
|
||||||
|
|
||||||
int relative = 1;
|
int relative = 0;
|
||||||
|
|
||||||
int lw = output_dim.w;
|
int lw = output_dim.w;
|
||||||
int lh = output_dim.h;
|
int lh = output_dim.h;
|
||||||
int netw = net->input_dim.w;
|
|
||||||
int neth = net->input_dim.h;
|
|
||||||
|
|
||||||
if (output_dim.n == 2) {
|
if (output_dim.n == 2) {
|
||||||
FatalError("BATCH of 2 not supported");
|
FatalError("BATCH of 2 not supported");
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ const char *c78_bin = "../tests/yolo3_berkeley/layers/c78.bin";
|
|||||||
const char *c79_bin = "../tests/yolo3_berkeley/layers/c79.bin";
|
const char *c79_bin = "../tests/yolo3_berkeley/layers/c79.bin";
|
||||||
const char *c80_bin = "../tests/yolo3_berkeley/layers/c80.bin";
|
const char *c80_bin = "../tests/yolo3_berkeley/layers/c80.bin";
|
||||||
const char *c81_bin = "../tests/yolo3_berkeley/layers/c81.bin";
|
const char *c81_bin = "../tests/yolo3_berkeley/layers/c81.bin";
|
||||||
const char *c82_bin = "../tests/yolo3_berkeley/layers/g82.bin";
|
const char *g82_bin = "../tests/yolo3_berkeley/layers/g82.bin";
|
||||||
const char *c84_bin = "../tests/yolo3_berkeley/layers/c84.bin";
|
const char *c84_bin = "../tests/yolo3_berkeley/layers/c84.bin";
|
||||||
const char *c87_bin = "../tests/yolo3_berkeley/layers/c87.bin";
|
const char *c87_bin = "../tests/yolo3_berkeley/layers/c87.bin";
|
||||||
const char *c88_bin = "../tests/yolo3_berkeley/layers/c88.bin";
|
const char *c88_bin = "../tests/yolo3_berkeley/layers/c88.bin";
|
||||||
@@ -70,7 +70,7 @@ const char *c90_bin = "../tests/yolo3_berkeley/layers/c90.bin";
|
|||||||
const char *c91_bin = "../tests/yolo3_berkeley/layers/c91.bin";
|
const char *c91_bin = "../tests/yolo3_berkeley/layers/c91.bin";
|
||||||
const char *c92_bin = "../tests/yolo3_berkeley/layers/c92.bin";
|
const char *c92_bin = "../tests/yolo3_berkeley/layers/c92.bin";
|
||||||
const char *c93_bin = "../tests/yolo3_berkeley/layers/c93.bin";
|
const char *c93_bin = "../tests/yolo3_berkeley/layers/c93.bin";
|
||||||
const char *c94_bin = "../tests/yolo3_berkeley/layers/g94.bin";
|
const char *g94_bin = "../tests/yolo3_berkeley/layers/g94.bin";
|
||||||
const char *c96_bin = "../tests/yolo3_berkeley/layers/c96.bin";
|
const char *c96_bin = "../tests/yolo3_berkeley/layers/c96.bin";
|
||||||
const char *c99_bin = "../tests/yolo3_berkeley/layers/c99.bin";
|
const char *c99_bin = "../tests/yolo3_berkeley/layers/c99.bin";
|
||||||
const char *c100_bin = "../tests/yolo3_berkeley/layers/c100.bin";
|
const char *c100_bin = "../tests/yolo3_berkeley/layers/c100.bin";
|
||||||
@@ -79,7 +79,7 @@ const char *c102_bin = "../tests/yolo3_berkeley/layers/c102.bin";
|
|||||||
const char *c103_bin = "../tests/yolo3_berkeley/layers/c103.bin";
|
const char *c103_bin = "../tests/yolo3_berkeley/layers/c103.bin";
|
||||||
const char *c104_bin = "../tests/yolo3_berkeley/layers/c104.bin";
|
const char *c104_bin = "../tests/yolo3_berkeley/layers/c104.bin";
|
||||||
const char *c105_bin = "../tests/yolo3_berkeley/layers/c105.bin";
|
const char *c105_bin = "../tests/yolo3_berkeley/layers/c105.bin";
|
||||||
const char *c106_bin = "../tests/yolo3_berkeley/layers/g106.bin";
|
const char *g106_bin = "../tests/yolo3_berkeley/layers/g106.bin";
|
||||||
const char *output_bins[3] = {
|
const char *output_bins[3] = {
|
||||||
"../tests/yolo3_berkeley/debug/layer82_out.bin",
|
"../tests/yolo3_berkeley/debug/layer82_out.bin",
|
||||||
"../tests/yolo3_berkeley/debug/layer94_out.bin",
|
"../tests/yolo3_berkeley/debug/layer94_out.bin",
|
||||||
@@ -241,7 +241,7 @@ int main() {
|
|||||||
tk::dnn::Conv2d c80 (&net,1024, 3, 3, 1, 1, 1, 1, c80_bin, true);
|
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::Activation a80 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||||
tk::dnn::Conv2d c81 (&net, 45, 1, 1, 1, 1, 0, 0, c81_bin, false);
|
tk::dnn::Conv2d c81 (&net, 45, 1, 1, 1, 1, 0, 0, c81_bin, false);
|
||||||
tk::dnn::Yolo yolo0 (&net, 10, 3, c84_bin);
|
tk::dnn::Yolo yolo0 (&net, 10, 3, g82_bin);
|
||||||
|
|
||||||
tk::dnn::Layer *m83_layers[1] = { &a79 };
|
tk::dnn::Layer *m83_layers[1] = { &a79 };
|
||||||
tk::dnn::Route m83 (&net, m83_layers, 1);
|
tk::dnn::Route m83 (&net, m83_layers, 1);
|
||||||
@@ -265,7 +265,7 @@ int main() {
|
|||||||
tk::dnn::Conv2d c92 (&net, 512, 3, 3, 1, 1, 1, 1, c92_bin, true);
|
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::Activation a92 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||||
tk::dnn::Conv2d c93 (&net, 45, 1, 1, 1, 1, 0, 0, c93_bin, false);
|
tk::dnn::Conv2d c93 (&net, 45, 1, 1, 1, 1, 0, 0, c93_bin, false);
|
||||||
tk::dnn::Yolo yolo1 (&net, 10, 3, c94_bin);
|
tk::dnn::Yolo yolo1 (&net, 10, 3, g94_bin);
|
||||||
|
|
||||||
tk::dnn::Layer *m95_layers[1] = { &a91 };
|
tk::dnn::Layer *m95_layers[1] = { &a91 };
|
||||||
tk::dnn::Route m95 (&net, m95_layers, 1);
|
tk::dnn::Route m95 (&net, m95_layers, 1);
|
||||||
@@ -289,7 +289,7 @@ int main() {
|
|||||||
tk::dnn::Conv2d c104 (&net, 256, 3, 3, 1, 1, 1, 1, c104_bin, true);
|
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::Activation a104 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||||
tk::dnn::Conv2d c105 (&net, 45, 1, 1, 1, 1, 0, 0, c105_bin, false);
|
tk::dnn::Conv2d c105 (&net, 45, 1, 1, 1, 1, 0, 0, c105_bin, false);
|
||||||
tk::dnn::Yolo yolo2 (&net, 10, 3, c106_bin);
|
tk::dnn::Yolo yolo2 (&net, 10, 3, g106_bin);
|
||||||
|
|
||||||
// Load input
|
// Load input
|
||||||
dnnType *data;
|
dnnType *data;
|
||||||
@@ -323,9 +323,25 @@ int main() {
|
|||||||
|
|
||||||
printCenteredTitle(" compute detections ", '=', 30);
|
printCenteredTitle(" compute detections ", '=', 30);
|
||||||
TIMER_START
|
TIMER_START
|
||||||
yolo0.computeDetections(640, 480, 0.5);
|
yolo0.computeDetections(dim.w, dim.h, net.input_dim.w, net.input_dim.h, 0.5);
|
||||||
yolo1.computeDetections(640, 480, 0.5);
|
yolo1.computeDetections(dim.w, dim.h, net.input_dim.w, net.input_dim.h, 0.5);
|
||||||
yolo2.computeDetections(640, 480, 0.5);
|
yolo2.computeDetections(dim.w, dim.h, net.input_dim.w, net.input_dim.h, 0.5);
|
||||||
|
|
||||||
|
for(int j=0; j<yolo1.detected; j++) {
|
||||||
|
tk::dnn::Yolo::box b = yolo1.dets[j].bbox;
|
||||||
|
int x0 = (b.x-b.w/2.);
|
||||||
|
int x1 = (b.x+b.w/2.);
|
||||||
|
int y0 = (b.y-b.h/2.);
|
||||||
|
int y1 = (b.y+b.h/2.);
|
||||||
|
|
||||||
|
int cl = 0;
|
||||||
|
for(int c = 0; c < yolo1.classes; ++c){
|
||||||
|
float prob = yolo1.dets[j].prob[c];
|
||||||
|
if(prob > 0)
|
||||||
|
cl = c;
|
||||||
|
}
|
||||||
|
std::cout<<cl<<": "<<x0<<" "<<y0<<" "<<x1<<" "<<y1<<"\n";
|
||||||
|
}
|
||||||
TIMER_STOP
|
TIMER_STOP
|
||||||
|
|
||||||
tk::dnn::dataDim_t dim2 = dim;
|
tk::dnn::dataDim_t dim2 = dim;
|
||||||
|
|||||||
Reference in New Issue
Block a user