darknet.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. #ifndef DARKNET_API
  2. #define DARKNET_API
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <pthread.h>
  7. #include <time.h>
  8. #ifdef GPU
  9. #define BLOCK 512
  10. #include "cuda_runtime.h"
  11. #include "curand.h"
  12. #include "cublas_v2.h"
  13. #ifdef CUDNN
  14. #include "cudnn.h"
  15. #endif
  16. #endif
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #define SECRET_NUM -1234
  21. extern int gpu_index;
  22. typedef struct{
  23. int classes;
  24. char **names;
  25. } metadata;
  26. metadata get_metadata(char *file);
  27. typedef struct{
  28. int *leaf;
  29. int n;
  30. int *parent;
  31. int *child;
  32. int *group;
  33. char **name;
  34. int groups;
  35. int *group_size;
  36. int *group_offset;
  37. } tree;
  38. tree *read_tree(char *filename);
  39. typedef enum{
  40. LOGISTIC, RELU, RELIE, LINEAR, RAMP, TANH, PLSE, LEAKY, ELU, LOGGY, STAIR, HARDTAN, LHTAN, SELU
  41. } ACTIVATION;
  42. typedef enum{
  43. PNG, BMP, TGA, JPG
  44. } IMTYPE;
  45. typedef enum{
  46. MULT, ADD, SUB, DIV
  47. } BINARY_ACTIVATION;
  48. typedef enum {
  49. CONVOLUTIONAL,
  50. DECONVOLUTIONAL,
  51. CONNECTED,
  52. MAXPOOL,
  53. SOFTMAX,
  54. DETECTION,
  55. DROPOUT,
  56. CROP,
  57. ROUTE,
  58. COST,
  59. NORMALIZATION,
  60. AVGPOOL,
  61. LOCAL,
  62. SHORTCUT,
  63. ACTIVE,
  64. RNN,
  65. GRU,
  66. LSTM,
  67. CRNN,
  68. BATCHNORM,
  69. NETWORK,
  70. XNOR,
  71. REGION,
  72. YOLO,
  73. ISEG,
  74. REORG,
  75. UPSAMPLE,
  76. LOGXENT,
  77. L2NORM,
  78. BLANK
  79. } LAYER_TYPE;
  80. typedef enum{
  81. SSE, MASKED, L1, SEG, SMOOTH,WGAN
  82. } COST_TYPE;
  83. typedef struct{
  84. int batch;
  85. float learning_rate;
  86. float momentum;
  87. float decay;
  88. int adam;
  89. float B1;
  90. float B2;
  91. float eps;
  92. int t;
  93. } update_args;
  94. struct network;
  95. typedef struct network network;
  96. struct layer;
  97. typedef struct layer layer;
  98. struct layer{
  99. LAYER_TYPE type;
  100. ACTIVATION activation;
  101. COST_TYPE cost_type;
  102. void (*forward) (struct layer, struct network);
  103. void (*backward) (struct layer, struct network);
  104. void (*update) (struct layer, update_args);
  105. void (*forward_gpu) (struct layer, struct network);
  106. void (*backward_gpu) (struct layer, struct network);
  107. void (*update_gpu) (struct layer, update_args);
  108. int batch_normalize;
  109. int shortcut;
  110. int batch;
  111. int forced;
  112. int flipped;
  113. int inputs;
  114. int outputs;
  115. int nweights;
  116. int nbiases;
  117. int extra;
  118. int truths;
  119. int h,w,c;
  120. int out_h, out_w, out_c;
  121. int n;
  122. int max_boxes;
  123. int groups;
  124. int size;
  125. int side;
  126. int stride;
  127. int reverse;
  128. int flatten;
  129. int spatial;
  130. int pad;
  131. int sqrt;
  132. int flip;
  133. int index;
  134. int binary;
  135. int xnor;
  136. int steps;
  137. int hidden;
  138. int truth;
  139. float smooth;
  140. float dot;
  141. float angle;
  142. float jitter;
  143. float saturation;
  144. float exposure;
  145. float shift;
  146. float ratio;
  147. float learning_rate_scale;
  148. float clip;
  149. int noloss;
  150. int softmax;
  151. int classes;
  152. int coords;
  153. int background;
  154. int rescore;
  155. int objectness;
  156. int joint;
  157. int noadjust;
  158. int reorg;
  159. int log;
  160. int tanh;
  161. int *mask;
  162. int total;
  163. float alpha;
  164. float beta;
  165. float kappa;
  166. float coord_scale;
  167. float object_scale;
  168. float noobject_scale;
  169. float mask_scale;
  170. float class_scale;
  171. int bias_match;
  172. int random;
  173. float ignore_thresh;
  174. float truth_thresh;
  175. float thresh;
  176. float focus;
  177. int classfix;
  178. int absolute;
  179. int onlyforward;
  180. int stopbackward;
  181. int dontload;
  182. int dontsave;
  183. int dontloadscales;
  184. int numload;
  185. float temperature;
  186. float probability;
  187. float scale;
  188. char * cweights;
  189. int * indexes;
  190. int * input_layers;
  191. int * input_sizes;
  192. int * map;
  193. int * counts;
  194. float ** sums;
  195. float * rand;
  196. float * cost;
  197. float * state;
  198. float * prev_state;
  199. float * forgot_state;
  200. float * forgot_delta;
  201. float * state_delta;
  202. float * combine_cpu;
  203. float * combine_delta_cpu;
  204. float * concat;
  205. float * concat_delta;
  206. float * binary_weights;
  207. float * biases;
  208. float * bias_updates;
  209. float * scales;
  210. float * scale_updates;
  211. float * weights;
  212. float * weight_updates;
  213. float * delta;
  214. float * output;
  215. float * loss;
  216. float * squared;
  217. float * norms;
  218. float * spatial_mean;
  219. float * mean;
  220. float * variance;
  221. float * mean_delta;
  222. float * variance_delta;
  223. float * rolling_mean;
  224. float * rolling_variance;
  225. float * x;
  226. float * x_norm;
  227. float * m;
  228. float * v;
  229. float * bias_m;
  230. float * bias_v;
  231. float * scale_m;
  232. float * scale_v;
  233. float *z_cpu;
  234. float *r_cpu;
  235. float *h_cpu;
  236. float * prev_state_cpu;
  237. float *temp_cpu;
  238. float *temp2_cpu;
  239. float *temp3_cpu;
  240. float *dh_cpu;
  241. float *hh_cpu;
  242. float *prev_cell_cpu;
  243. float *cell_cpu;
  244. float *f_cpu;
  245. float *i_cpu;
  246. float *g_cpu;
  247. float *o_cpu;
  248. float *c_cpu;
  249. float *dc_cpu;
  250. float * binary_input;
  251. struct layer *input_layer;
  252. struct layer *self_layer;
  253. struct layer *output_layer;
  254. struct layer *reset_layer;
  255. struct layer *update_layer;
  256. struct layer *state_layer;
  257. struct layer *input_gate_layer;
  258. struct layer *state_gate_layer;
  259. struct layer *input_save_layer;
  260. struct layer *state_save_layer;
  261. struct layer *input_state_layer;
  262. struct layer *state_state_layer;
  263. struct layer *input_z_layer;
  264. struct layer *state_z_layer;
  265. struct layer *input_r_layer;
  266. struct layer *state_r_layer;
  267. struct layer *input_h_layer;
  268. struct layer *state_h_layer;
  269. struct layer *wz;
  270. struct layer *uz;
  271. struct layer *wr;
  272. struct layer *ur;
  273. struct layer *wh;
  274. struct layer *uh;
  275. struct layer *uo;
  276. struct layer *wo;
  277. struct layer *uf;
  278. struct layer *wf;
  279. struct layer *ui;
  280. struct layer *wi;
  281. struct layer *ug;
  282. struct layer *wg;
  283. tree *softmax_tree;
  284. size_t workspace_size;
  285. #ifdef GPU
  286. int *indexes_gpu;
  287. float *z_gpu;
  288. float *r_gpu;
  289. float *h_gpu;
  290. float *temp_gpu;
  291. float *temp2_gpu;
  292. float *temp3_gpu;
  293. float *dh_gpu;
  294. float *hh_gpu;
  295. float *prev_cell_gpu;
  296. float *cell_gpu;
  297. float *f_gpu;
  298. float *i_gpu;
  299. float *g_gpu;
  300. float *o_gpu;
  301. float *c_gpu;
  302. float *dc_gpu;
  303. float *m_gpu;
  304. float *v_gpu;
  305. float *bias_m_gpu;
  306. float *scale_m_gpu;
  307. float *bias_v_gpu;
  308. float *scale_v_gpu;
  309. float * combine_gpu;
  310. float * combine_delta_gpu;
  311. float * prev_state_gpu;
  312. float * forgot_state_gpu;
  313. float * forgot_delta_gpu;
  314. float * state_gpu;
  315. float * state_delta_gpu;
  316. float * gate_gpu;
  317. float * gate_delta_gpu;
  318. float * save_gpu;
  319. float * save_delta_gpu;
  320. float * concat_gpu;
  321. float * concat_delta_gpu;
  322. float * binary_input_gpu;
  323. float * binary_weights_gpu;
  324. float * mean_gpu;
  325. float * variance_gpu;
  326. float * rolling_mean_gpu;
  327. float * rolling_variance_gpu;
  328. float * variance_delta_gpu;
  329. float * mean_delta_gpu;
  330. float * x_gpu;
  331. float * x_norm_gpu;
  332. float * weights_gpu;
  333. float * weight_updates_gpu;
  334. float * weight_change_gpu;
  335. float * biases_gpu;
  336. float * bias_updates_gpu;
  337. float * bias_change_gpu;
  338. float * scales_gpu;
  339. float * scale_updates_gpu;
  340. float * scale_change_gpu;
  341. float * output_gpu;
  342. float * loss_gpu;
  343. float * delta_gpu;
  344. float * rand_gpu;
  345. float * squared_gpu;
  346. float * norms_gpu;
  347. #ifdef CUDNN
  348. cudnnTensorDescriptor_t srcTensorDesc, dstTensorDesc;
  349. cudnnTensorDescriptor_t dsrcTensorDesc, ddstTensorDesc;
  350. cudnnTensorDescriptor_t normTensorDesc;
  351. cudnnFilterDescriptor_t weightDesc;
  352. cudnnFilterDescriptor_t dweightDesc;
  353. cudnnConvolutionDescriptor_t convDesc;
  354. cudnnConvolutionFwdAlgo_t fw_algo;
  355. cudnnConvolutionBwdDataAlgo_t bd_algo;
  356. cudnnConvolutionBwdFilterAlgo_t bf_algo;
  357. #endif
  358. #endif
  359. };
  360. void free_layer(layer);
  361. typedef enum {
  362. CONSTANT, STEP, EXP, POLY, STEPS, SIG, RANDOM
  363. } learning_rate_policy;
  364. typedef struct network{
  365. int n;
  366. int batch;
  367. size_t *seen;
  368. int *t;
  369. float epoch;
  370. int subdivisions;
  371. layer *layers;
  372. float *output;
  373. learning_rate_policy policy;
  374. float learning_rate;
  375. float momentum;
  376. float decay;
  377. float gamma;
  378. float scale;
  379. float power;
  380. int time_steps;
  381. int step;
  382. int max_batches;
  383. float *scales;
  384. int *steps;
  385. int num_steps;
  386. int burn_in;
  387. int adam;
  388. float B1;
  389. float B2;
  390. float eps;
  391. int inputs;
  392. int outputs;
  393. int truths;
  394. int notruth;
  395. int h, w, c;
  396. int max_crop;
  397. int min_crop;
  398. float max_ratio;
  399. float min_ratio;
  400. int center;
  401. float angle;
  402. float aspect;
  403. float exposure;
  404. float saturation;
  405. float hue;
  406. int random;
  407. int gpu_index;
  408. tree *hierarchy;
  409. float *input;
  410. float *truth;
  411. float *delta;
  412. float *workspace;
  413. int train;
  414. int index;
  415. float *cost;
  416. float clip;
  417. #ifdef GPU
  418. float *input_gpu;
  419. float *truth_gpu;
  420. float *delta_gpu;
  421. float *output_gpu;
  422. #endif
  423. } network;
  424. typedef struct {
  425. int w;
  426. int h;
  427. float scale;
  428. float rad;
  429. float dx;
  430. float dy;
  431. float aspect;
  432. } augment_args;
  433. typedef struct {
  434. int w;
  435. int h;
  436. int c;
  437. float *data;
  438. } image;
  439. typedef struct{
  440. float x, y, w, h;
  441. } box;
  442. typedef struct detection{
  443. box bbox;
  444. int classes;
  445. float *prob;
  446. float *mask;
  447. float objectness;
  448. int sort_class;
  449. } detection;
  450. typedef struct matrix{
  451. int rows, cols;
  452. float **vals;
  453. } matrix;
  454. typedef struct{
  455. int w, h;
  456. matrix X;
  457. matrix y;
  458. int shallow;
  459. int *num_boxes;
  460. box **boxes;
  461. } data;
  462. typedef enum {
  463. 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, ISEG_DATA
  464. } data_type;
  465. typedef struct load_args{
  466. int threads;
  467. char **paths;
  468. char *path;
  469. int n;
  470. int m;
  471. char **labels;
  472. int h;
  473. int w;
  474. int out_w;
  475. int out_h;
  476. int nh;
  477. int nw;
  478. int num_boxes;
  479. int min, max, size;
  480. int classes;
  481. int background;
  482. int scale;
  483. int center;
  484. int coords;
  485. float jitter;
  486. float angle;
  487. float aspect;
  488. float saturation;
  489. float exposure;
  490. float hue;
  491. data *d;
  492. image *im;
  493. image *resized;
  494. data_type type;
  495. tree *hierarchy;
  496. } load_args;
  497. typedef struct{
  498. int id;
  499. float x,y,w,h;
  500. float left, right, top, bottom;
  501. } box_label;
  502. network *load_network(char *cfg, char *weights, int clear);
  503. load_args get_base_args(network *net);
  504. void free_data(data d);
  505. typedef struct node{
  506. void *val;
  507. struct node *next;
  508. struct node *prev;
  509. } node;
  510. typedef struct list{
  511. int size;
  512. node *front;
  513. node *back;
  514. } list;
  515. pthread_t load_data(load_args args);
  516. list *read_data_cfg(char *filename);
  517. list *read_cfg(char *filename);
  518. unsigned char *read_file(char *filename);
  519. data resize_data(data orig, int w, int h);
  520. data *tile_data(data orig, int divs, int size);
  521. data select_data(data *orig, int *inds);
  522. void forward_network(network *net);
  523. void backward_network(network *net);
  524. void update_network(network *net);
  525. float dot_cpu(int N, float *X, int INCX, float *Y, int INCY);
  526. void axpy_cpu(int N, float ALPHA, float *X, int INCX, float *Y, int INCY);
  527. void copy_cpu(int N, float *X, int INCX, float *Y, int INCY);
  528. void scal_cpu(int N, float ALPHA, float *X, int INCX);
  529. void fill_cpu(int N, float ALPHA, float * X, int INCX);
  530. void normalize_cpu(float *x, float *mean, float *variance, int batch, int filters, int spatial);
  531. void softmax(float *input, int n, float temp, int stride, float *output);
  532. int best_3d_shift_r(image a, image b, int min, int max);
  533. #ifdef GPU
  534. void axpy_gpu(int N, float ALPHA, float * X, int INCX, float * Y, int INCY);
  535. void fill_gpu(int N, float ALPHA, float * X, int INCX);
  536. void scal_gpu(int N, float ALPHA, float * X, int INCX);
  537. void copy_gpu(int N, float * X, int INCX, float * Y, int INCY);
  538. void cuda_set_device(int n);
  539. void cuda_free(float *x_gpu);
  540. float *cuda_make_array(float *x, size_t n);
  541. void cuda_pull_array(float *x_gpu, float *x, size_t n);
  542. float cuda_mag_array(float *x_gpu, size_t n);
  543. void cuda_push_array(float *x_gpu, float *x, size_t n);
  544. void forward_network_gpu(network *net);
  545. void backward_network_gpu(network *net);
  546. void update_network_gpu(network *net);
  547. float train_networks(network **nets, int n, data d, int interval);
  548. void sync_nets(network **nets, int n, int interval);
  549. void harmless_update_network_gpu(network *net);
  550. #endif
  551. image get_label(image **characters, char *string, int size);
  552. void draw_label(image a, int r, int c, image label, const float *rgb);
  553. void save_image(image im, const char *name);
  554. void save_image_options(image im, const char *name, IMTYPE f, int quality);
  555. void get_next_batch(data d, int n, int offset, float *X, float *y);
  556. void grayscale_image_3c(image im);
  557. void normalize_image(image p);
  558. void matrix_to_csv(matrix m);
  559. float train_network_sgd(network *net, data d, int n);
  560. void rgbgr_image(image im);
  561. data copy_data(data d);
  562. data concat_data(data d1, data d2);
  563. data load_cifar10_data(char *filename);
  564. float matrix_topk_accuracy(matrix truth, matrix guess, int k);
  565. void matrix_add_matrix(matrix from, matrix to);
  566. void scale_matrix(matrix m, float scale);
  567. matrix csv_to_matrix(char *filename);
  568. float *network_accuracies(network *net, data d, int n);
  569. float train_network_datum(network *net);
  570. image make_random_image(int w, int h, int c);
  571. void denormalize_connected_layer(layer l);
  572. void denormalize_convolutional_layer(layer l);
  573. void statistics_connected_layer(layer l);
  574. void rescale_weights(layer l, float scale, float trans);
  575. void rgbgr_weights(layer l);
  576. image *get_weights(layer l);
  577. void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, int classes, int frame_skip, char *prefix, int avg, float hier_thresh, int w, int h, int fps, int fullscreen);
  578. void get_detection_detections(layer l, int w, int h, float thresh, detection *dets);
  579. char *option_find_str(list *l, char *key, char *def);
  580. int option_find_int(list *l, char *key, int def);
  581. int option_find_int_quiet(list *l, char *key, int def);
  582. network *parse_network_cfg(char *filename);
  583. void save_weights(network *net, char *filename);
  584. void load_weights(network *net, char *filename);
  585. void save_weights_upto(network *net, char *filename, int cutoff);
  586. void load_weights_upto(network *net, char *filename, int start, int cutoff);
  587. void zero_objectness(layer l);
  588. void get_region_detections(layer l, int w, int h, int netw, int neth, float thresh, int *map, float tree_thresh, int relative, detection *dets);
  589. int get_yolo_detections(layer l, int w, int h, int netw, int neth, float thresh, int *map, int relative, detection *dets);
  590. void free_network(network *net);
  591. void set_batch_network(network *net, int b);
  592. void set_temp_network(network *net, float t);
  593. image load_image(char *filename, int w, int h, int c);
  594. image load_image_color(char *filename, int w, int h);
  595. image make_image(int w, int h, int c);
  596. image resize_image(image im, int w, int h);
  597. void censor_image(image im, int dx, int dy, int w, int h);
  598. image letterbox_image(image im, int w, int h);
  599. image crop_image(image im, int dx, int dy, int w, int h);
  600. image center_crop_image(image im, int w, int h);
  601. image resize_min(image im, int min);
  602. image resize_max(image im, int max);
  603. image threshold_image(image im, float thresh);
  604. image mask_to_rgb(image mask);
  605. int resize_network(network *net, int w, int h);
  606. void free_matrix(matrix m);
  607. void test_resize(char *filename);
  608. int show_image(image p, const char *name, int ms);
  609. image copy_image(image p);
  610. void draw_box_width(image a, int x1, int y1, int x2, int y2, int w, float r, float g, float b);
  611. float get_current_rate(network *net);
  612. void composite_3d(char *f1, char *f2, char *out, int delta);
  613. data load_data_old(char **paths, int n, int m, char **labels, int k, int w, int h);
  614. size_t get_current_batch(network *net);
  615. void constrain_image(image im);
  616. image get_network_image_layer(network *net, int i);
  617. layer get_network_output_layer(network *net);
  618. void top_predictions(network *net, int n, int *index);
  619. void flip_image(image a);
  620. image float_to_image(int w, int h, int c, float *data);
  621. void ghost_image(image source, image dest, int dx, int dy);
  622. float network_accuracy(network *net, data d);
  623. void random_distort_image(image im, float hue, float saturation, float exposure);
  624. void fill_image(image m, float s);
  625. image grayscale_image(image im);
  626. void rotate_image_cw(image im, int times);
  627. double what_time_is_it_now();
  628. image rotate_image(image m, float rad);
  629. void visualize_network(network *net);
  630. float box_iou(box a, box b);
  631. data load_all_cifar10();
  632. box_label *read_boxes(char *filename, int *n);
  633. box float_to_box(float *f, int stride);
  634. void draw_detections(image im, detection *dets, int num, float thresh, char **names, image **alphabet, int classes);
  635. matrix network_predict_data(network *net, data test);
  636. image **load_alphabet();
  637. image get_network_image(network *net);
  638. float *network_predict(network *net, float *input);
  639. int network_width(network *net);
  640. int network_height(network *net);
  641. float *network_predict_image(network *net, image im);
  642. void network_detect(network *net, image im, float thresh, float hier_thresh, float nms, detection *dets);
  643. detection *get_network_boxes(network *net, int w, int h, float thresh, float hier, int *map, int relative, int *num);
  644. void free_detections(detection *dets, int n);
  645. void reset_network_state(network *net, int b);
  646. char **get_labels(char *filename);
  647. void do_nms_obj(detection *dets, int total, int classes, float thresh);
  648. void do_nms_sort(detection *dets, int total, int classes, float thresh);
  649. matrix make_matrix(int rows, int cols);
  650. #ifdef OPENCV
  651. void *open_video_stream(const char *f, int c, int w, int h, int fps);
  652. image get_image_from_stream(void *p);
  653. void make_window(char *name, int w, int h, int fullscreen);
  654. #endif
  655. void free_image(image m);
  656. float train_network(network *net, data d);
  657. pthread_t load_data_in_thread(load_args args);
  658. void load_data_blocking(load_args args);
  659. list *get_paths(char *filename);
  660. void hierarchy_predictions(float *predictions, int n, tree *hier, int only_leaves, int stride);
  661. void change_leaves(tree *t, char *leaf_list);
  662. int find_int_arg(int argc, char **argv, char *arg, int def);
  663. float find_float_arg(int argc, char **argv, char *arg, float def);
  664. int find_arg(int argc, char* argv[], char *arg);
  665. char *find_char_arg(int argc, char **argv, char *arg, char *def);
  666. char *basecfg(char *cfgfile);
  667. void find_replace(char *str, char *orig, char *rep, char *output);
  668. void free_ptrs(void **ptrs, int n);
  669. char *fgetl(FILE *fp);
  670. void strip(char *s);
  671. float sec(clock_t clocks);
  672. void **list_to_array(list *l);
  673. void top_k(float *a, int n, int k, int *index);
  674. int *read_map(char *filename);
  675. void error(const char *s);
  676. int max_index(float *a, int n);
  677. int max_int_index(int *a, int n);
  678. int sample_array(float *a, int n);
  679. int *random_index_order(int min, int max);
  680. void free_list(list *l);
  681. float mse_array(float *a, int n);
  682. float variance_array(float *a, int n);
  683. float mag_array(float *a, int n);
  684. void scale_array(float *a, int n, float s);
  685. float mean_array(float *a, int n);
  686. float sum_array(float *a, int n);
  687. void normalize_array(float *a, int n);
  688. int *read_intlist(char *s, int *n, int d);
  689. size_t rand_size_t();
  690. float rand_normal();
  691. float rand_uniform(float min, float max);
  692. #ifdef __cplusplus
  693. }
  694. #endif
  695. #endif