2013-11-13 22:50:38 +04:00
|
|
|
#ifndef DATA_H
|
|
|
|
#define DATA_H
|
2014-12-12 00:15:26 +03:00
|
|
|
#include <pthread.h>
|
2013-11-13 22:50:38 +04:00
|
|
|
|
2013-12-07 01:26:09 +04:00
|
|
|
#include "matrix.h"
|
2014-02-15 04:09:07 +04:00
|
|
|
#include "list.h"
|
2015-06-16 09:22:44 +03:00
|
|
|
#include "image.h"
|
2013-11-13 22:50:38 +04:00
|
|
|
|
2015-04-15 10:32:32 +03:00
|
|
|
extern unsigned int data_seed;
|
|
|
|
|
2015-04-01 20:25:50 +03:00
|
|
|
static inline float distance_from_edge(int x, int max)
|
|
|
|
{
|
|
|
|
int dx = (max/2) - x;
|
|
|
|
if (dx < 0) dx = -dx;
|
|
|
|
dx = (max/2) + 1 - dx;
|
|
|
|
dx *= 2;
|
|
|
|
float dist = (float)dx/max;
|
|
|
|
if (dist > 1) dist = 1;
|
|
|
|
return dist;
|
|
|
|
}
|
|
|
|
|
2013-11-13 22:50:38 +04:00
|
|
|
typedef struct{
|
2013-12-07 01:26:09 +04:00
|
|
|
matrix X;
|
|
|
|
matrix y;
|
|
|
|
int shallow;
|
|
|
|
} data;
|
2013-11-13 22:50:38 +04:00
|
|
|
|
2015-08-25 04:27:42 +03:00
|
|
|
typedef enum {
|
2015-09-23 02:36:57 +03:00
|
|
|
CLASSIFICATION_DATA, DETECTION_DATA, CAPTCHA_DATA, REGION_DATA, IMAGE_DATA, COMPARE_DATA, WRITING_DATA
|
2015-08-25 04:27:42 +03:00
|
|
|
} data_type;
|
|
|
|
|
|
|
|
typedef struct load_args{
|
|
|
|
char **paths;
|
|
|
|
char *path;
|
|
|
|
int n;
|
|
|
|
int m;
|
|
|
|
char **labels;
|
|
|
|
int h;
|
|
|
|
int w;
|
2015-09-24 00:13:43 +03:00
|
|
|
int out_w;
|
|
|
|
int out_h;
|
2015-08-25 04:27:42 +03:00
|
|
|
int nh;
|
|
|
|
int nw;
|
|
|
|
int num_boxes;
|
|
|
|
int classes;
|
|
|
|
int background;
|
|
|
|
data *d;
|
|
|
|
image *im;
|
|
|
|
image *resized;
|
|
|
|
data_type type;
|
|
|
|
} load_args;
|
2013-11-13 22:50:38 +04:00
|
|
|
|
2015-09-01 21:21:01 +03:00
|
|
|
typedef struct{
|
|
|
|
int id;
|
|
|
|
float x,y,w,h;
|
|
|
|
float left, right, top, bottom;
|
|
|
|
} box_label;
|
|
|
|
|
2013-12-07 01:26:09 +04:00
|
|
|
void free_data(data d);
|
2014-12-13 23:01:21 +03:00
|
|
|
|
2015-08-25 04:27:42 +03:00
|
|
|
pthread_t load_data_in_thread(load_args args);
|
|
|
|
|
2015-02-24 05:52:05 +03:00
|
|
|
void print_letters(float *pred, int n);
|
2015-04-10 01:18:54 +03:00
|
|
|
data load_data_captcha(char **paths, int n, int m, int k, int w, int h);
|
|
|
|
data load_data_captcha_encode(char **paths, int n, int m, int w, int h);
|
|
|
|
data load_data(char **paths, int n, int m, char **labels, int k, int w, int h);
|
2015-08-25 04:27:42 +03:00
|
|
|
data load_data_detection(int n, char **paths, int m, int classes, int w, int h, int num_boxes, int background);
|
2014-12-28 20:42:35 +03:00
|
|
|
|
2015-09-01 21:21:01 +03:00
|
|
|
box_label *read_boxes(char *filename, int *n);
|
2014-03-13 08:57:34 +04:00
|
|
|
data load_cifar10_data(char *filename);
|
2014-08-08 23:04:15 +04:00
|
|
|
data load_all_cifar10();
|
2015-04-10 01:18:54 +03:00
|
|
|
|
2015-09-24 00:13:43 +03:00
|
|
|
data load_data_writing(char **paths, int n, int m, int w, int h, int out_w, int out_h);
|
2015-05-25 21:53:10 +03:00
|
|
|
|
2014-02-15 04:09:07 +04:00
|
|
|
list *get_paths(char *filename);
|
2014-10-25 22:57:26 +04:00
|
|
|
char **get_labels(char *filename);
|
2014-10-28 05:45:06 +03:00
|
|
|
void get_random_batch(data d, int n, float *X, float *y);
|
|
|
|
void get_next_batch(data d, int n, int offset, float *X, float *y);
|
2013-12-07 01:26:09 +04:00
|
|
|
data load_categorical_data_csv(char *filename, int target, int k);
|
|
|
|
void normalize_data_rows(data d);
|
2014-02-14 22:26:31 +04:00
|
|
|
void scale_data_rows(data d, float s);
|
2014-07-14 09:07:51 +04:00
|
|
|
void translate_data_rows(data d, float s);
|
2013-12-07 01:26:09 +04:00
|
|
|
void randomize_data(data d);
|
2013-12-07 21:38:50 +04:00
|
|
|
data *split_data(data d, int part, int total);
|
2015-04-20 18:43:54 +03:00
|
|
|
data concat_data(data d1, data d2);
|
2013-11-13 22:50:38 +04:00
|
|
|
|
|
|
|
#endif
|