forked from btgraham/SparseConvNet-archived
/
SpatiallySparseDatasetKagglePlankton.cpp
52 lines (50 loc) · 1.52 KB
/
SpatiallySparseDatasetKagglePlankton.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "SpatiallySparseDatasetKagglePlankton.h"
#include<iostream>
#include<fstream>
#include<string>
#include "utilities.h"
KagglePlanktonLabeledDataSet::KagglePlanktonLabeledDataSet
(std::string classesListFile, std::string dataDirectory, batchType type_, int backgroundCol) {
name=dataDirectory;
type=type_;
{
std::ifstream f(classesListFile.c_str());
std::string cl;
int ctr=0;
while (f >> cl)
classes[cl]=ctr++;
}
nClasses=classes.size();
for (auto &kv : classes) {
for (auto &file : globVector(dataDirectory+kv.first+"/*.jpg")) {
OpenCVPicture* pic = new OpenCVPicture(file,-1,backgroundCol,kv.second);
pic->loadDataWithoutScaling();
nFeatures=pic->mat.channels();
pic->scale=powf(powf(pic->mat.rows,2)+powf(pic->mat.cols,2),0.5);
pictures.push_back(pic);
}
}
}
KagglePlanktonUnlabeledDataSet::KagglePlanktonUnlabeledDataSet
(std::string classesListFile, std::string dataDirectory, int backgroundCol) {
name=dataDirectory;
header="image";
type=UNLABELEDBATCH;
{
std::ifstream f(classesListFile.c_str());
std::string cl;
int ctr=0;
while (f >> cl) {
classes[cl]=ctr++;
header=header+","+cl;
}
}
nClasses=classes.size();
for (auto &file : globVector(std::string(dataDirectory+"*.jpg"))) {
OpenCVPicture* pic = new OpenCVPicture(file,-1,backgroundCol,0);
pic->loadDataWithoutScaling();
nFeatures=pic->mat.channels();
pic->scale=powf(powf(pic->mat.rows,2)+powf(pic->mat.cols,2),0.5);
pictures.push_back(pic);
}
}