Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Generated 2 new data readers for Traffic Sensor #218

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions DetectionMetrics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ include(FindPkgConfig)
include(Deps/ice/CMakeLists.txt)
include(Deps/numpy/CMakeLists.txt)
include(Deps/yaml-cpp/CMakeLists.txt)
include(Deps/ros/CMakeLists.txt)
#include(Deps/ros/CMakeLists.txt)
include(Deps/opencv/CMakeLists.txt)
include(Deps/qt/CMakeLists.txt)

Expand All @@ -46,9 +46,9 @@ SET( INTERFACES_CPP_DIR ${CMAKE_CURRENT_BINARY_DIR}/libs/interfaces/cpp/jderobot
if(ZeroCIce_FOUND)
add_definitions(-DICE)
endif()
if(roscpp_FOUND)
add_definitions(-DJDERROS)
endif()
#if(roscpp_FOUND)
# add_definitions(-DJDERROS)
#endif()
if(OpenCV_FOUND)
SET(ENABLE_DNN_CAFFE ON)
add_definitions(-DENABLE_DNN_CAFFE)
Expand All @@ -62,14 +62,14 @@ endif(OpenCV_FOUND)
add_subdirectory(SampleGenerationApp)
add_subdirectory(Tools)

if(roscpp_FOUND)
add_subdirectory(DetectionMetricsROS)
endif()
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/ClassMappingHierarchy.xml
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/ClassMappingHierarchy.xml
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Tools)
#if(roscpp_FOUND)
# add_subdirectory(DetectionMetricsROS)
#endif()
# file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/ClassMappingHierarchy.xml
# DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
# file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/ClassMappingHierarchy.xml
# DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Tools)

