2013-11-04 23:11:01 +04:00
|
|
|
#include <time.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2015-03-06 21:49:03 +03:00
|
|
|
#include "parser.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "cuda.h"
|
|
|
|
|
2014-01-29 04:28:42 +04:00
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <fenv.h>
|
|
|
|
|
2015-03-06 21:49:03 +03:00
|
|
|
extern void run_imagenet(int argc, char **argv);
|
|
|
|
extern void run_detection(int argc, char **argv);
|
|
|
|
extern void run_captcha(int argc, char **argv);
|
2015-02-24 05:52:05 +03:00
|
|
|
|
2014-12-17 02:34:10 +03:00
|
|
|
void del_arg(int argc, char **argv, int index)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = index; i < argc-1; ++i) argv[i] = argv[i+1];
|
2015-02-07 05:53:53 +03:00
|
|
|
argv[i] = 0;
|
2014-12-17 02:34:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int find_arg(int argc, char* argv[], char *arg)
|
2014-12-08 22:48:57 +03:00
|
|
|
{
|
|
|
|
int i;
|
2015-02-07 05:53:53 +03:00
|
|
|
for(i = 0; i < argc; ++i) {
|
|
|
|
if(!argv[i]) continue;
|
|
|
|
if(0==strcmp(argv[i], arg)) {
|
|
|
|
del_arg(argc, argv, i);
|
|
|
|
return 1;
|
|
|
|
}
|
2014-12-17 02:34:10 +03:00
|
|
|
}
|
2014-12-08 22:48:57 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-17 02:34:10 +03:00
|
|
|
int find_int_arg(int argc, char **argv, char *arg, int def)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < argc-1; ++i){
|
2015-02-07 05:53:53 +03:00
|
|
|
if(!argv[i]) continue;
|
2014-12-17 02:34:10 +03:00
|
|
|
if(0==strcmp(argv[i], arg)){
|
|
|
|
def = atoi(argv[i+1]);
|
|
|
|
del_arg(argc, argv, i);
|
|
|
|
del_arg(argc, argv, i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
2015-03-08 21:25:28 +03:00
|
|
|
void change_rate(char *filename, float scale, float add)
|
2015-02-07 05:53:53 +03:00
|
|
|
{
|
|
|
|
// Ready for some weird shit??
|
|
|
|
FILE *fp = fopen(filename, "r+b");
|
|
|
|
if(!fp) file_error(filename);
|
|
|
|
float rate = 0;
|
|
|
|
fread(&rate, sizeof(float), 1, fp);
|
2015-03-08 21:25:28 +03:00
|
|
|
printf("Scaling learning rate from %f to %f\n", rate, rate*scale+add);
|
|
|
|
rate = rate*scale + add;
|
2015-02-07 05:53:53 +03:00
|
|
|
fseek(fp, 0, SEEK_SET);
|
|
|
|
fwrite(&rate, sizeof(float), 1, fp);
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
2015-03-08 21:25:28 +03:00
|
|
|
void partial(char *cfgfile, char *weightfile, char *outfile, int max)
|
|
|
|
{
|
|
|
|
network net = parse_network_cfg(cfgfile);
|
|
|
|
if(weightfile){
|
|
|
|
load_weights_upto(&net, weightfile, max);
|
|
|
|
}
|
2015-04-17 22:32:54 +03:00
|
|
|
net.seen = 0;
|
2015-03-08 21:25:28 +03:00
|
|
|
save_weights(net, outfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
void visualize(char *cfgfile, char *weightfile)
|
|
|
|
{
|
|
|
|
network net = parse_network_cfg(cfgfile);
|
|
|
|
if(weightfile){
|
|
|
|
load_weights(&net, weightfile);
|
|
|
|
}
|
|
|
|
visualize_network(net);
|
|
|
|
cvWaitKey(0);
|
|
|
|
}
|
|
|
|
|
2014-12-17 02:34:10 +03:00
|
|
|
int main(int argc, char **argv)
|
2014-11-22 02:35:19 +03:00
|
|
|
{
|
2015-04-24 20:27:50 +03:00
|
|
|
//test_box();
|
2015-01-23 03:38:24 +03:00
|
|
|
//test_convolutional_layer();
|
2014-11-22 02:35:19 +03:00
|
|
|
if(argc < 2){
|
|
|
|
fprintf(stderr, "usage: %s <function>\n", argv[0]);
|
|
|
|
return 0;
|
2014-08-08 23:04:15 +04:00
|
|
|
}
|
2014-12-17 02:34:10 +03:00
|
|
|
gpu_index = find_int_arg(argc, argv, "-i", 0);
|
|
|
|
if(find_arg(argc, argv, "-nogpu")) gpu_index = -1;
|
|
|
|
|
|
|
|
#ifndef GPU
|
|
|
|
gpu_index = -1;
|
|
|
|
#else
|
|
|
|
if(gpu_index >= 0){
|
2015-01-23 03:38:24 +03:00
|
|
|
cudaSetDevice(gpu_index);
|
2014-12-17 02:34:10 +03:00
|
|
|
}
|
2014-12-12 00:15:26 +03:00
|
|
|
#endif
|
2014-12-17 02:34:10 +03:00
|
|
|
|
2015-03-06 21:49:03 +03:00
|
|
|
if(0==strcmp(argv[1], "imagenet")){
|
2015-03-08 21:25:28 +03:00
|
|
|
run_imagenet(argc, argv);
|
2015-03-06 21:49:03 +03:00
|
|
|
} else if (0 == strcmp(argv[1], "detection")){
|
2015-03-08 21:25:28 +03:00
|
|
|
run_detection(argc, argv);
|
2015-04-14 00:09:55 +03:00
|
|
|
} else if (0 == strcmp(argv[1], "test")){
|
|
|
|
test_resize(argv[2]);
|
2015-03-06 21:49:03 +03:00
|
|
|
} else if (0 == strcmp(argv[1], "captcha")){
|
2015-03-08 21:25:28 +03:00
|
|
|
run_captcha(argc, argv);
|
|
|
|
} else if (0 == strcmp(argv[1], "change")){
|
|
|
|
change_rate(argv[2], atof(argv[3]), (argc > 4) ? atof(argv[4]) : 0);
|
|
|
|
} else if (0 == strcmp(argv[1], "partial")){
|
|
|
|
partial(argv[2], argv[3], argv[4], atoi(argv[5]));
|
|
|
|
} else if (0 == strcmp(argv[1], "visualize")){
|
|
|
|
visualize(argv[2], (argc > 3) ? argv[3] : 0);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Not an option: %s\n", argv[1]);
|
2014-12-18 22:28:42 +03:00
|
|
|
}
|
2014-11-22 02:35:19 +03:00
|
|
|
return 0;
|
2014-02-15 04:09:07 +04:00
|
|
|
}
|
2014-11-22 02:35:19 +03:00
|
|
|
|