本文整理汇总了C++中parse_network_cfg函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_network_cfg函数的具体用法?C++ parse_network_cfg怎么用?C++ parse_network_cfg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_network_cfg函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_yolo
void test_yolo(char *cfgfile, char *weightfile, char *filename, float thresh)
{
network net = parse_network_cfg(cfgfile);
if(weightfile){
load_weights(&net, weightfile);
}
detection_layer l = net.layers[net.n-1];
set_batch_network(&net, 1);
srand(2222222);
clock_t time;
char buff[256];
char *input = buff;
int j;
float nms=.5;
box *boxes = calloc(l.side*l.side*l.n, sizeof(box));
float **probs = calloc(l.side*l.side*l.n, sizeof(float *));
for(j = 0; j < l.side*l.side*l.n; ++j) probs[j] = calloc(l.classes, sizeof(float *));
while(1){
if(filename){
strncpy(input, filename, 256);
} else {
printf("Enter Image Path: ");
fflush(stdout);
input = fgets(input, 256, stdin);
if(!input) return;
strtok(input, "\n");
}
image im = load_image_color(input,0,0);
image sized = resize_image(im, net.w, net.h);
float *X = sized.data;
time=clock();
float *predictions = network_predict(net, X);
printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time));
convert_yolo_detections(predictions, l.classes, l.n, l.sqrt, l.side, 1, 1, thresh, probs, boxes, 0);
if (nms) do_nms_sort(boxes, probs, l.side*l.side*l.n, l.classes, nms);
draw_detections(im, l.side*l.side*l.n, thresh, boxes, probs, voc_names, voc_labels, 20);
show_image(im, "predictions");
show_image(sized, "resized");
free_image(im);
free_image(sized);
#ifdef OPENCV
cvWaitKey(0);
cvDestroyAllWindows();
#endif
if (filename) break;
}
}
示例2: darknet_load_network
int darknet_load_network(struct darknet_helper *dnet, const char *cfg, const char *weights)
{
dnet->priv->net = parse_network_cfg((char *)cfg);
load_weights(&dnet->priv->net, (char *)weights);
set_batch_network(&dnet->priv->net, 1);
detection_layer l = dnet->priv->net.layers[dnet->priv->net.n-1];
dnet->priv->boxes = (box *)calloc(l.side*l.side*l.n, sizeof(box));
dnet->priv->probs = (float **)calloc(l.side*l.side*l.n, sizeof(float *));
int j;
for(j = 0; j < l.side * l.side * l.n; ++j)
dnet->priv->probs[j] = (float *)calloc(l.classes, sizeof(float *));
return 0;
}
示例3: vec_char_rnn
void vec_char_rnn(char *cfgfile, char *weightfile, char *seed)
{
char *base = basecfg(cfgfile);
fprintf(stderr, "%s\n", base);
network net = parse_network_cfg(cfgfile);
if(weightfile){
load_weights(&net, weightfile);
}
int inputs = get_network_input_size(net);
int c;
int seed_len = strlen(seed);
float *input = calloc(inputs, sizeof(float));
int i;
char *line;
while((line=fgetl(stdin)) != 0){
reset_rnn_state(net, 0);
for(i = 0; i < seed_len; ++i){
c = seed[i];
input[(int)c] = 1;
network_predict(net, input);
input[(int)c] = 0;
}
strip(line);
int str_len = strlen(line);
for(i = 0; i < str_len; ++i){
c = line[i];
input[(int)c] = 1;
network_predict(net, input);
input[(int)c] = 0;
}
c = ' ';
input[(int)c] = 1;
network_predict(net, input);
input[(int)c] = 0;
layer l = net.layers[0];
#ifdef GPU
cuda_pull_array(l.output_gpu, l.output, l.outputs);
#endif
printf("%s", line);
for(i = 0; i < l.outputs; ++i){
printf(",%g", l.output[i]);
}
printf("\n");
}
}
示例4: test_writing
void test_writing(char *cfgfile, char *weightfile, char *filename)
{
network * net = parse_network_cfg(cfgfile);
if(weightfile){
load_weights(net, weightfile);
}
set_batch_network(net, 1);
srand(2222222);
clock_t time;
char buff[256];
char *input = buff;
while(1){
if(filename){
strncpy(input, filename, 256);
}else{
printf("Enter Image Path: ");
fflush(stdout);
input = fgets(input, 256, stdin);
if(!input) return;
strtok(input, "\n");
}
image im = load_image_color(input, 0, 0);
resize_network(net, im.w, im.h);
printf("%d %d %d\n", im.h, im.w, im.c);
float *X = im.data;
time=clock();
network_predict(net, X);
printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time));
image pred = get_network_image(net);
image upsampled = resize_image(pred, im.w, im.h);
image thresh = threshold_image(upsampled, .5);
pred = thresh;
show_image(pred, "prediction");
show_image(im, "orig");
#ifdef OPENCV
cvWaitKey(0);
cvDestroyAllWindows();
#endif
free_image(upsampled);
free_image(thresh);
free_image(im);
if (filename) break;
}
}
示例5: rgbgr_net
void rgbgr_net(char *cfgfile, char *weightfile, char *outfile)
{
network net = parse_network_cfg(cfgfile);
if(weightfile){
load_weights(&net, weightfile);
}
int i;
for(i = 0; i < net.n; ++i){
layer l = net.layers[i];
if(l.type == CONVOLUTIONAL){
rgbgr_filters(l);
break;
}
}
save_weights(net, outfile);
}
示例6: test_mnist_multi
void test_mnist_multi(char *filename, char *weightfile)
{
network net = parse_network_cfg(filename);
if(weightfile){
load_weights(&net, weightfile);
}
set_batch_network(&net, 1);
srand(time(0));
float avg_acc = 0;
data test;
test = load_mnist_data("data/mnist/t10k-images.idx3-ubyte", "data/mnist/t10k-labels.idx1-ubyte", 10000);
int i;
for(i = 0; i < test.X.rows; ++i){
image im = float_to_image(28, 28, 1, test.X.vals[i]);
float pred[10] = {0};
float *p = network_predict(net, im.data);
axpy_cpu(10, 1, p, 1, pred, 1);
// flip_image(im);
image im1 = rotate_image(im, -2.0*3.1415926/180.0);
image im2 = rotate_image(im, 2.0*3.1415926/180.0);
image im3 = rotate_image(im, -3.0*3.1415926/180.0);
image im4 = rotate_image(im, 3.0*3.1415926/180.0);
p = network_predict(net, im1.data);
axpy_cpu(10, 1, p, 1, pred, 1);
p = network_predict(net, im2.data);
axpy_cpu(10, 1, p, 1, pred, 1);
p = network_predict(net, im3.data);
axpy_cpu(10, 1, p, 1, pred, 1);
p = network_predict(net, im4.data);
axpy_cpu(10, 1, p, 1, pred, 1);
int index = max_index(pred, 10);
int class = max_index(test.y.vals[i], 10);
if(index == class) avg_acc += 1;
free_image(im);
free_image(im1);
free_image(im2);
free_image(im3);
free_image(im4);
printf("%4d: %.2f%%\n", i, 100.*avg_acc/(i+1));
}
printf("%4d: %.2f%%\n", i, 100.*avg_acc/(i+1));
}
示例7: train_cifar
void train_cifar(char *cfgfile, char *weightfile)
{
srand(time(0));
float avg_loss = -1;
char *base = basecfg(cfgfile);
printf("%s\n", base);
network net = parse_network_cfg(cfgfile);
if(weightfile){
load_weights(&net, weightfile);
}
printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net.learning_rate, net.momentum, net.decay);
char *backup_directory = "/home/pjreddie/backup/";
int classes = 10;
int N = 50000;
char **labels = get_labels("data/cifar/labels.txt");
int epoch = (*net.seen)/N;
data train = load_all_cifar10();
while(get_current_batch(net) < net.max_batches || net.max_batches == 0){
clock_t time=clock();
float loss = train_network_sgd(net, train, 1);
if(avg_loss == -1) avg_loss = loss;
avg_loss = avg_loss*.95 + loss*.05;
printf("%d, %.3f: %f, %f avg, %f rate, %lf seconds, %d images\n", get_current_batch(net), (float)(*net.seen)/N, loss, avg_loss, get_current_rate(net), sec(clock()-time), *net.seen);
if(*net.seen/N > epoch){
epoch = *net.seen/N;
char buff[256];
sprintf(buff, "%s/%s_%d.weights",backup_directory,base, epoch);
save_weights(net, buff);
}
if(get_current_batch(net)%100 == 0){
char buff[256];
sprintf(buff, "%s/%s.backup",backup_directory,base);
save_weights(net, buff);
}
}
char buff[256];
sprintf(buff, "%s/%s.weights", backup_directory, base);
save_weights(net, buff);
free_network(net);
free_ptrs((void**)labels, classes);
free(base);
free_data(train);
}
示例8: denormalize_net
static void denormalize_net(char *cfgfile, char *weightfile, char *outfile)
{
gpu_index = -1;
network net = parse_network_cfg(cfgfile);
if (weightfile) {
load_weights(&net, weightfile);
}
int i;
for (i = 0; i < net.n; ++i) {
layer_t l = net.layers[i];
if (l.type == CONVOLUTIONAL && l.batch_normalize) {
denormalize_convolutional_layer(l);
net.layers[i].batch_normalize=0;
}
}
save_weights(net, outfile);
}
示例9: rescale_net
static void rescale_net(char *cfgfile, char *weightfile, char *outfile)
{
gpu_index = -1;
network net = parse_network_cfg(cfgfile);
if(weightfile){
load_weights(&net, weightfile);
}
int i;
for(i = 0; i < net.n; ++i){
layer_t l = net.layers[i];
if(l.type == CONVOLUTIONAL){
rescale_filters(l, 2, -.5);
break;
}
}
save_weights(net, outfile);
}
示例10: train_writing
void train_writing(char *cfgfile, char *weightfile)
{
data_seed = time(0);
srand(time(0));
float avg_loss = -1;
char *base = basecfg(cfgfile);
printf("%s\n", base);
network net = parse_network_cfg(cfgfile);
if(weightfile){
load_weights(&net, weightfile);
}
printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net.learning_rate, net.momentum, net.decay);
int imgs = 256;
int i = net.seen/imgs;
list *plist = get_paths("data/train.list");
char **paths = (char **)list_to_array(plist);
printf("%d\n", plist->size);
clock_t time;
while(1){
++i;
time=clock();
data train = load_data_writing(paths, imgs, plist->size, 256, 256, 4);
float loss = train_network(net, train);
#ifdef GPU
float *out = get_network_output_gpu(net);
#else
float *out = get_network_output(net);
#endif
// image pred = float_to_image(32, 32, 1, out);
// print_image(pred);
net.seen += imgs;
if(avg_loss == -1) avg_loss = loss;
avg_loss = avg_loss*.9 + loss*.1;
printf("%d: %f, %f avg, %lf seconds, %d images\n", i, loss, avg_loss, sec(clock()-time), net.seen);
free_data(train);
if((i % 20000) == 0) net.learning_rate *= .1;
//if(i%100 == 0 && net.learning_rate > .00001) net.learning_rate *= .97;
if(i%250==0){
char buff[256];
sprintf(buff, "/home/pjreddie/writing_backup/%s_%d.weights", base, i);
save_weights(net, buff);
}
}
}
示例11: predict_classifier
void predict_classifier(char *datacfg, char *cfgfile, char *weightfile, char *filename)
{
network net = parse_network_cfg(cfgfile);
if(weightfile){
load_weights(&net, weightfile);
}
set_batch_network(&net, 1);
srand(2222222);
list *options = read_data_cfg(datacfg);
char *name_list = option_find_str(options, "names", 0);
if(!name_list) name_list = option_find_str(options, "labels", "data/labels.list");
int top = option_find_int(options, "top", 1);
int i = 0;
char **names = get_labels(name_list);
clock_t time;
int *indexes = calloc(top, sizeof(int));
char buff[256];
char *input = buff;
while(1){
if(filename){
strncpy(input, filename, 256);
}else{
printf("Enter Image Path: ");
fflush(stdout);
input = fgets(input, 256, stdin);
if(!input) return;
strtok(input, "\n");
}
image im = load_image_color(input, net.w, net.h);
float *X = im.data;
time=clock();
float *predictions = network_predict(net, X);
top_predictions(net, top, indexes);
printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time));
for(i = 0; i < top; ++i){
int index = indexes[i];
printf("%s: %f\n", names[index], predictions[index]);
}
free_image(im);
if (filename) break;
}
}
示例12: visualize_learned_weights
void visualize_learned_weights(char *cfgfile, char *weightfile, char *out_file){
network net = parse_network_cfg(cfgfile);
if(weightfile){
load_weights(&net, weightfile);
}
layer l = net.layers[0];
int num = l.n*l.c*l.size*l.size;
int filter_size = l.size*l.size*l.c;
printf("Layer params: %dX%dX%d - %d\n",l.size,l.size,l.c,l.n);
printf("Filter size: %d\n",filter_size);
float * filters = net.layers[0].filters;
FILE *f = fopen(out_file,"w");
if(f==NULL){
printf("Error opening file!\n");
exit(1);
}
for (int f_num = 0; f_num<l.n; f_num++){
fprintf(f,"###############FILTER %d###################\n",f_num);
printf("###############FILTER %d###################\n",f_num);
for(int channel=0; channel<l.c; channel++){
printf("~~~~~~~~~~~~~CHANNEL %d~~~~~~~~~~~~\n",channel);
printf("=========================================\n");
for(int r=0; r<l.size; r++){
printf("|");
for(int c=0; c<l.size; c++){
int target_index = c + l.size*r+l.size*l.size*channel+f_num*filter_size;
if(target_index>=num)
printf('Sono incapace di contare\n');
printf("%f\t",filters[target_index]);
fprintf(f,"%f;",filters[target_index]);
}
fprintf(f,"\n");
printf("----------------------------------------\n");
}
//visualize filter
fprintf(f,"\n");
printf("=========================================\n");
}
fprintf(f,"\n\n");
printf("\n\n");
}
fclose(f);
}
示例13: test_tactic_rnn
void test_tactic_rnn(char *cfgfile, char *weightfile, int num, float temp, int rseed, char *token_file)
{
char **tokens = 0;
if(token_file){
size_t n;
tokens = read_tokens(token_file, &n);
}
srand(rseed);
char *base = basecfg(cfgfile);
fprintf(stderr, "%s\n", base);
network net = parse_network_cfg(cfgfile);
if(weightfile){
load_weights(&net, weightfile);
}
int inputs = get_network_input_size(net);
int i, j;
for(i = 0; i < net.n; ++i) net.layers[i].temperature = temp;
int c = 0;
float *input = calloc(inputs, sizeof(float));
float *out = 0;
while((c = getc(stdin)) != EOF){
input[c] = 1;
out = network_predict(net, input);
input[c] = 0;
}
for(i = 0; i < num; ++i){
for(j = 0; j < inputs; ++j){
if (out[j] < .0001) out[j] = 0;
}
int next = sample_array(out, inputs);
if(c == '.' && next == '\n') break;
c = next;
print_symbol(c, tokens);
input[c] = 1;
out = network_predict(net, input);
input[c] = 0;
}
printf("\n");
}
示例14: test_tag
void test_tag(char *cfgfile, char *weightfile, char *filename)
{
network net = parse_network_cfg(cfgfile);
if(weightfile){
load_weights(&net, weightfile);
}
set_batch_network(&net, 1);
srand(2222222);
int i = 0;
char **names = get_labels("data/tags.txt");
clock_t time;
int indexes[10];
char buff[256];
char *input = buff;
int size = net.w;
while(1){
if(filename){
strncpy(input, filename, 256);
}else{
printf("Enter Image Path: ");
fflush(stdout);
input = fgets(input, 256, stdin);
if(!input) return;
strtok(input, "\n");
}
image im = load_image_color(input, 0, 0);
image r = resize_min(im, size);
resize_network(&net, r.w, r.h);
printf("%d %d\n", r.w, r.h);
float *X = r.data;
time=clock();
float *predictions = network_predict(net, X);
top_predictions(net, 10, indexes);
printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time));
for(i = 0; i < 10; ++i){
int index = indexes[i];
printf("%.1f%%: %s\n", predictions[index]*100, names[index]);
}
if(r.data != im.data) free_image(r);
free_image(im);
if (filename) break;
}
}
示例15: speed
void speed(char *cfgfile, int tics)
{
if (tics == 0) tics = 1000;
network *net = parse_network_cfg(cfgfile);
set_batch_network(net, 1);
int i;
double time=what_time_is_it_now();
image im = make_image(net->w, net->h, net->c*net->batch);
for(i = 0; i < tics; ++i){
network_predict(net, im.data);
}
double t = what_time_is_it_now() - time;
long ops = numops(net);
printf("\n%d evals, %f Seconds\n", tics, t);
printf("Floating Point Operations: %.2f Bn\n", (float)ops/1000000000.);
printf("FLOPS: %.2f Bn\n", (float)ops/1000000000.*tics/t);
printf("Speed: %f sec/eval\n", t/tics);
printf("Speed: %f Hz\n", tics/t);
}