@@ -49,6 +49,7 @@ nvinfer1::ITensor* TensorRTOpConverter::Reshape(TensorRTOpConverterParams* param
4949 auto layer = params->network ->addShuffle (*input);
5050 ICHECK (layer != nullptr );
5151 layer->setReshapeDimensions (VectorToTrtDims (new_shape));
52+ layer->setOutputType (0 , input->getType ());
5253 return layer->getOutput (0 );
5354}
5455
@@ -99,7 +100,8 @@ nvinfer1::ITensor* TensorRTOpConverter::CreateScalar(
99100 std::fill_n (dims.d , dims.nbDims , 1 );
100101 float * values = new float [1 ];
101102 values[0 ] = value;
102- nvinfer1::Weights weights{nvinfer1::DataType::kFLOAT , static_cast <void *>(values), 1 };
103+ const nvinfer1::DataType weight_type = params->inputs .at (1 ).weight .type ;
104+ nvinfer1::Weights weights{weight_type, static_cast <void *>(values), 1 };
103105 params->trt_weights ->push_back (weights);
104106 return params->network ->addConstant (dims, weights)->getOutput (0 );
105107}
@@ -252,7 +254,9 @@ class Conv1DOpConverter : public TensorRTOpConverter {
252254 input_tensor = shuffle_layer->getOutput (0 );
253255
254256 const auto kernel_size = nvinfer1::DimsHW (weight_shape[2 ], 1 );
255- nvinfer1::Weights bias{nvinfer1::DataType::kFLOAT , nullptr , 0 };
257+ const nvinfer1::DataType weight_type = params->inputs .at (1 ).weight .type ;
258+
259+ nvinfer1::Weights bias{weight_type, nullptr , 0 };
256260
257261 auto conv_layer = params->network ->addConvolution (*input_tensor, channels, kernel_size,
258262 params->inputs .at (1 ).weight , bias);
@@ -313,7 +317,8 @@ class Conv2DOpConverter : public TensorRTOpConverter {
313317#endif
314318
315319 const auto kernel_size = nvinfer1::DimsHW (weight_shape[2 ], weight_shape[3 ]);
316- nvinfer1::Weights bias{nvinfer1::DataType::kFLOAT , nullptr , 0 };
320+ const nvinfer1::DataType weight_type = params->inputs .at (1 ).weight .type ;
321+ nvinfer1::Weights bias{weight_type, nullptr , 0 };
317322 auto conv_layer = params->network ->addConvolution (*input_tensor, channels, kernel_size,
318323 params->inputs .at (1 ).weight , bias);
319324 ICHECK (conv_layer != nullptr );
@@ -361,7 +366,8 @@ class Conv3DOpConverter : public TensorRTOpConverter {
361366 const int num_outputs =
362367 std::stoi (params->node .GetAttr <std::vector<std::string>>(" channels" )[0 ]);
363368 const auto kernel_size = nvinfer1::Dims3 (weight_shape[2 ], weight_shape[3 ], weight_shape[4 ]);
364- nvinfer1::Weights bias{nvinfer1::DataType::kFLOAT , nullptr , 0 };
369+ const nvinfer1::DataType weight_type = params->inputs .at (1 ).weight .type ;
370+ nvinfer1::Weights bias{weight_type, nullptr , 0 };
365371 auto conv_layer = params->network ->addConvolutionNd (*input_tensor, num_outputs, kernel_size,
366372 params->inputs .at (1 ).weight , bias);
367373 ICHECK (conv_layer != nullptr );
@@ -404,7 +410,8 @@ class DenseOpConverter : public TensorRTOpConverter {
404410 // Weights are in KC format.
405411 ICHECK_EQ (params->inputs .at (1 ).weight_shape .size (), 2 );
406412 const int num_units = params->inputs .at (1 ).weight_shape [0 ];
407- nvinfer1::Weights bias{nvinfer1::DataType::kFLOAT , nullptr , 0 };
413+ const nvinfer1::DataType weight_type = params->inputs .at (1 ).weight .type ;
414+ nvinfer1::Weights bias{weight_type, nullptr , 0 };
408415 nvinfer1::IFullyConnectedLayer* fc_layer = params->network ->addFullyConnected (
409416 *input_tensor, num_units, params->inputs .at (1 ).weight , bias);
410417 ICHECK (fc_layer != nullptr );
@@ -466,12 +473,15 @@ class BatchNormOpConverter : public TensorRTOpConverter {
466473 }
467474
468475 void * weight_scale_ptr = new float [gamma.count ];
469- nvinfer1::Weights weight_scale{nvinfer1::DataType::kFLOAT , weight_scale_ptr, gamma.count };
476+ const nvinfer1::DataType weight_type_scale = params->inputs .at (1 ).weight .type ;
477+ nvinfer1::Weights weight_scale{weight_type_scale, weight_scale_ptr, gamma.count };
470478 params->trt_weights ->push_back (weight_scale);
471479 void * weight_shift_ptr = new float [gamma.count ];
472- nvinfer1::Weights weight_shift{nvinfer1::DataType::kFLOAT , weight_shift_ptr, gamma.count };
480+ const nvinfer1::DataType weight_type_shift = params->inputs .at (2 ).weight .type ;
481+ nvinfer1::Weights weight_shift{weight_type_shift, weight_shift_ptr, gamma.count };
473482 params->trt_weights ->push_back (weight_shift);
474- nvinfer1::Weights power{nvinfer1::DataType::kFLOAT , nullptr , 0 };
483+ const nvinfer1::DataType weight_type_power = params->inputs .at (3 ).weight .type ;
484+ nvinfer1::Weights power{weight_type_power, nullptr , 0 };
475485
476486 // fill in the content of weights for the Scale layer
477487 const float * gamma_ptr = reinterpret_cast <const float *>(gamma.values );
@@ -911,8 +921,10 @@ class BiasAddOpConverter : public TensorRTOpConverter {
911921 input_tensor = Reshape (params, input_tensor, new_shape);
912922 }
913923
914- nvinfer1::Weights shift{nvinfer1::DataType::kFLOAT , nullptr , 0 };
915- nvinfer1::Weights power{nvinfer1::DataType::kFLOAT , nullptr , 0 };
924+ const nvinfer1::DataType weight_type = params->inputs .at (1 ).weight .type ;
925+
926+ nvinfer1::Weights shift{weight_type, nullptr , 0 };
927+ nvinfer1::Weights power{weight_type, nullptr , 0 };
916928 nvinfer1::IScaleLayer* scale_layer = params->network ->addScale (
917929 *input_tensor, nvinfer1::ScaleMode::kCHANNEL , params->inputs .at (1 ).weight , shift, power);
918930 ICHECK (scale_layer != nullptr );
@@ -962,7 +974,8 @@ class Conv2DTransposeOpConverter : public TensorRTOpConverter {
962974 const int num_outputs =
963975 std::stoi (params->node .GetAttr <std::vector<std::string>>(" channels" )[0 ]);
964976 const auto kernel_size = nvinfer1::DimsHW (weight_shape[2 ], weight_shape[3 ]);
965- nvinfer1::Weights bias{nvinfer1::DataType::kFLOAT , nullptr , 0 };
977+ const nvinfer1::DataType weight_type = params->inputs .at (1 ).weight .type ;
978+ nvinfer1::Weights bias{weight_type, nullptr , 0 };
966979 auto deconv_layer = params->network ->addDeconvolution (*input_tensor, num_outputs, kernel_size,
967980 params->inputs .at (1 ).weight , bias);
968981 ICHECK (deconv_layer != nullptr );
@@ -1020,7 +1033,8 @@ class Conv3DTransposeOpConverter : public TensorRTOpConverter {
10201033 const int num_outputs =
10211034 std::stoi (params->node .GetAttr <std::vector<std::string>>(" channels" )[0 ]);
10221035 const auto kernel_size = nvinfer1::Dims3 (weight_shape[2 ], weight_shape[3 ], weight_shape[4 ]);
1023- nvinfer1::Weights bias{nvinfer1::DataType::kFLOAT , nullptr , 0 };
1036+ const nvinfer1::DataType weight_type = params->inputs .at (1 ).weight .type ;
1037+ nvinfer1::Weights bias{weight_type, nullptr , 0 };
10241038 auto deconv_layer = params->network ->addDeconvolutionNd (*input_tensor, num_outputs, kernel_size,
10251039 params->inputs .at (1 ).weight , bias);
10261040 ICHECK (deconv_layer != nullptr );
0 commit comments