-
Notifications
You must be signed in to change notification settings - Fork 4
Replace tile metadata files with layouts database #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kirstenmg
wants to merge
11
commits into
TASM-interface
Choose a base branch
from
tile-layout-index
base: TASM-interface
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
19e444f
Initial commit of layout database changes
kirstenmg 759e8a4
Fix locationOfTileForId
kirstenmg a8d6200
Load videos in TasmTest; un-comment test in SemanticIndexTest
kirstenmg e390868
Load resources per test
kirstenmg 1ce81a8
Add prepared statements for layout database queries
kirstenmg a0628d4
Finish adding prepared statments for layout database
kirstenmg c119f8d
Use testing paths, rather than default, for DatabaseTest and Semantic…
kirstenmg 231fc8f
Replace bird video with red video
kirstenmg ef91b9f
Add benchmarking for layout database
kirstenmg 400f6f3
Small improvements for layout database benchmarking
kirstenmg 51afabc
Fixed wrong order of id, frames in testLocationOfTileForId
kirstenmg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| #include "LayoutDatabase.h" | ||
| #include "Files.h" | ||
| #include <gtest/gtest.h> | ||
|
|
||
| namespace tasm { | ||
|
|
||
| class DatabaseTestFixture : public ::testing::Test { | ||
| public: | ||
| DatabaseTestFixture() {} | ||
|
|
||
| protected: | ||
| void SetUp() { | ||
| // set test configuration | ||
| std::unordered_map<std::string, std::string> options { | ||
| {EnvironmentConfiguration::DefaultLayoutsDB, "test-layout.db"}, | ||
| }; | ||
| auto config = EnvironmentConfiguration::instance(EnvironmentConfiguration(options)); | ||
| std::experimental::filesystem::remove(config.defaultLayoutDatabasePath()); | ||
| LayoutDatabase::instance()->open(); | ||
| } | ||
| void TearDown() { | ||
| std::experimental::filesystem::remove(EnvironmentConfiguration::instance().defaultLayoutDatabasePath()); | ||
| } | ||
| }; | ||
|
|
||
| TEST_F(DatabaseTestFixture, testOpenDb) { | ||
| std::shared_ptr<LayoutDatabase> layoutDatabase = LayoutDatabase::instance(); | ||
|
|
||
| std::experimental::filesystem::path layouts = EnvironmentConfiguration::instance().defaultLayoutDatabasePath(); | ||
| assert(std::experimental::filesystem::exists(layouts)); | ||
| std::experimental::filesystem::remove(layouts); | ||
|
|
||
| layoutDatabase->open(); | ||
| assert(std::experimental::filesystem::exists(layouts)); | ||
| } | ||
|
|
||
| TEST_F(DatabaseTestFixture, testAddSelectLayout) { | ||
| std::shared_ptr<LayoutDatabase> layoutDatabase = LayoutDatabase::instance(); | ||
|
|
||
| std::string video = "video"; | ||
| unsigned int id = 0; | ||
|
|
||
| std::vector<unsigned int> heights{1, 2, 3}; | ||
| std::vector<unsigned int> widths{1, 2, 3, 4}; | ||
| unsigned int numColumns = widths.size(); | ||
| unsigned int numRows = heights.size(); | ||
| std::shared_ptr<TileLayout> tileLayout = std::make_shared<TileLayout>(numColumns, numRows, widths, heights); | ||
|
|
||
| layoutDatabase->addTileLayout(video, id, 40, 50, tileLayout); | ||
|
|
||
| std::shared_ptr<TileLayout> selectedLayout = layoutDatabase->tileLayoutForId(video, id); | ||
| assert(selectedLayout->numberOfColumns() == numColumns); | ||
| assert(selectedLayout->numberOfRows() == numRows); | ||
| assert(selectedLayout->widthsOfColumns() == widths); | ||
| assert(selectedLayout->heightsOfRows() == heights); | ||
| assert(*selectedLayout == *tileLayout); | ||
| } | ||
|
|
||
| TEST_F(DatabaseTestFixture, testSelectLayoutIds) { | ||
| std::shared_ptr<LayoutDatabase> layoutDatabase = LayoutDatabase::instance(); | ||
|
|
||
| std::string video = "video"; | ||
|
|
||
| std::vector<unsigned int> heights{1, 2, 3}; | ||
| std::vector<unsigned int> widths{1, 2, 3, 4}; | ||
| unsigned int numColumns = widths.size(); | ||
| unsigned int numRows = heights.size(); | ||
| std::shared_ptr<TileLayout> tileLayout = std::make_shared<TileLayout>(numColumns, numRows, widths, heights); | ||
|
|
||
| std::vector<int> layoutIds{0, 2, 4, 7}; | ||
|
|
||
| for (auto &id : layoutIds) { | ||
| layoutDatabase->addTileLayout(video, id, id, id + 10, tileLayout); | ||
| } | ||
|
|
||
| // add an id that won't be selected, since it doesn't include frame 10 | ||
| layoutDatabase->addTileLayout(video, 10, 11, 12, tileLayout); | ||
|
|
||
| std::vector<int> foundLayoutIds = layoutDatabase->tileLayoutIdsForFrame(video, 10); | ||
| std::sort(layoutIds.begin(), layoutIds.end()); | ||
| std::sort(foundLayoutIds.begin(), foundLayoutIds.end()); | ||
| assert(layoutIds == foundLayoutIds); | ||
| } | ||
|
|
||
| TEST_F(DatabaseTestFixture, testTotalWidthHeight) { | ||
| std::shared_ptr<LayoutDatabase> layoutDatabase = LayoutDatabase::instance(); | ||
|
|
||
| std::string name = "name"; | ||
| std::vector<unsigned int> heights; | ||
| std::vector<unsigned int> widths; | ||
| unsigned int maxHeight = 10; | ||
| unsigned int maxWidth = 7; | ||
| unsigned int totalHeight = 0; | ||
| unsigned int totalWidth = 0; | ||
|
|
||
| for (unsigned int i = 0; i <= maxHeight; ++i) { | ||
| heights.push_back(i); | ||
| totalHeight += i; | ||
| } | ||
|
|
||
| for (unsigned int i = 0; i <= maxWidth; ++i) { | ||
| widths.push_back(i); | ||
| totalWidth += i; | ||
| } | ||
|
|
||
| unsigned int id = 2; | ||
| unsigned int firstFrame = 40; | ||
| unsigned int lastFrame = 59; | ||
| unsigned int numColumns = widths.size(); | ||
| unsigned int numRows = heights.size(); | ||
| std::shared_ptr<TileLayout> tileLayout = std::make_shared<TileLayout>(numColumns, numRows, widths, heights); | ||
|
|
||
| layoutDatabase->addTileLayout(name, id, firstFrame, lastFrame, tileLayout); | ||
|
|
||
| assert(layoutDatabase->totalWidth(name) == totalWidth); | ||
| assert(layoutDatabase->totalHeight(name) == totalHeight); | ||
| assert(layoutDatabase->largestWidth(name) == maxWidth); | ||
| assert(layoutDatabase->largestHeight(name) == maxHeight); | ||
| assert(layoutDatabase->maximumFrame(name) == lastFrame); | ||
| } | ||
| } // namespace tasm |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| #include "TiledVideoManager.h" | ||
| #include "SemanticIndex.h" | ||
| #include "VideoManager.h" | ||
| #include "Tasm.h" | ||
| #include <gtest/gtest.h> | ||
| #include <chrono> | ||
| #include <fstream> | ||
| #include <iostream> | ||
| #include <functional> | ||
|
|
||
| using namespace tasm; | ||
|
|
||
| const int NUM_VIDEOS = 2; | ||
| const std::string VIDEO_PATHS[NUM_VIDEOS] {"/home/maureen/red_videos/red_6sec_2k.mp4", "/home/maureen/red_videos/red_900sec_2k.mp4"}; | ||
| const std::string LABEL_PATHS[NUM_VIDEOS] {"/home/maureen/NFLX_dataset/detections/labels/birdsincage.db", "/home/maureen/visualroad_tiling/labels_yolo/traffic-2k-001_yolo.db"}; | ||
| const std::string VIDEO_LABELS[NUM_VIDEOS] {"bird", "car"}; | ||
| const std::string VIDEO_NAMES[NUM_VIDEOS] {"birdsincage", "traffic-2k-001_yolo"}; | ||
| const int NUM_FRAMES[NUM_VIDEOS] {180, 27000}; | ||
| const int IDS[NUM_VIDEOS] {197, 8476}; // from tileLayoutIdsForFrame | ||
|
|
||
| const int NUM_ITERATIONS = 3; | ||
| const int FUNCTION_REPETITIONS = 50; // for functions that are too fast to measure without repetition | ||
| const std::string SEP = ","; | ||
| const std::string IMPLEMENTATION = "layout database"; | ||
| const std::string OUTFILE_NAME = "layout_database_benchmark.csv"; | ||
|
|
||
| void printStat(std::ofstream &file, std::string experiment, std::string step, std::string video, int frame, | ||
| int iteration, long time, int repetitions) { | ||
| file << IMPLEMENTATION << SEP << experiment << SEP << step << SEP << video << SEP << frame << SEP << iteration << | ||
| SEP << time << SEP << repetitions << "\n"; | ||
| file.flush(); | ||
| } | ||
|
|
||
| void runBenchmark(std::string videoName, std::shared_ptr<TiledEntry> entry, int iteration, std::ofstream &outputFile, | ||
| int frameNumber, std::string experiment, std::function<void(TiledVideoManager &)> testFunction) { | ||
| std::chrono::system_clock::time_point totalStart = std::chrono::system_clock::now(); | ||
| std::chrono::system_clock::time_point constructorStart = std::chrono::system_clock::now(); | ||
|
|
||
| TiledVideoManager tiledVideoManager(entry); | ||
|
|
||
| std::chrono::system_clock::time_point constructorEnd = std::chrono::system_clock::now(); | ||
| std::chrono::system_clock::time_point functionStart = std::chrono::system_clock::now(); | ||
|
|
||
| for (int i = 0; i < FUNCTION_REPETITIONS; i++) { | ||
| testFunction(tiledVideoManager); | ||
| } | ||
|
|
||
| std::chrono::system_clock::time_point functionEnd = std::chrono::system_clock::now(); | ||
| std::chrono::system_clock::time_point totalEnd = std::chrono::system_clock::now(); | ||
|
|
||
| auto totalDuration = std::chrono::duration_cast<std::chrono::microseconds>(totalEnd - totalStart).count(); | ||
| auto constructorDuration = std::chrono::duration_cast<std::chrono::microseconds>(constructorEnd - constructorStart).count(); | ||
| auto functionDuration = std::chrono::duration_cast<std::chrono::microseconds>(functionEnd - functionStart).count(); | ||
|
|
||
| // output data to csv file | ||
| printStat(outputFile, experiment, "total", videoName, frameNumber, iteration, totalDuration, FUNCTION_REPETITIONS); | ||
| printStat(outputFile, experiment, "constructor", videoName, frameNumber, iteration, constructorDuration, FUNCTION_REPETITIONS); | ||
| printStat(outputFile, experiment, "processing", videoName, frameNumber, iteration, functionDuration, FUNCTION_REPETITIONS); | ||
| } | ||
|
|
||
| void storeVideos(std::string videoName, std::string videoPath, std::string label, int iteration, std::ofstream &outputFile) { | ||
| std::chrono::system_clock::time_point start = std::chrono::system_clock::now(); | ||
|
|
||
| // store red video around objects | ||
| TASM tasm(SemanticIndex::IndexType::LegacyWH); | ||
| tasm.storeWithNonUniformLayout(videoPath, videoName, videoName, label); | ||
|
|
||
| auto end = std::chrono::system_clock::now(); | ||
| auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count(); | ||
|
|
||
| // output data to csv file | ||
| printStat(outputFile, "storeVideos", "processing", videoName, -1, iteration, duration, 1); | ||
| } | ||
|
|
||
| void testConstructor(std::string videoName, std::shared_ptr<TiledEntry> entry, int iteration, std::ofstream &outputFile) { | ||
| std::chrono::system_clock::time_point start = std::chrono::system_clock::now(); | ||
|
|
||
| TiledVideoManager tiledVideoManager(entry); | ||
|
|
||
| auto end = std::chrono::system_clock::now(); | ||
| auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count(); | ||
|
|
||
| // output data to csv file | ||
| printStat(outputFile, "testConstructor", "constructor", videoName, -1, iteration, duration, 1); | ||
| } | ||
|
|
||
| void testTileLayoutIdsForFrame (std::string videoName, std::shared_ptr<TiledEntry> entry, int frames, int iteration, std::ofstream &outputFile) { | ||
| for (int frameNumber = 0; frameNumber < frames; frameNumber += frames / 4) { | ||
| runBenchmark(videoName, entry, iteration, outputFile, frameNumber, "tileLayoutIdsForFrame", [frameNumber](TiledVideoManager &manager) { | ||
| manager.tileLayoutIdsForFrame(frameNumber); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| void testTileLayoutForId (std::string videoName, std::shared_ptr<TiledEntry> entry, int id, int iteration, std::ofstream &outputFile) { | ||
| runBenchmark(videoName, entry, iteration, outputFile, -1, "tileLayoutForId", [id] (TiledVideoManager &manager){ | ||
| manager.tileLayoutForId(id); | ||
| }); | ||
| } | ||
|
|
||
| void testLocationOfTileForId (std::string videoName, std::shared_ptr<TiledEntry> entry, int frames, int id, int iteration, std::ofstream &outputFile) { | ||
| for (int frameNumber = 0; frameNumber < frames; frameNumber += frames / 4) { | ||
| runBenchmark(videoName, entry, iteration, outputFile, frameNumber, "locationOfTileForId", [frameNumber, id] (TiledVideoManager &manager){ | ||
| manager.locationOfTileForId(frameNumber, id); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| void testTotalWidth (std::string videoName, std::shared_ptr<TiledEntry> entry, int iteration, std::ofstream &outputFile) { | ||
| runBenchmark(videoName, entry, iteration, outputFile, -1, "testTotalWidth", [] (TiledVideoManager &manager){ | ||
| manager.totalWidth(); | ||
| }); | ||
| } | ||
|
|
||
| void testTotalHeight (std::string videoName, std::shared_ptr<TiledEntry> entry, int iteration, std::ofstream &outputFile) { | ||
| runBenchmark(videoName, entry, iteration, outputFile, -1, "totalHeight", [] (TiledVideoManager &manager){ | ||
| manager.totalHeight(); | ||
| }); | ||
| } | ||
|
|
||
| void testLargestWidth (std::string videoName, std::shared_ptr<TiledEntry> entry, int iteration, std::ofstream &outputFile) { | ||
| runBenchmark(videoName, entry, iteration, outputFile, -1, "largestWidth", [] (TiledVideoManager &manager){ | ||
| manager.largestWidth(); | ||
| }); | ||
| } | ||
|
|
||
| void testLargestHeight (std::string videoName, std::shared_ptr<TiledEntry> entry, int iteration, std::ofstream &outputFile) { | ||
| runBenchmark(videoName, entry, iteration, outputFile, -1, "largestHeight", [] (TiledVideoManager &manager){ | ||
| manager.largestHeight(); | ||
| }); | ||
| } | ||
|
|
||
| void testMaximumFrame (std::string videoName, std::shared_ptr<TiledEntry> entry, int iteration, std::ofstream &outputFile) { | ||
| runBenchmark(videoName, entry, iteration, outputFile, -1, "maximumFrame", [] (TiledVideoManager &manager){ | ||
| manager.maximumFrame(); | ||
| }); | ||
| } | ||
|
|
||
| class LayoutBenchmarkTestFixture : public ::testing::Test { | ||
| public: | ||
| LayoutBenchmarkTestFixture() { | ||
| } | ||
| }; | ||
|
|
||
| TEST_F(LayoutBenchmarkTestFixture, runBenchmarks) { | ||
| // set test configuration | ||
| std::unordered_map<std::string, std::string> options { | ||
| {EnvironmentConfiguration::DefaultLayoutsDB, "benchmark-layout.db"}, | ||
| {EnvironmentConfiguration::CatalogPath, "benchmark-resources"}, | ||
| {EnvironmentConfiguration::DefaultLabelsDB, "benchmark-labels.db"} | ||
| }; | ||
| auto config = EnvironmentConfiguration::instance(EnvironmentConfiguration(options)); | ||
|
|
||
| // open output file and add header | ||
| std::ofstream outputFile; | ||
| outputFile.open(OUTFILE_NAME, std::ios::out); | ||
| outputFile << "implementation" << SEP << "experiment" << SEP << "step" << SEP << "video" << SEP << "frame"\ | ||
| << SEP << "iteration" << SEP << "time" << SEP << "repetitions\n"; | ||
|
|
||
| // run experiments for each video | ||
| for (int i = 0; i < NUM_VIDEOS; i++) { | ||
| std::string labelPath = LABEL_PATHS[i]; | ||
| std::string videoPath = VIDEO_PATHS[i]; | ||
| std::string label = VIDEO_LABELS[i]; | ||
| std::string name = VIDEO_NAMES[i]; | ||
| int frames = NUM_FRAMES[i]; | ||
| int id = IDS[i]; | ||
|
|
||
| std::experimental::filesystem::remove(config.defaultLayoutDatabasePath()); | ||
| LayoutDatabase::instance()->open(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these the only two lines that are specific to the layout database instance? |
||
|
|
||
| // load object database from real video | ||
| std::experimental::filesystem::remove(config.defaultLabelsDatabasePath()); | ||
| std::experimental::filesystem::copy(labelPath, config.defaultLabelsDatabasePath()); | ||
|
|
||
| // initialize tiledentry | ||
| std::shared_ptr<TiledEntry> entry = std::make_shared<TiledEntry>(name); | ||
|
|
||
| for (int j = 0; j < NUM_ITERATIONS; j++) { | ||
| storeVideos(name, videoPath, label, j, outputFile); | ||
| testConstructor(name, entry, j, outputFile); | ||
| testTileLayoutIdsForFrame(name, entry, frames, j, outputFile); | ||
| testTileLayoutForId(name, entry, id, j, outputFile); | ||
| testLocationOfTileForId(name, entry, frames, id, j, outputFile); | ||
| testTotalWidth(name, entry, j, outputFile); | ||
| testTotalHeight(name, entry, j, outputFile); | ||
| testLargestWidth(name, entry, j, outputFile); | ||
| testLargestHeight(name, entry, j, outputFile); | ||
| testMaximumFrame(name, entry, j, outputFile); | ||
| } | ||
| } | ||
| outputFile.close(); | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to also flush the ofstream so that even if something fails and the tests don't finish, we should hopefully have partial results in the output file.