Skip to content

Commit

Permalink
added benchmarking for saliency and matching
Browse files Browse the repository at this point in the history
  • Loading branch information
tuas-travis-ci authored and Samir-Rashid committed Jun 12, 2024
1 parent 7a6b6c0 commit f860d77
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/cv/saliency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <opencv2/opencv.hpp>
#include "utilities/logging.hpp"


#define REGULAR_TARGET 1
#define MANNIKIN 2

Expand All @@ -25,6 +26,7 @@ Saliency::Saliency(std::string modelPath) {
catch (const c10::Error& e) {
LOG_F(ERROR, "error loading the model %s", e.msg().c_str());
}

}

std::vector<CroppedTarget> Saliency::salience(cv::Mat image) {
Expand Down
10 changes: 10 additions & 0 deletions tests/integration/cv_matching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "cv/matching.hpp"
#include "utilities/constants.hpp"
#include "utilities/common.hpp"

// Download these test images by running "make pull_matching_test_images" or from the test.zip here https://drive.google.com/drive/u/1/folders/1opXBWx6bBF7J3-JSFtrhfFIkYis9qhGR
// Or, any cropped not-stolen images will work
Expand Down Expand Up @@ -79,7 +80,10 @@ int main(int argc, char* argv[]) {
cv::Mat ref4 = cv::imread(refImagePath4);
referenceImages.push_back(std::make_pair(ref4, BottleDropIndex(1)));

auto startLoad = getUnixTime_ms().count();
Matching matcher(bottlesToDrop, referenceImages, modelPath);
auto endLoad = getUnixTime_ms().count();
LOG_F(INFO, "time to load: %lu milliseconds", endLoad - startLoad);
cv::Mat image = cv::imread(imageMatchPath);
Bbox dummyBox(0, 0, 0, 0);
CroppedTarget cropped = {
Expand All @@ -95,15 +99,21 @@ int main(int argc, char* argv[]) {
false
};

auto startMatch = getUnixTime_ms().count();
MatchResult result = matcher.match(cropped);
auto endMatch = getUnixTime_ms().count();
LOG_F(INFO, "\nTRUE MATCH TEST:\nClosest is bottle at index %d\nThe similarity is %.3f\n",
int(result.bottleDropIndex),
result.distance);

auto startMatchFalse = getUnixTime_ms().count();
MatchResult resultFalse = matcher.match(croppedFalse);
auto endMatchFalse = getUnixTime_ms().count();
LOG_F(INFO, "\nFALSE MATCH TEST:\nClosest is bottle at index %d\nThe similarity is %.3f\n",
int(resultFalse.bottleDropIndex),
resultFalse.distance);
LOG_F(INFO, "time to match: %lu milliseconds",
(endMatch - startMatch + endMatchFalse - startMatchFalse)/2);

return 0;
}
8 changes: 8 additions & 0 deletions tests/integration/cv_saliency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string>

#include "cv/saliency.hpp"
#include "utilities/common.hpp"
#include "loguru.hpp"

// expected arguments: <path-to-model> <path-to-image>
Expand All @@ -18,11 +19,18 @@ int main(int argc, const char* argv[]) {
// convert image to tensor

const char* modelPath = argv[1];
auto startLoad = getUnixTime_ms().count();
Saliency sal(modelPath);
auto endLoad = getUnixTime_ms().count();
LOG_F(INFO, "time to load: %u milliseconds", endLoad - startLoad);

const char* imgPath = argv[2];
cv::Mat img = cv::imread(imgPath, cv::IMREAD_COLOR);

auto startSalience = getUnixTime_ms().count();
std::vector<CroppedTarget> predictions = sal.salience(img);
auto endSalience = getUnixTime_ms().count();
LOG_F(INFO, "time to saliency: %u milliseconds", endSalience - startSalience);

img = cv::imread(imgPath, cv::IMREAD_COLOR);

Expand Down

0 comments on commit f860d77

Please sign in to comment.