mirror of
https://github.com/pjreddie/darknet.git
synced 2023-08-10 21:13:14 +03:00
fixes to image
This commit is contained in:
@ -4,7 +4,7 @@ subdivisions=2
|
|||||||
height=256
|
height=256
|
||||||
width=256
|
width=256
|
||||||
channels=3
|
channels=3
|
||||||
learning_rate=0.0000001
|
learning_rate=0.000001
|
||||||
momentum=0.9
|
momentum=0.9
|
||||||
decay=0.0005
|
decay=0.0005
|
||||||
seen=0
|
seen=0
|
||||||
|
@ -499,7 +499,7 @@ image threshold_image(image im, float thresh)
|
|||||||
int i;
|
int i;
|
||||||
image t = make_image(im.w, im.h, im.c);
|
image t = make_image(im.w, im.h, im.c);
|
||||||
for(i = 0; i < im.w*im.h*im.c; ++i){
|
for(i = 0; i < im.w*im.h*im.c; ++i){
|
||||||
t.data[i] = im.data[i]>0 ? 1 : 0;
|
t.data[i] = im.data[i]>thresh ? 1 : 0;
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
@ -622,7 +622,7 @@ image resize_image(image im, int w, int h)
|
|||||||
float val = (1-dy) * get_pixel(part, c, iy, k);
|
float val = (1-dy) * get_pixel(part, c, iy, k);
|
||||||
set_pixel(resized, c, r, k, val);
|
set_pixel(resized, c, r, k, val);
|
||||||
}
|
}
|
||||||
if(r == h-1) continue;
|
if(r == h-1 || im.h == 1) continue;
|
||||||
for(c = 0; c < w; ++c){
|
for(c = 0; c < w; ++c){
|
||||||
float val = dy * get_pixel(part, c, iy+1, k);
|
float val = dy * get_pixel(part, c, iy+1, k);
|
||||||
add_pixel(resized, c, r, k, val);
|
add_pixel(resized, c, r, k, val);
|
||||||
|
@ -69,13 +69,18 @@ void train_writing(char *cfgfile, char *weightfile)
|
|||||||
if(avg_loss == -1) avg_loss = loss;
|
if(avg_loss == -1) avg_loss = loss;
|
||||||
avg_loss = avg_loss*.9 + loss*.1;
|
avg_loss = avg_loss*.9 + loss*.1;
|
||||||
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);
|
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);
|
||||||
free_data(train);
|
free_data(train);
|
||||||
if(*net.seen/N > epoch){
|
if(get_current_batch(net)%100 == 0){
|
||||||
epoch = *net.seen/N;
|
char buff[256];
|
||||||
char buff[256];
|
sprintf(buff, "%s/%s_batch_%d.weights", backup_directory, base, get_current_batch(net));
|
||||||
sprintf(buff, "%s/%s_%d.weights",backup_directory,base, epoch);
|
save_weights(net, buff);
|
||||||
save_weights(net, buff);
|
}
|
||||||
}
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +107,7 @@ void test_writing(char *cfgfile, char *weightfile, char *outfile)
|
|||||||
printf("%s: Predicted in %f seconds.\n", filename, sec(clock()-time));
|
printf("%s: Predicted in %f seconds.\n", filename, sec(clock()-time));
|
||||||
image pred = get_network_image(net);
|
image pred = get_network_image(net);
|
||||||
|
|
||||||
image t = threshold_image(pred, .2);
|
image t = threshold_image(pred, .5);
|
||||||
free_image(pred);
|
free_image(pred);
|
||||||
pred = t;
|
pred = t;
|
||||||
|
|
||||||
@ -110,28 +115,29 @@ void test_writing(char *cfgfile, char *weightfile, char *outfile)
|
|||||||
printf("Save image as %s.png (shape: %d %d)\n", outfile, pred.w, pred.h);
|
printf("Save image as %s.png (shape: %d %d)\n", outfile, pred.w, pred.h);
|
||||||
save_image(pred, outfile);
|
save_image(pred, outfile);
|
||||||
} else {
|
} else {
|
||||||
|
show_image(sized, "orig");
|
||||||
show_image(pred, "prediction");
|
show_image(pred, "prediction");
|
||||||
#ifdef OPENCV
|
#ifdef OPENCV
|
||||||
cvWaitKey(0);
|
cvWaitKey(0);
|
||||||
cvDestroyAllWindows();
|
cvDestroyAllWindows();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
free_image(im);
|
free_image(im);
|
||||||
free_image(sized);
|
free_image(sized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void run_writing(int argc, char **argv)
|
void run_writing(int argc, char **argv)
|
||||||
{
|
{
|
||||||
if(argc < 4){
|
if(argc < 4){
|
||||||
fprintf(stderr, "usage: %s %s [train/test/valid] [cfg] [weights (optional)]\n", argv[0], argv[1]);
|
fprintf(stderr, "usage: %s %s [train/test/valid] [cfg] [weights (optional)]\n", argv[0], argv[1]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *cfg = argv[3];
|
char *cfg = argv[3];
|
||||||
char *weights = (argc > 4) ? argv[4] : 0;
|
char *weights = (argc > 4) ? argv[4] : 0;
|
||||||
char *outfile = (argc > 5) ? argv[5] : 0;
|
char *outfile = (argc > 5) ? argv[5] : 0;
|
||||||
if(0==strcmp(argv[2], "train")) train_writing(cfg, weights);
|
if(0==strcmp(argv[2], "train")) train_writing(cfg, weights);
|
||||||
else if(0==strcmp(argv[2], "test")) test_writing(cfg, weights, outfile);
|
else if(0==strcmp(argv[2], "test")) test_writing(cfg, weights, outfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user