Skip to content

Commit

Permalink
fix usedImageNum init bug in quantization tool
Browse files Browse the repository at this point in the history
  • Loading branch information
liqing committed Aug 23, 2019
1 parent a92cefd commit 27f45da
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions tools/quantization/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ bool Helper::fileExist(const std::string& file) {
return stat(file.c_str(), &buffer) == 0;
}

void Helper::readImages(std::vector<std::string>& images, const std::string& filePath, const int usedImageNum) {
void Helper::readImages(std::vector<std::string>& images, const std::string& filePath, int* usedImageNum) {
DIR* root = opendir(filePath.c_str());
int count = 0;
if (root == NULL) {
Expand All @@ -40,11 +40,11 @@ void Helper::readImages(std::vector<std::string>& images, const std::string& fil
if (fileExist(fileName)) {
// std::cout << "==> " << fileName << std::endl;
// DLOG(INFO) << fileName;
if (usedImageNum <= 0) {
if (*usedImageNum == 0) {
// use all images in the folder
images.push_back(fileName);
count++;
} else if (count < usedImageNum) {
} else if (count < *usedImageNum) {
// use usedImageNum images
images.push_back(fileName);
count++;
Expand All @@ -55,6 +55,9 @@ void Helper::readImages(std::vector<std::string>& images, const std::string& fil
}
ent = readdir(root);
}
if (*usedImageNum == 0) {
*usedImageNum = count;
}
DLOG(INFO) << "used image num: " << images.size();
}

Expand Down
2 changes: 1 addition & 1 deletion tools/quantization/Helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Helper {
static std::set<std::string> weightQuantizeMethod;

static bool fileExist(const std::string& file);
static void readImages(std::vector<std::string>& images, const std::string& filePath, const int usedImageNum);
static void readImages(std::vector<std::string>& images, const std::string& filePath, int *usedImageNum);
static void preprocessInput(MNN::CV::ImageProcess* pretreat, int targetWidth, int targetHeight,
const std::string& inputImageFileName, MNN::Tensor* input);
static void invertData(float* dst, const float* src, int size);
Expand Down
3 changes: 2 additions & 1 deletion tools/quantization/calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Calibration::Calibration(MNN::NetT* model, uint8_t* modelBuffer, const int buffe

config.sourceFormat = RGBA;
std::string imagePath;
_imageNum = 0;
{
if (picObj.HasMember("mean")) {
auto mean = picObj["mean"].GetArray();
Expand Down Expand Up @@ -112,7 +113,7 @@ Calibration::Calibration(MNN::NetT* model, uint8_t* modelBuffer, const int buffe
_process = process;

// read images file names
Helper::readImages(_imgaes, imagePath.c_str(), _imageNum);
Helper::readImages(_imgaes, imagePath.c_str(), &_imageNum);

_initMNNSession(modelBuffer, bufferSize, channles);
_initMaps();
Expand Down

0 comments on commit 27f45da

Please sign in to comment.