You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
179 lines
5.8 KiB
179 lines
5.8 KiB
#ifndef __CORTEX_DATA_HEADER__
|
|
#define __CORTEX_DATA_HEADER__
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "basicUtils.h"
|
|
#include "basicImage.h"
|
|
#include "basicBox.h"
|
|
|
|
#define SECRET_NUM -1234
|
|
|
|
//#include "dn_cuda.h"
|
|
#ifndef MUTEX_HANDLE_TYPE
|
|
#ifdef __linux__
|
|
// Linux impl.
|
|
#include <pthread.h>
|
|
|
|
#define MUTEX_HANDLE_TYPE pthread_mutex_t
|
|
#define MUTEX_INIT( X ) pthread_mutex_init( &X, NULL )
|
|
#define MUTEX_LOCK( X ) pthread_mutex_lock( &X )
|
|
#define MUTEX_TRY_LOCK( X ) pthread_mutex_trylock( &X )
|
|
#define MUTEX_UNLOCK( X ) pthread_mutex_unlock( &X )
|
|
#define MUTEX_DESTROY( X ) pthread_mutex_destroy( &X )
|
|
#else
|
|
// Windows impl.
|
|
#include "Windows.h"
|
|
|
|
#define MUTEX_HANDLE_TYPE HANDLE
|
|
#define MUTEX_INIT( X ) X = CreateMutex( NULL, FALSE, NULL )
|
|
#define MUTEX_LOCK( X ) WaitForSingleObject( X, INFINITE )
|
|
#define MUTEX_TRY_LOCK( X ) (WaitForSingleObject( X, 0 )==WAIT_OBJECT_0)
|
|
#define MUTEX_UNLOCK( X ) ReleaseMutex( X )
|
|
#define MUTEX_DESTROY( X ) CloseHandle( X )
|
|
#endif
|
|
#endif
|
|
|
|
#include "basicMatrix.h"
|
|
#include "basicTree.h"
|
|
#include "basicImage.h"
|
|
|
|
class basicCortex;
|
|
|
|
typedef enum E_DATATYPE {
|
|
CLASSIFICATION_DATA, DETECTION_DATA, CAPTCHA_DATA, REGION_DATA, IMAGE_DATA, COMPARE_DATA, WRITING_DATA, SWAG_DATA, TAG_DATA, OLD_CLASSIFICATION_DATA, STUDY_DATA, DET_DATA, SUPER_DATA, LETTERBOX_DATA, REGRESSION_DATA, SEGMENTATION_DATA, INSTANCE_DATA
|
|
} cortexDATATYPE;
|
|
|
|
typedef struct S_network_state {
|
|
float *truth;
|
|
float *input;
|
|
float *delta;
|
|
float *workspace;
|
|
bool train;
|
|
int32_t index;
|
|
//struct S_network net;
|
|
basicCortex *net;
|
|
} cortexSTATE;
|
|
|
|
typedef struct S_DATA{
|
|
uint32_t width;
|
|
uint32_t height;
|
|
cortexMATRIX X;
|
|
cortexMATRIX Y;
|
|
bool bShallow;
|
|
int *indexes;
|
|
arrayBOX boxes;
|
|
} cortexDATA;
|
|
|
|
typedef struct S_THREAD_ARGS{
|
|
uint32_t threads;
|
|
cortexList *paths;
|
|
void *me;
|
|
char *path;
|
|
uint32_t n;
|
|
uint32_t m;
|
|
cortexList *labels;
|
|
uint32_t h;
|
|
uint32_t w;
|
|
uint32_t out_w;
|
|
uint32_t out_h;
|
|
uint32_t nh;
|
|
uint32_t nw;
|
|
uint32_t num_boxes;
|
|
uint32_t min, max, size;
|
|
uint32_t classes;
|
|
uint32_t background;
|
|
bool scale;
|
|
uint32_t center;
|
|
uint32_t coords;
|
|
float jitter;
|
|
float angle;
|
|
float aspect;
|
|
float saturation;
|
|
float exposure;
|
|
float hue;
|
|
cortexDATA *d;
|
|
cortexImage *im;
|
|
cortexImage *resized;
|
|
cortexDATATYPE type;
|
|
cortexTREE *hierarchy;
|
|
} cortexTHREAD_ARGS;
|
|
|
|
typedef enum E_ACTIVATION{
|
|
LOGISTIC, RELU, RELIE, LINEAR, RAMP, TANH, PLSE, LEAKY, ELU, LOGGY, STAIR, HARDTAN, LHTAN
|
|
} ACTIVATION;
|
|
|
|
typedef enum E_LAYER_TYPE{
|
|
CONVOLUTIONAL,
|
|
DECONVOLUTIONAL,
|
|
CONNECTED,
|
|
MAXPOOL,
|
|
SOFTMAX,
|
|
DETECTION,
|
|
DROPOUT,
|
|
CROP,
|
|
ROUTE,
|
|
COST,
|
|
NORMALIZATION,
|
|
AVGPOOL,
|
|
LOCAL,
|
|
SHORTCUT,
|
|
ACTIVE,
|
|
RNN,
|
|
GRU,
|
|
LSTM,
|
|
CRNN,
|
|
BATCHNORM,
|
|
NETWORK,
|
|
XNOR,
|
|
REGION,
|
|
REORG,
|
|
BLANK
|
|
} LAYER_TYPE;
|
|
|
|
typedef enum E_COST_TYPE{
|
|
SSE, MASKED, L1, SEG, SMOOTH
|
|
} COST_TYPE;
|
|
|
|
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;
|
|
};
|
|
|
|
void loadBlocking(cortexTHREAD_ARGS *args);
|
|
|
|
|
|
cortexList * get_paths( char *filename );
|
|
cortexDATA * load_data_captcha( cortexList *paths, uint32_t n, uint32_t m, uint32_t k, uint32_t w, uint32_t h );
|
|
cortexDATA * load_data_captcha_encode( cortexList *paths, uint32_t n, uint32_t m, uint32_t w, uint32_t h );
|
|
cortexDATA * load_data_detection( uint32_t n, cortexList *paths, uint32_t m, uint32_t w, uint32_t h, uint32_t boxes, uint32_t classes, float jitter, float hue, float saturation, float exposure );
|
|
cortexDATA * load_data_old( cortexList *paths, int m, cortexList *labels, int w, int h );
|
|
cortexDATA * load_data_tag( cortexList *paths, uint32_t m, uint32_t k, uint32_t min, uint32_t max, uint32_t size, float angle, float aspect, float hue, float saturation, float exposure );
|
|
cortexDATA * load_data_super( cortexList *paths, uint32_t m, uint32_t w, uint32_t h, uint32_t scale );
|
|
cortexDATA * load_data_augment( cortexList *paths, uint32_t m, cortexList *labels, cortexTREE *hierarchy, uint32_t min, uint32_t max, uint32_t size, float angle, float aspect, float hue, float saturation, float exposure, uint32_t center );
|
|
cortexDATA * load_data_regression( cortexList *paths, uint32_t m, uint32_t min, uint32_t max, uint32_t size, float angle, float aspect, float hue, float saturation, float exposure );
|
|
cortexDATA * load_go( char *filename );
|
|
cortexDATA * load_data_writing( cortexList *paths, uint32_t m, uint32_t w, uint32_t h, uint32_t out_w, uint32_t out_h );
|
|
cortexDATA * get_data_part( cortexDATA *d, uint32_t part, uint32_t total );
|
|
cortexDATA * get_random_data( cortexDATA *d, uint32_t num );
|
|
cortexDATA * load_categorical_data_csv( char *filename, uint32_t target, uint32_t k );
|
|
cortexDATA * split_data( cortexDATA *d, uint32_t part, uint32_t total );
|
|
cortexDATA * concat_datas( cortexDATA *d, uint32_t n );
|
|
cortexMATRIX * load_image_augment_paths( cortexList *paths, uint32_t min, uint32_t max, uint32_t size, float angle, float aspect, float hue, float saturation, float exposure, uint32_t center);
|
|
void get_random_batch( cortexDATA *d, uint32_t n, float *X, float *Y);
|
|
void normalize_data_rows( cortexDATA *d);
|
|
void scale_data_rows( cortexDATA *d, float s);
|
|
void translate_data_rows( cortexDATA *d, float s);
|
|
void randomize_data( cortexDATA *d);
|
|
void fill_truth( char *path, cortexList *labels, uint32_t k, float *truth );
|
|
void print_letters( float *pred, uint32_t n);
|
|
COST_TYPE get_cost_type(char *s);
|
|
char * get_cost_string(COST_TYPE a);
|
|
|
|
#endif
|