Created
January 12, 2018 18:08
-
-
Save sydney0zq/56b9203e5b91309b8386a39fb6f1e116 to your computer and use it in GitHub Desktop.
Tracker trainer test separately
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <opencv2/core/core.hpp> | |
#include <opencv2/highgui/highgui.hpp> | |
using namespace cv; | |
using namespace std; | |
// Number of images in each batch. | |
const int kBatchSize = 50; | |
// Number of examples that we generate (by applying synthetic transformations) | |
// to each image. | |
const int kGeneratedExamplesPerImage = 10; | |
std::vector<cv::Mat> images_batch_; # I put it outside cause it is a class member | |
# for this member function, it is global | |
void Train(cv::Mat image){ | |
// Make training examples. | |
std::vector<cv::Mat> images; | |
for (int i=0; i < 11; i++){ | |
images.push_back(image); | |
} | |
while (images.size() > 0) { | |
// Compute the number of images left to complete the batch. | |
const int num_in_batch = images_batch_.size(); | |
const int num_left_in_batch = kBatchSize - num_in_batch; | |
cout << "num_left_in_batch " << num_left_in_batch << endl; | |
// The number of images to use is upper-bounded by the number left in the batch. | |
// The rest go into the next batch. | |
const int num_use = std::min(static_cast<int>(images.size()), num_left_in_batch); | |
cout << "num_use " << num_use << endl; | |
if (num_use < 0) { | |
cout << "Error num use" << num_use << endl; | |
} | |
// Add the approrpriate number of images to the batch. | |
images_batch_.insert(images_batch_.end(), | |
images.begin(), images.begin() + num_use); | |
// If we have a full batch, then train! Otherwise, save this batch for later. | |
if (images_batch_.size() == kBatchSize) { | |
// Increment the batch count. | |
cout << "Process batch" << endl; | |
// After training, clear the batch. | |
images_batch_.clear(); | |
// Reserve the appropriate amount of space for the next batch. | |
images_batch_.reserve(kBatchSize); | |
} | |
// Remove the images that were used. | |
images.erase(images.begin(), images.begin() + num_use); | |
} | |
} | |
int main(int argc, char** argv){ | |
//cv::Mat image = imread(argv[1], CV_LOAD_IMAGE_COLOR); | |
cv::Mat image = Mat::zeros(100, 100, 0); | |
cout << "start"; | |
Train(image); | |
Train(image); | |
Train(image); | |
Train(image); | |
Train(image); | |
Train(image); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compile it with