Fix the Deformable convolution code sintax.
Signed-off-by: Davide Sapienza <sapienza.dav@gmail.com>
This commit is contained in:
+18
-22
@@ -10,10 +10,9 @@ namespace tk { namespace dnn {
|
||||
void DeformConv2d::initCUDNN() {
|
||||
|
||||
stat = cublasCreate(&handle);
|
||||
if (stat != CUBLAS_STATUS_SUCCESS) {
|
||||
printf ("CUBLAS initialization failed\n");
|
||||
return;
|
||||
}
|
||||
if (stat != CUBLAS_STATUS_SUCCESS)
|
||||
FatalError("CUBLAS initialization failed\n");
|
||||
|
||||
checkCUDNN( cudnnCreateTensorDescriptor(&biasTensorDesc) );
|
||||
checkCUDNN( cudnnSetTensor4dDescriptor(biasTensorDesc,
|
||||
net->tensorFormat, net->dataType,
|
||||
@@ -27,28 +26,27 @@ void DeformConv2d::initCUDNN() {
|
||||
const int dim_ones = preconv->input_dim.c * this->kernelH * this->kernelW * 1 * height_ones * width_ones;
|
||||
|
||||
int dst_dim = preconv->output_dim.tot();
|
||||
if (dst_dim % 3 != 0 )
|
||||
std::cout<<"take attention\n\n";
|
||||
if( dst_dim % 3 != 0 )
|
||||
FatalError("DeformConv2d: the Conv2d output is not divisible by three");
|
||||
chunk_dim = dst_dim/3;
|
||||
checkCuda( cudaMalloc(&offset, 2*chunk_dim*sizeof(dnnType)));
|
||||
checkCuda( cudaMalloc(&mask, chunk_dim*sizeof(dnnType)));
|
||||
|
||||
// kernel ones
|
||||
|
||||
checkCuda( cudaMalloc(&ones_d1, (height_ones*width_ones)*sizeof(dnnType)) );
|
||||
dnnType *aus1;
|
||||
checkCuda( cudaMallocHost(&aus1, (height_ones*width_ones)*sizeof(dnnType)) );
|
||||
dnnType *ones_h1;
|
||||
checkCuda( cudaMallocHost(&ones_h1, (height_ones*width_ones)*sizeof(dnnType)) );
|
||||
for(int i=0; i<height_ones*width_ones; i++)
|
||||
aus1[i]=1.0f;
|
||||
checkCuda( cudaMemcpy(ones_d1, aus1, (height_ones*width_ones)*sizeof(dnnType), cudaMemcpyHostToDevice) );
|
||||
checkCuda( cudaFreeHost(aus1) );
|
||||
ones_h1[i]=1.0f;
|
||||
checkCuda( cudaMemcpy(ones_d1, ones_h1, (height_ones*width_ones)*sizeof(dnnType), cudaMemcpyHostToDevice) );
|
||||
checkCuda( cudaFreeHost(ones_h1) );
|
||||
checkCuda( cudaMalloc(&ones_d2, dim_ones*sizeof(dnnType)) );
|
||||
dnnType *aus2;
|
||||
checkCuda( cudaMallocHost(&aus2, dim_ones*sizeof(dnnType)) );
|
||||
dnnType *ones_h2;
|
||||
checkCuda( cudaMallocHost(&ones_h2, dim_ones*sizeof(dnnType)) );
|
||||
for(int i=0; i<dim_ones; i++)
|
||||
aus2[i]=1.0f;
|
||||
checkCuda( cudaMemcpy(ones_d2, aus2, (dim_ones)*sizeof(dnnType), cudaMemcpyHostToDevice) );
|
||||
checkCuda( cudaFreeHost(aus2) );
|
||||
ones_h2[i]=1.0f;
|
||||
checkCuda( cudaMemcpy(ones_d2, ones_h2, (dim_ones)*sizeof(dnnType), cudaMemcpyHostToDevice) );
|
||||
checkCuda( cudaFreeHost(ones_h2) );
|
||||
checkCuda( cudaDeviceSynchronize() );
|
||||
}
|
||||
|
||||
@@ -57,8 +55,7 @@ DeformConv2d::DeformConv2d( Network *net, int out_ch, int deformable_group, int
|
||||
std::string d_fname_weights, std::string fname_weights, bool batchnorm) :
|
||||
|
||||
LayerWgs(net, net->getOutputDim().c, out_ch, kernelH, kernelW, 1,
|
||||
d_fname_weights, batchnorm, true){
|
||||
|
||||
d_fname_weights, batchnorm, true) {
|
||||
this->out_ch = out_ch;
|
||||
this->deformableGroup = deformable_group;
|
||||
this->kernelH = kernelH;
|
||||
@@ -81,7 +78,6 @@ DeformConv2d::DeformConv2d( Network *net, int out_ch, int deformable_group, int
|
||||
}
|
||||
|
||||
DeformConv2d::~DeformConv2d() {
|
||||
|
||||
checkCUDNN( cudnnDestroyTensorDescriptor(biasTensorDesc) );
|
||||
checkCuda( cudaFree(dstData) );
|
||||
checkCuda( cudaFree(ones_d1) );
|
||||
@@ -96,14 +92,14 @@ dnnType* DeformConv2d::infer(dataDim_t &dim, dnnType* srcData) {
|
||||
|
||||
// conv2d
|
||||
output_conv = preconv->infer(dim, srcData);
|
||||
// split conv2d outputs into offset to mask
|
||||
// split conv2d outputs into offset and mask
|
||||
checkCuda(cudaMemcpy(offset, output_conv, 2*chunk_dim*sizeof(dnnType), cudaMemcpyDeviceToDevice));
|
||||
checkCuda(cudaMemcpy(mask, output_conv + 2*chunk_dim, chunk_dim*sizeof(dnnType), cudaMemcpyDeviceToDevice));
|
||||
// kernel sigmoide
|
||||
activationSIGMOIDForward(mask, mask, chunk_dim);
|
||||
|
||||
// deformable convolution
|
||||
dcn_v2_cuda_forward(stat, handle,
|
||||
dcnV2CudaForward(stat, handle,
|
||||
srcData, this->data_d,
|
||||
this->bias2_d, ones_d1,
|
||||
offset, mask,
|
||||
|
||||
Reference in New Issue
Block a user