Skip to content

Commit

Permalink
Add basic definition of models, Needs to be trained and tested
Browse files Browse the repository at this point in the history
Trained a lenet1 model

Add All Weights

Add unzip utility function, fix linux build

Completed everything

Fix build, Style fixes next

Use force local for windows while unzipping tar files

Use force local for windows while unzipping tar files

Added Utility Function

Added Utility Function

Style Fix

Fix Typo causing build error in windows

Fix Typo causing build error in windows

Fix const issue for windows

Extract in data folder

Reposition force local

This should work

Print Path in windows for debugging

Print Path in windows for debugging

Print Path in windows for debugging

Stip components of tar

Stip components of tar

strip componenets

Initial Definition

Add List Dir utility function

Add List Dir utility function

Squash this, annotation read

Yay, we can read xml now
  • Loading branch information
kartikdutt18 committed May 29, 2020
1 parent e70d009 commit 3353e2e
Show file tree
Hide file tree
Showing 12 changed files with 445 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .ci/linux-steps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ steps:
displayName: 'Build models'

# Run CTests.
- script: cd build/tests/ && sudo CTEST_OUTPUT_ON_FAILURE=1 ctest -R UtilsTest
- script: cd build/tests/ && sudo CTEST_OUTPUT_ON_FAILURE=1 ctest -T Test .
displayName: 'Run tests via ctest'

# Publish test results to Azure Pipelines
Expand Down
2 changes: 1 addition & 1 deletion .ci/macos-steps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ steps:
displayName: 'Build models'

# Run CTests.
- script: cd build/tests/ && sudo CTEST_OUTPUT_ON_FAILURE=1 ctest -R UtilsTest
- script: cd build/tests/ && sudo CTEST_OUTPUT_ON_FAILURE=1 ctest -T Test .
displayName: 'Run tests via ctest'

# Publish test results to Azure Pipelines
Expand Down
2 changes: 1 addition & 1 deletion .ci/windows-steps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ steps:
# Run tests via ctest.
- bash: |
cd build/tests
CTEST_OUTPUT_ON_FAILURE=1 ctest -T Test -C Release -R UtilsTest
CTEST_OUTPUT_ON_FAILURE=1 ctest -T Test -C Release .
displayName: 'Run tests via ctest'

# Publish test results to Azure Pipelines
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ xcode*
.idea
cmake-build-*
*.csv
*.tar
*.zip
*.tar.gz
.travis/configs.hpp
Testing/*
63 changes: 63 additions & 0 deletions data/annotations/2007_000027.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<annotation>
<folder>VOC2012</folder>
<filename>2007_000027.jpg</filename>
<source>
<database>The VOC2007 Database</database>
<annotation>PASCAL VOC2007</annotation>
<image>flickr</image>
</source>
<size>
<width>486</width>
<height>500</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>person</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>174</xmin>
<ymin>101</ymin>
<xmax>349</xmax>
<ymax>351</ymax>
</bndbox>
<part>
<name>head</name>
<bndbox>
<xmin>169</xmin>
<ymin>104</ymin>
<xmax>209</xmax>
<ymax>146</ymax>
</bndbox>
</part>
<part>
<name>hand</name>
<bndbox>
<xmin>278</xmin>
<ymin>210</ymin>
<xmax>297</xmax>
<ymax>233</ymax>
</bndbox>
</part>
<part>
<name>foot</name>
<bndbox>
<xmin>273</xmin>
<ymin>333</ymin>
<xmax>297</xmax>
<ymax>354</ymax>
</bndbox>
</part>
<part>
<name>foot</name>
<bndbox>
<xmin>319</xmin>
<ymin>307</ymin>
<xmax>340</xmax>
<ymax>326</ymax>
</bndbox>
</part>
</object>
</annotation>
63 changes: 63 additions & 0 deletions data/annotations/2007_000032.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<annotation>
<folder>VOC2012</folder>
<filename>2007_000032.jpg</filename>
<source>
<database>The VOC2007 Database</database>
<annotation>PASCAL VOC2007</annotation>
<image>flickr</image>
</source>
<size>
<width>500</width>
<height>281</height>
<depth>3</depth>
</size>
<segmented>1</segmented>
<object>
<name>aeroplane</name>
<pose>Frontal</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>104</xmin>
<ymin>78</ymin>
<xmax>375</xmax>
<ymax>183</ymax>
</bndbox>
</object>
<object>
<name>aeroplane</name>
<pose>Left</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>133</xmin>
<ymin>88</ymin>
<xmax>197</xmax>
<ymax>123</ymax>
</bndbox>
</object>
<object>
<name>person</name>
<pose>Rear</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>195</xmin>
<ymin>180</ymin>
<xmax>213</xmax>
<ymax>229</ymax>
</bndbox>
</object>
<object>
<name>person</name>
<pose>Rear</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>26</xmin>
<ymin>189</ymin>
<xmax>44</xmax>
<ymax>238</ymax>
</bndbox>
</object>
</annotation>
55 changes: 50 additions & 5 deletions dataloader/dataloader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
*/
#include <mlpack/core/data/scaler_methods/min_max_scaler.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <mlpack/core/math/shuffle_data.hpp>
#include <mlpack/core/data/split_data.hpp>
#include <mlpack/prereqs.hpp>
#include <boost/property_tree/ptree.hpp>
#include <dataloader/datasets.hpp>
#include <mlpack/prereqs.hpp>
#include <boost/foreach.hpp>
#include <mlpack/core.hpp>
#include <utils/utils.hpp>

