1
0

darknet.h 19 KB

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