IF (BUILD_TEST)
IF (BUILD_TEST)
add_subdirectory(test)
ENDIF()
2 changes: 1 addition & 1 deletion DetectionMetrics/DetectionMetricsLib/Common/Sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Sample::Sample(const std::string &path, const std::string &id,bool loadDepth) {

if (boost::filesystem::exists(boost::filesystem::path(path + "/" + id + ".json")))
this->rectRegions=RectRegionsPtr(new RectRegions(path + "/" + id + ".json"));
else{
else {
LOG(ERROR) << "Error " + id + " sample has not associated detection";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ SET (DatasetConverters_SOURCE_FILES
readers/COCODatasetReader
readers/PascalVOCDatasetReader
readers/PrincetonDatasetReader
readers/TrafficSensorGTDatasetReader
readers/TrafficSensorOutputDatasetReader
writers/PascalVOCDatasetWriter
readers/ImageNetDatasetReader
readers/SpinelloDatasetReader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ bool COCODatasetReader::appendDataset(const std::string &datasetPath, const std:
if(!a.IsArray())
throw std::invalid_argument("Invalid Annotations file Passed, Images member isn't an array");


std::string img_filename, img_dirname;
std::size_t filename_id_start, filename_ext;

Expand All @@ -80,21 +79,17 @@ bool COCODatasetReader::appendDataset(const std::string &datasetPath, const std:
LOG(INFO) << "Image Directory Found: " << img_dir.string() << '\n';
} else {
throw std::invalid_argument("Corresponding Image Directory can't be located, please place it in the same Directory as annotations if you wish to continue without reading images");

}

if(!doc.HasMember("images"))
throw std::invalid_argument("Images Member not available, invalid annotations file passed");


const rapidjson::Value& imgs = doc["images"];

if(!imgs.IsArray())
throw std::invalid_argument("Invalid Annotations file Passed, Images member isn't an array");


for (rapidjson::Value::ConstValueIterator itr = imgs.Begin(); itr != imgs.End(); ++itr) {

unsigned long int id = (*itr)["id"].GetUint64();
std::string filename = (*itr)["file_name"].GetString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ GenericDatasetReader::GenericDatasetReader(const std::string &path, const std::s
if (std::find(this->availableImplementations.begin(), this->availableImplementations.end(), readerImplementation) != this->availableImplementations.end()){
imp = getImplementation(readerImplementation);
switch (imp) {
case OPENIMAGES:
case OPENIMAGES:
this->openimagesDatasetReaderPtr = OpenImagesDatasetReaderPtr( new OpenImagesDatasetReader(path,classNamesFile,imagesRequired));
break;
case IMAGENET:
case IMAGENET:
this->imagenetDatasetReaderPtr = ImageNetDatasetReaderPtr( new ImageNetDatasetReader(path,classNamesFile,imagesRequired));
break;
case COCO:
Expand All @@ -35,6 +35,12 @@ GenericDatasetReader::GenericDatasetReader(const std::string &path, const std::s
case PRINCETON:
this->princetonDatasetReaderPtr = PrincetonDatasetReaderPtr( new PrincetonDatasetReader(path,classNamesFile,imagesRequired));
break;
case TRAFFICSENSORGT:
this->trafficSensorGTDatasetReaderPtr = TrafficSensorGTDatasetReaderPtr(new TrafficSensorGTDatasetReader(path,classNamesFile,imagesRequired));
break;
case TRAFFICSENSOROUTPUT:
this->trafficSensorOutputDatasetReaderPtr = TrafficSensorOutputDatasetReaderPtr(new TrafficSensorOutputDatasetReader(path,classNamesFile,imagesRequired));
break;
default:
LOG(WARNING)<<readerImplementation + " is not a valid reader implementation";
break;
Expand Down Expand Up @@ -110,33 +116,31 @@ void GenericDatasetReader::configureAvailablesImplementations(std::vector<std::s
data.push_back("Spinello");
data.push_back("Own");
data.push_back("Princeton");

data.push_back("Traffic Sensor GT");
data.push_back("Traffic Sensor Output");
}

READER_IMPLEMENTATIONS GenericDatasetReader::getImplementation(const std::string& readerImplementation) {
if (readerImplementation == "Open Images") {
return OPENIMAGES;
}
if (readerImplementation == "ImageNet"){
return OPENIMAGES;
} else if (readerImplementation == "ImageNet"){
return IMAGENET;
}
if (readerImplementation == "COCO"){
} else if (readerImplementation == "COCO"){
return COCO;
}
if (readerImplementation == "Pascal VOC"){
} else if (readerImplementation == "Pascal VOC"){
return PASCALVOC;
}
if (readerImplementation == "YOLO"){
} else if (readerImplementation == "YOLO"){
return YOLO_1;
}
if (readerImplementation == "Spinello"){
} else if (readerImplementation == "Spinello"){
return SPINELLO;
}
if (readerImplementation == "Own"){
} else if (readerImplementation == "Own"){
return OWN;
}
if (readerImplementation == "Princeton"){
} else if (readerImplementation == "Princeton"){
return PRINCETON;
} else if (readerImplementation == "Traffic Sensor GT"){
return TRAFFICSENSORGT;
} else if (readerImplementation == "Traffic Sensor Output"){
return TRAFFICSENSOROUTPUT;
}
}

Expand All @@ -158,6 +162,10 @@ DatasetReaderPtr GenericDatasetReader::getReader() {
return this->ownDatasetReaderPtr;
case PRINCETON:
return this->princetonDatasetReaderPtr;
case TRAFFICSENSORGT:
return this->trafficSensorGTDatasetReaderPtr;
case TRAFFICSENSOROUTPUT:
return this->trafficSensorOutputDatasetReaderPtr;
default:
LOG(WARNING)<<imp + " is not a valid reader implementation";
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
#include <DatasetConverters/readers/DatasetReader.h>
#include "OwnDatasetReader.h"
#include "PrincetonDatasetReader.h"
#include "TrafficSensorGTDatasetReader.h"
#include "TrafficSensorOutputDatasetReader.h"
#include "SamplesReader.h"


enum READER_IMPLEMENTATIONS{OWN, SPINELLO, PASCALVOC, COCO, IMAGENET, YOLO_1, PRINCETON, OPENIMAGES};
enum READER_IMPLEMENTATIONS{OWN, SPINELLO, PASCALVOC, COCO, IMAGENET, YOLO_1, PRINCETON, OPENIMAGES, TRAFFICSENSORGT, TRAFFICSENSOROUTPUT};


class GenericDatasetReader {
Expand All @@ -40,6 +42,8 @@ class GenericDatasetReader {
COCODatasetReaderPtr cocoDatasetReaderPtr;
ImageNetDatasetReaderPtr imagenetDatasetReaderPtr;
OpenImagesDatasetReaderPtr openimagesDatasetReaderPtr;
TrafficSensorGTDatasetReaderPtr trafficSensorGTDatasetReaderPtr;
TrafficSensorOutputDatasetReaderPtr trafficSensorOutputDatasetReaderPtr;
SamplesReaderPtr samplesReaderPtr;

std::vector<std::string> availableImplementations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ bool ImageNetDatasetReader::appendDataset(const std::string &datasetPath, const
boost::filesystem::path boostDatasetPath(datasetPath);

if (!boost::filesystem::is_directory(boostDatasetPath)) {
throw std::invalid_argument("Invalid File received for Imagenet Parser");
throw std::invalid_argument("Invalid File received for ImageNet Parser");
}


path img_dir;

if (imagesRequired) {
Expand All @@ -87,14 +86,11 @@ bool ImageNetDatasetReader::appendDataset(const std::string &datasetPath, const
} else {
LOG(WARNING) << "Corresponding Image Directory, can't be located, Skipping" << '\n';
}

}


boost::filesystem::directory_iterator end_itr;
for (boost::filesystem::directory_iterator itr(boostDatasetPath); itr!=end_itr; ++itr)
{
if (!boost::filesystem::is_directory(*itr)){
for (boost::filesystem::directory_iterator itr(boostDatasetPath); itr!=end_itr; ++itr) {
if (!boost::filesystem::is_directory(*itr)) {
LOG(INFO) << itr->path().string() << '\n';
boost::property_tree::ptree tree;

Expand All @@ -105,23 +101,18 @@ bool ImageNetDatasetReader::appendDataset(const std::string &datasetPath, const
std::string m_width = tree.get<std::string>("annotation.size.width");
std::string m_height = tree.get<std::string>("annotation.size.height");




Sample sample;
sample.setSampleID(m_filename);

if (imagesRequired) {
std::string imgPath = img_dir.string() + "/" + m_filename + ".JPEG";
sample.setColorImagePath(imgPath);

}


RectRegionsPtr rectRegions(new RectRegions());

BOOST_FOREACH(boost::property_tree::ptree::value_type &v, tree.get_child("annotation")) {
// The data function is used to access the data stored in a node.
// The data function is used to access the data stored in a node.
if (v.first == "object") {
std::string object_name = v.second.get<std::string>("name");
int xmin = v.second.get<int>("bndbox.xmin");
Expand All @@ -131,13 +122,11 @@ bool ImageNetDatasetReader::appendDataset(const std::string &datasetPath, const

cv::Rect bounding(xmin, ymin, xmax - xmin, ymax - ymin);
rectRegions->add(bounding,object_name);

}
}

sample.setRectRegions(rectRegions);
this->samples.push_back(sample);

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,18 @@ OwnDatasetReader::OwnDatasetReader(const std::string &path,const std::string& cl
appendDataset(path);
}

OwnDatasetReader::OwnDatasetReader(const bool imagesRequired):DatasetReader(imagesRequired) {

}
OwnDatasetReader::OwnDatasetReader(const bool imagesRequired):DatasetReader(imagesRequired) {}

bool OwnDatasetReader::appendDataset(const std::string &datasetPath, const std::string &datasetPrefix) {
boost::filesystem::directory_iterator end_itr;
boost::filesystem::path boostPath(datasetPath);


std::vector<std::string> filesID;

for (boost::filesystem::directory_iterator itr(boostPath); itr!=end_itr; ++itr)
{
if ((is_regular_file(itr->status()) && itr->path().extension()==".json") && (itr->path().string().find("-region") == std::string::npos)) {
filesID.push_back(itr->path().filename().stem().string());
}

}

std::sort(filesID.begin(),filesID.end());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
#include <DatasetConverters/readers/DatasetReader.h>

class OwnDatasetReader:public DatasetReader {
public:
OwnDatasetReader(const std::string& path,const std::string& classNamesFile, const bool imagesRequired);
OwnDatasetReader(const bool imagesRequired);
bool appendDataset(const std::string& datasetPath, const std::string& datasetPrefix="");
private:

public:
OwnDatasetReader(const std::string& path,const std::string& classNamesFile, const bool imagesRequired);
OwnDatasetReader(const bool imagesRequired);
bool appendDataset(const std::string& datasetPath, const std::string& datasetPrefix="");
private:
};


typedef boost::shared_ptr<OwnDatasetReader> OwnDatasetReaderPtr;


#endif //SAMPLERGENERATOR_OWNDATASETREADER_H
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@ class PrincetonDatasetReader: public DatasetReader {

typedef boost::shared_ptr<PrincetonDatasetReader> PrincetonDatasetReaderPtr;



#endif //SAMPLERGENERATOR_PRINCETONDATASETREADER_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <boost/filesystem.hpp>
#include <glog/logging.h>
#include <boost/lexical_cast.hpp>
#include "DatasetConverters/readers/TrafficSensorGTDatasetReader.h"

TrafficSensorGTDatasetReader::TrafficSensorGTDatasetReader(const std::string &path,const std::string& classNamesFile,const bool imagesRequired):DatasetReader(imagesRequired){
this->classNamesFile=classNamesFile;
appendDataset(path);
}

TrafficSensorGTDatasetReader::TrafficSensorGTDatasetReader(const bool imagesRequired):DatasetReader(imagesRequired) {}

bool TrafficSensorGTDatasetReader::appendDataset(const std::string &datasetPath, const std::string &datasetPrefix) {
boost::filesystem::directory_iterator end_itr;
boost::filesystem::path boostPath(datasetPath);
std::vector<std::string> filesID;


for (boost::filesystem::directory_iterator itr(boostPath); itr!=end_itr; ++itr)
{
if ((is_regular_file(itr->status()) && itr->path().extension()==".xml") && (itr->path().string().find("-region") == std::string::npos)) {
filesID.push_back(itr->path().string());
}
}

std::sort(filesID.begin(),filesID.end());

for (auto it = filesID.begin(), end=filesID.end(); it != end; ++it) {

Sample sample;
sample.setSampleID(datasetPrefix + boost::filesystem::path(*it).filename().stem().string());

boost::property_tree::ptree tree;
boost::property_tree::read_xml(boost::filesystem::path(*it).string(), tree);

RectRegionsPtr rectRegions(new RectRegions());

std::string m_folder = tree.get<std::string>("annotation.folder");
std::string m_filename = tree.get<std::string>("annotation.filename");
std::string m_path = tree.get<std::string>("annotation.path");

BOOST_FOREACH(boost::property_tree::ptree::value_type &v, tree.get_child("annotation")) {
// The data function is used to access the data stored in a node.
if (v.first == "object") {
std::string object_name = v.second.get<std::string>("name");
int xmin = v.second.get<int>("bndbox.xmin");
int xmax = v.second.get<int>("bndbox.xmax");
int ymin = v.second.get<int>("bndbox.ymin");
int ymax = v.second.get<int>("bndbox.ymax");

cv::Rect bounding(xmin, ymin, xmax - xmin, ymax - ymin);
rectRegions->add(bounding, object_name);
sample.setRectRegions(rectRegions);
}
}

this->samples.push_back(sample);
}

LOG(INFO) << "Loaded: " + boost::lexical_cast<std::string>(this->samples.size()) + " samples";
printDatasetStats();
return true;
}
Loading