Skip to content

Commit

Permalink
add DLA, plugin for shortcut and leaky. new verison 0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
mive93 committed Jan 15, 2020
1 parent f3f5daf commit da4f246
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
7 changes: 7 additions & 0 deletions demo/demo/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ int main(int argc, char *argv[]) {
}

std::cout<<"detection end\n";


std::cout<<COL_GREENB<<"\n\nTime stats:\n";
std::cout<<"Min: "<<*std::min_element(yolo.stats.begin(), yolo.stats.end())<<" ms\n";
std::cout<<"Max: "<<*std::max_element(yolo.stats.begin(), yolo.stats.end())<<" ms\n";
double mean = 0; for(int i=0; i<yolo.stats.size(); i++) mean += yolo.stats[i]; mean /= yolo.stats.size();
std::cout<<"Avg: "<<mean<<" ms\n"<<COL_END;
return 0;
}

3 changes: 3 additions & 0 deletions include/tkDNN/Yolo3Detection.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class Yolo3Detection {
// this is filled with results
std::vector<tk::dnn::box> detected;

// keep track of inference times (ms)
std::vector<double> stats;

Yolo3Detection() {}

virtual ~Yolo3Detection() {}
Expand Down
2 changes: 1 addition & 1 deletion include/tkDNN/tkdnn.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
#include "Layer.h"
#include "NetworkRT.h"

#define TKDNN_VERSION 300
#define TKDNN_VERSION 400
22 changes: 18 additions & 4 deletions src/NetworkRT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ NetworkRT::NetworkRT(Network *net, const char *name) {
builderRT = createInferBuilder(loggerRT);
std::cout<<"Float16 support: "<<builderRT->platformHasFastFp16()<<"\n";
std::cout<<"Int8 support: "<<builderRT->platformHasFastInt8()<<"\n";
//std::cout<<"DLAs: "<<builderRT->getNbDLACores()<<"\n";
std::cout<<"DLAs: "<<builderRT->getNbDLACores()<<"\n";
networkRT = builderRT->createNetwork();

if(!fileExist(name)) {
Expand All @@ -51,15 +51,13 @@ NetworkRT::NetworkRT(Network *net, const char *name) {
dtRT = DataType::kHALF;
builderRT->setHalf2Mode(true);
}
/*
if(net->dla && builderRT->getNbDLACores() > 0) {
dtRT = DataType::kHALF;
builderRT->setFp16Mode(true);
builderRT->allowGPUFallback(true);
builderRT->setDefaultDeviceType(DeviceType::kDLA);
builderRT->setDLACore(0);
}
*/

//add input layer
ITensor *input = networkRT->addInput("data", DataType::kFLOAT,
Expand Down Expand Up @@ -276,10 +274,19 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Activation *l) {

if(l->act_mode == ACTIVATION_LEAKY) {
//std::cout<<"New plugin LEAKY\n";

/*
// plugin version
IPlugin *plugin = new ActivationLeakyRT();
IPluginLayer *lRT = networkRT->addPlugin(&input, 1, *plugin);
checkNULL(lRT);
return lRT;
*/

IActivationLayer *lRT = networkRT->addActivation(*input, ActivationType::kLEAKY_RELU);
lRT->setAlpha(0.1);
checkNULL(lRT);
return lRT;

} else if(l->act_mode == CUDNN_ACTIVATION_RELU) {
IActivationLayer *lRT = networkRT->addActivation(*input, ActivationType::kRELU);
Expand Down Expand Up @@ -340,14 +347,21 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Shortcut *l) {
//std::cout<<"convert Shortcut\n";

//std::cout<<"New plugin Shortcut\n";

ITensor *back_tens = tensors[l->backLayer];
/*
// plugin version
IPlugin *plugin = new ShortcutRT();

ITensor **inputs = new ITensor*[2];
inputs[0] = input;
inputs[1] = back_tens;
IPluginLayer *lRT = networkRT->addPlugin(inputs, 2, *plugin);
checkNULL(lRT);
*/

IElementWiseLayer *lRT = networkRT->addElementWise(*input, *back_tens, ElementWiseOperation::kSUM);
checkNULL(lRT);

return lRT;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Yolo3Detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ void Yolo3Detection::update(cv::Mat &imageORIG) {
netRT->infer(dim, input_d);
TIMER_STOP
dim.print();

stats.push_back(t_ns);
}

TIMER_START
Expand Down

0 comments on commit da4f246

Please sign in to comment.