From dfc437daa009bbfc30d5c4672d7cf347663ebb42 Mon Sep 17 00:00:00 2001 From: wang-xinyu Date: Thu, 29 Sep 2022 18:48:29 +0800 Subject: [PATCH] fix coding style --- yolov5/calibrator.cpp | 37 +++++++++++++++---------------------- yolov5/calibrator.h | 5 ++--- yolov5/common.hpp | 10 +++------- 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/yolov5/calibrator.cpp b/yolov5/calibrator.cpp index 2e2f586..472582f 100644 --- a/yolov5/calibrator.cpp +++ b/yolov5/calibrator.cpp @@ -7,32 +7,28 @@ #include "utils.h" Int8EntropyCalibrator2::Int8EntropyCalibrator2(int batchsize, int input_w, int input_h, const char* img_dir, const char* calib_table_name, const char* input_blob_name, bool read_cache) - : batchsize_(batchsize) - , input_w_(input_w) - , input_h_(input_h) - , img_idx_(0) - , img_dir_(img_dir) - , calib_table_name_(calib_table_name) - , input_blob_name_(input_blob_name) - , read_cache_(read_cache) -{ + : batchsize_(batchsize), + input_w_(input_w), + input_h_(input_h), + img_idx_(0), + img_dir_(img_dir), + calib_table_name_(calib_table_name), + input_blob_name_(input_blob_name), + read_cache_(read_cache) { input_count_ = 3 * input_w * input_h * batchsize; CUDA_CHECK(cudaMalloc(&device_input_, input_count_ * sizeof(float))); read_files_in_dir(img_dir, img_files_); } -Int8EntropyCalibrator2::~Int8EntropyCalibrator2() -{ +Int8EntropyCalibrator2::~Int8EntropyCalibrator2() { CUDA_CHECK(cudaFree(device_input_)); } -int Int8EntropyCalibrator2::getBatchSize() const TRT_NOEXCEPT -{ +int Int8EntropyCalibrator2::getBatchSize() const TRT_NOEXCEPT { return batchsize_; } -bool Int8EntropyCalibrator2::getBatch(void* bindings[], const char* names[], int nbBindings) TRT_NOEXCEPT -{ +bool Int8EntropyCalibrator2::getBatch(void* bindings[], const char* names[], int nbBindings) TRT_NOEXCEPT { if (img_idx_ + batchsize_ > (int)img_files_.size()) { return false; } @@ -41,7 +37,7 @@ bool Int8EntropyCalibrator2::getBatch(void* bindings[], const char* names[], int for (int i = img_idx_; i < img_idx_ + batchsize_; i++) { std::cout << img_files_[i] << " " << i << std::endl; cv::Mat temp = cv::imread(img_dir_ + img_files_[i]); - if (temp.empty()){ + if (temp.empty()) { std::cerr << "Fatal error: image cannot open!" << std::endl; return false; } @@ -57,22 +53,19 @@ bool Int8EntropyCalibrator2::getBatch(void* bindings[], const char* names[], int return true; } -const void* Int8EntropyCalibrator2::readCalibrationCache(size_t& length) TRT_NOEXCEPT -{ +const void* Int8EntropyCalibrator2::readCalibrationCache(size_t& length) TRT_NOEXCEPT { std::cout << "reading calib cache: " << calib_table_name_ << std::endl; calib_cache_.clear(); std::ifstream input(calib_table_name_, std::ios::binary); input >> std::noskipws; - if (read_cache_ && input.good()) - { + if (read_cache_ && input.good()) { std::copy(std::istream_iterator(input), std::istream_iterator(), std::back_inserter(calib_cache_)); } length = calib_cache_.size(); return length ? calib_cache_.data() : nullptr; } -void Int8EntropyCalibrator2::writeCalibrationCache(const void* cache, size_t length) TRT_NOEXCEPT -{ +void Int8EntropyCalibrator2::writeCalibrationCache(const void* cache, size_t length) TRT_NOEXCEPT { std::cout << "writing calib cache: " << calib_table_name_ << " size: " << length << std::endl; std::ofstream output(calib_table_name_, std::ios::binary); output.write(reinterpret_cast(cache), length); diff --git a/yolov5/calibrator.h b/yolov5/calibrator.h index aae4ca4..afba664 100644 --- a/yolov5/calibrator.h +++ b/yolov5/calibrator.h @@ -11,8 +11,7 @@ //! \brief Implements Entropy calibrator 2. //! CalibrationAlgoType is kENTROPY_CALIBRATION_2. //! -class Int8EntropyCalibrator2 : public nvinfer1::IInt8EntropyCalibrator2 -{ +class Int8EntropyCalibrator2 : public nvinfer1::IInt8EntropyCalibrator2 { public: Int8EntropyCalibrator2(int batchsize, int input_w, int input_h, const char* img_dir, const char* calib_table_name, const char* input_blob_name, bool read_cache = true); @@ -37,4 +36,4 @@ private: std::vector calib_cache_; }; -#endif // ENTROPY_CALIBRATOR_H +#endif // ENTROPY_CALIBRATOR_H diff --git a/yolov5/common.hpp b/yolov5/common.hpp index c7eeb4e..190850e 100644 --- a/yolov5/common.hpp +++ b/yolov5/common.hpp @@ -98,8 +98,7 @@ std::map loadWeights(const std::string file) { input >> count; assert(count > 0 && "Invalid weight map file."); - while (count--) - { + while (count--) { Weights wt{ DataType::kFLOAT, nullptr, 0 }; uint32_t size; @@ -110,8 +109,7 @@ std::map loadWeights(const std::string file) { // Load blob uint32_t* val = reinterpret_cast(malloc(sizeof(val) * size)); - for (uint32_t x = 0, y = size; x < y; ++x) - { + for (uint32_t x = 0, y = size; x < y; ++x) { input >> std::hex >> val[x]; } wt.values = val; @@ -156,8 +154,6 @@ IScaleLayer* addBatchNorm2d(INetworkDefinition *network, std::map& weightMap, ITensor& input, int outch, int ksize, int s, int g, std::string lname) { Weights emptywts{ DataType::kFLOAT, nullptr, 0 }; int p = ksize / 3; @@ -323,5 +319,5 @@ IPluginV2Layer* addYoLoLayer(INetworkDefinition *network, std::mapaddPluginV2(&input_tensors[0], input_tensors.size(), *plugin_obj); return yolo; } -#endif +#endif // YOLOV5_COMMON_H_