Expand Down Expand Up @@ -117,6 +120,28 @@ class DataLoader
std::vector<std::string>(),
const double augmentationProbability = 0.2);

/**
* Loads object detection dataset. It requires a single annotation file in xml format.
* Each XML file should correspond to a single image in images folder.
*
* XML file should containg the following :
* 1. Each XML file should be wrapped in annotation tag.
* 2. Filename of image in images folder will be depicted by filename tag.
* 3. Object tag depicting characteristics of bounding box.
* 4. Each object tag should contain name tag i.e. class of the object.
* 5. Each object tag should contain bndbox tag containing xmin, ymin, xmax, ymax.
*
* NOTE : Labels are assigned using lexicographically. Set verbose to 1 to print labels
* and their corresponding class.
*
* @param pathToAnnotations Path to the folder containg xml type annotation files.
* @param pathToImages Path to folder containing images corresponding to annotations.
* @param absolutePath Boolean to determine if absolute path is used. Defaults to false.
*/
void LoadObjectDetectionDataset(const std::string& pathToAnnotations,
const std::string& pathToImages,
const bool absolutePath = false);

//! Get the training dataset features.
DatasetX TrainFeatures() const { return trainFeatures; }

Expand Down Expand Up @@ -179,11 +204,30 @@ class DataLoader
*/
void DownloadDataset(const std::string& dataset)
{
if (datasetMap[dataset].zipFile && (!Utils::PathExists(
datasetMap[dataset].trainPath) ||
!Utils::PathExists(datasetMap[dataset].testPath)))
{
Utils::DownloadFile(datasetMap[dataset].datasetURL,
datasetMap[dataset].datasetPath, dataset + "_training_data.",
false, false, datasetMap[dataset].serverName,
datasetMap[dataset].zipFile);

if (!Utils::CompareCRC32(datasetMap[dataset].datasetPath,
datasetMap[dataset].datasetHash))
{
mlpack::Log::Fatal << "Corrupted Data for " << dataset <<
" downloaded." << std::endl;
}

return;
}

if (!Utils::PathExists(datasetMap[dataset].trainPath))
{
Utils::DownloadFile(datasetMap[dataset].trainDownloadUrl,
Utils::DownloadFile(datasetMap[dataset].trainDownloadURL,
datasetMap[dataset].trainPath, dataset + "_training_data.",
false);
false, false, datasetMap[dataset].serverName);

if (!Utils::CompareCRC32(datasetMap[dataset].trainPath,
datasetMap[dataset].trainHash))
Expand All @@ -192,11 +236,12 @@ class DataLoader
dataset << " downloaded." << std::endl;
}
}

if (!Utils::PathExists(datasetMap[dataset].testPath))
{
Utils::DownloadFile(datasetMap[dataset].trainDownloadUrl,
Utils::DownloadFile(datasetMap[dataset].trainDownloadURL,
datasetMap[dataset].testPath, dataset + "_testing_data.",
false);
false, false, datasetMap[dataset].serverName);

if (!Utils::CompareCRC32(datasetMap[dataset].testPath,
datasetMap[dataset].testHash))
Expand Down
48 changes: 40 additions & 8 deletions dataloader/dataloader_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,6 @@ template<
arma::mat trainDataset, validDataset;
data::Split(dataset, trainDataset, validDataset, ratio, shuffle);

if (useScaler)
{
scaler.Fit(trainDataset);
scaler.Transform(trainDataset, trainDataset);
scaler.Transform(validDataset, validDataset);
}

trainFeatures = trainDataset.rows(WrapIndex(startInputFeatures,
trainDataset.n_rows), WrapIndex(endInputFeatures,
trainDataset.n_rows));
Expand All @@ -125,10 +118,16 @@ template<
validDataset.n_rows), WrapIndex(endInputFeatures,
validDataset.n_rows));

validLabels = trainDataset.rows(WrapIndex(startPredictionFeatures,
validLabels = validDataset.rows(WrapIndex(startPredictionFeatures,
validDataset.n_rows), WrapIndex(endPredictionFeatures,
validDataset.n_rows));

if (useScaler)
{
scaler.Fit(trainFeatures);
scaler.Transform(trainFeatures, trainFeatures);
scaler.Transform(validFeatures, validFeatures);
}
// TODO : Add support for augmentation here.
mlpack::Log::Info << "Training Dataset Loaded." << std::endl;
}
Expand All @@ -145,4 +144,37 @@ template<
}
}

template<
typename DatasetX,
typename DatasetY,
class ScalerType
> void DataLoader<
DatasetX, DatasetY, ScalerType
>::LoadObjectDetectionDataset(const std::string& pathToAnnotations,
const std::string& pathToImages,
const bool absolutePath)
{
std::vector<boost::filesystem::path> annotationsDirectory, imagesDirectory;

// Fill the directory.
Utils::ListDir(pathToAnnotations, annotationsDirectory, absolutePath);
Utils::ListDir(pathToImages, imagesDirectory, absolutePath);

// Read the xml file.
for (boost::filesystem::path annotationFile : annotationsDirectory)
{
// Read the xml file.
boost::property_tree::ptree annotation;
std::cout << annotationFile.string() << std::endl;
boost::property_tree::read_xml(annotationFile.string(), annotation);

// Read properties inside annotation file.
BOOST_FOREACH (boost::property_tree::ptree::value_type const& object,
annotation.get_child("annotation.object"))
{
std::cout << object.first << std::endl;
}
}
}

#endif
Loading

0 comments on commit 3353e2e

Please sign in to comment.