Fix monodepth2, add demoDepth:
- Fix monodepth2 network, now works with both cuDNN and tensorRT - Substitute cuDNN ELU with tkDNN one - add DepthNN class - add demoDepth demo, now only works with monodepth2 net Signed-off-by: Micaela Verucchi <micaelaverucchi@gmail.com> Francesco Gatti <gattifrancesco@hotmail.it>
This commit is contained in:
@@ -279,6 +279,8 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Layer *l) {
|
||||
return convert_layer(input, (Padding*) l);
|
||||
if(type == LAYER_BATCHNORM)
|
||||
return convert_layer(input,(BatchNorm*) l);
|
||||
if(type == LAYER_MULADD)
|
||||
return convert_layer(input,(MulAdd*) l);
|
||||
|
||||
std::cout<<l->getLayerName()<<"\n";
|
||||
FatalError("Layer not implemented in tensorRT");
|
||||
@@ -441,6 +443,80 @@ ILayer* NetworkRT::convert_layer(ITensor *input,BatchNorm *l){
|
||||
|
||||
}
|
||||
|
||||
ILayer* NetworkRT::convert_layer(ITensor *input,MulAdd *l){
|
||||
|
||||
void *power_b, *shift_b, *scales_b;
|
||||
int size = l->input_dim.tot();
|
||||
|
||||
power_b = new dnnType[size];
|
||||
shift_b = new dnnType[size];
|
||||
scales_b = new dnnType[size];
|
||||
|
||||
for(int i=0; i<size; i++) {
|
||||
((dnnType*) power_b)[i] = 1.0;
|
||||
((dnnType*) shift_b)[i] = l->add;
|
||||
((dnnType*) scales_b)[i] = l->mul;
|
||||
}
|
||||
|
||||
if(dtRT == DataType::kHALF) {
|
||||
|
||||
__half *power16_h = nullptr, *power16_d = nullptr;
|
||||
__half *scales16_h = nullptr, *scales16_d = nullptr;
|
||||
__half *shift16_h = nullptr, *shift16_d = nullptr;
|
||||
|
||||
dnnType * power_d = nullptr;
|
||||
dnnType * scales_d = nullptr;
|
||||
dnnType * shift_d = nullptr;
|
||||
|
||||
cudaMalloc(&power_d, size*sizeof(dnnType));
|
||||
cudaMemcpy(power_d, power_b, size*sizeof(dnnType), cudaMemcpyHostToDevice);
|
||||
|
||||
cudaMalloc(&shift_d, size*sizeof(dnnType));
|
||||
cudaMemcpy(shift_d, shift_b, size*sizeof(dnnType), cudaMemcpyHostToDevice);
|
||||
|
||||
cudaMalloc(&scales_d, size*sizeof(dnnType));
|
||||
cudaMemcpy(scales_d, scales_b, size*sizeof(dnnType), cudaMemcpyHostToDevice);
|
||||
|
||||
//convert to fp16
|
||||
power16_h = new __half[size];
|
||||
cudaMalloc(&power16_d, size*sizeof(__half));
|
||||
float2half(power_d, power16_d, size);
|
||||
cudaMemcpy(power16_h, power16_d, size*sizeof(__half), cudaMemcpyDeviceToHost);
|
||||
|
||||
shift16_h = new __half[size];
|
||||
cudaMalloc(&shift16_d, size*sizeof(__half));
|
||||
float2half(shift_d, shift16_d, size);
|
||||
cudaMemcpy(shift16_h, shift16_d, size*sizeof(__half), cudaMemcpyDeviceToHost);
|
||||
|
||||
scales16_h = new __half[size];
|
||||
cudaMalloc(&scales16_d, size*sizeof(__half));
|
||||
float2half(scales_d, scales16_d, size);
|
||||
cudaMemcpy(scales16_h, scales16_d, size*sizeof(__half), cudaMemcpyDeviceToHost);
|
||||
|
||||
power_b = power16_h;
|
||||
shift_b = shift16_h;
|
||||
scales_b = scales16_h;
|
||||
|
||||
|
||||
cudaFree(power16_d);
|
||||
cudaFree(shift16_d);
|
||||
cudaFree(scales16_d);
|
||||
|
||||
cudaFree(power_d);
|
||||
cudaFree(shift_d);
|
||||
cudaFree(scales_d);
|
||||
}
|
||||
|
||||
Weights power{dtRT, power_b, size};
|
||||
Weights shift{dtRT, shift_b, size};
|
||||
Weights scale{dtRT, scales_b, size};
|
||||
IScaleLayer *lRT = networkRT->addScale(*input, ScaleMode::kELEMENTWISE,
|
||||
shift, scale, power);
|
||||
checkNULL(lRT);
|
||||
return lRT;
|
||||
}
|
||||
|
||||
|
||||
ILayer* NetworkRT::convert_layer(ITensor *input, Pooling *l) {
|
||||
// std::cout<<"convert Pooling\n";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user