mirror of
https://github.com/pjreddie/darknet.git
synced 2023-08-10 21:13:14 +03:00
it's raining really hard outside :-( :rain: :storm: ☁️
This commit is contained in:
368
examples/lsd.c
368
examples/lsd.c
@ -16,9 +16,9 @@ void train_lsd3(char *fcfg, char *fweight, char *gcfg, char *gweight, char *acfg
|
||||
char *gbase = basecfg(gcfg);
|
||||
char *abase = basecfg(acfg);
|
||||
|
||||
printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", gnet.learning_rate, gnet.momentum, gnet.decay);
|
||||
int imgs = gnet.batch*gnet.subdivisions;
|
||||
int i = *gnet.seen/imgs;
|
||||
printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", gnet->learning_rate, gnet->momentum, gnet->decay);
|
||||
int imgs = gnet->batch*gnet->subdivisions;
|
||||
int i = *gnet->seen/imgs;
|
||||
data train, tbuffer;
|
||||
data style, sbuffer;
|
||||
|
||||
@ -55,27 +55,27 @@ void train_lsd3(char *fcfg, char *fweight, char *gcfg, char *gweight, char *acfg
|
||||
float aloss_avg = -1;
|
||||
float floss_avg = -1;
|
||||
|
||||
fnet.train=1;
|
||||
int x_size = fnet.inputs*fnet.batch;
|
||||
int y_size = fnet.truths*fnet.batch;
|
||||
fnet->train=1;
|
||||
int x_size = fnet->inputs*fnet->batch;
|
||||
int y_size = fnet->truths*fnet->batch;
|
||||
float *X = calloc(x_size, sizeof(float));
|
||||
float *y = calloc(y_size, sizeof(float));
|
||||
|
||||
|
||||
int ax_size = anet.inputs*anet.batch;
|
||||
int ay_size = anet.truths*anet.batch;
|
||||
fill_gpu(ay_size, .9, anet.truth_gpu, 1);
|
||||
anet.delta_gpu = cuda_make_array(0, ax_size);
|
||||
anet.train = 1;
|
||||
int ax_size = anet->inputs*anet->batch;
|
||||
int ay_size = anet->truths*anet->batch;
|
||||
fill_gpu(ay_size, .9, anet->truth_gpu, 1);
|
||||
anet->delta_gpu = cuda_make_array(0, ax_size);
|
||||
anet->train = 1;
|
||||
|
||||
int gx_size = gnet.inputs*gnet.batch;
|
||||
int gy_size = gnet.truths*gnet.batch;
|
||||
int gx_size = gnet->inputs*gnet->batch;
|
||||
int gy_size = gnet->truths*gnet->batch;
|
||||
gstate.input = cuda_make_array(0, gx_size);
|
||||
gstate.truth = 0;
|
||||
gstate.delta = 0;
|
||||
gstate.train = 1;
|
||||
|
||||
while (get_current_batch(gnet) < gnet.max_batches) {
|
||||
while (get_current_batch(gnet) < gnet->max_batches) {
|
||||
i += 1;
|
||||
time=clock();
|
||||
pthread_join(tload_thread, 0);
|
||||
@ -92,20 +92,20 @@ void train_lsd3(char *fcfg, char *fweight, char *gcfg, char *gweight, char *acfg
|
||||
|
||||
int j, k;
|
||||
float floss = 0;
|
||||
for(j = 0; j < fnet.subdivisions; ++j){
|
||||
layer imlayer = gnet.layers[gnet.n - 1];
|
||||
get_next_batch(train, fnet.batch, j*fnet.batch, X, y);
|
||||
for(j = 0; j < fnet->subdivisions; ++j){
|
||||
layer imlayer = gnet->layers[gnet->n - 1];
|
||||
get_next_batch(train, fnet->batch, j*fnet->batch, X, y);
|
||||
|
||||
cuda_push_array(fstate.input, X, x_size);
|
||||
cuda_push_array(gstate.input, X, gx_size);
|
||||
*gnet.seen += gnet.batch;
|
||||
*gnet->seen += gnet->batch;
|
||||
|
||||
forward_network_gpu(fnet, fstate);
|
||||
float *feats = fnet.layers[fnet.n - 2].output_gpu;
|
||||
float *feats = fnet->layers[fnet->n - 2].output_gpu;
|
||||
copy_gpu(y_size, feats, 1, fstate.truth, 1);
|
||||
|
||||
forward_network_gpu(gnet, gstate);
|
||||
float *gen = gnet.layers[gnet.n-1].output_gpu;
|
||||
float *gen = gnet->layers[gnet->n-1].output_gpu;
|
||||
copy_gpu(x_size, gen, 1, fstate.input, 1);
|
||||
|
||||
fill_gpu(x_size, 0, fstate.delta, 1);
|
||||
@ -135,11 +135,11 @@ void train_lsd3(char *fcfg, char *fweight, char *gcfg, char *gweight, char *acfg
|
||||
|
||||
backward_network_gpu(gnet, gstate);
|
||||
|
||||
floss += get_network_cost(fnet) /(fnet.subdivisions*fnet.batch);
|
||||
floss += get_network_cost(fnet) /(fnet->subdivisions*fnet->batch);
|
||||
|
||||
cuda_pull_array(imlayer.output_gpu, imlayer.output, imlayer.outputs*imlayer.batch);
|
||||
for(k = 0; k < gnet.batch; ++k){
|
||||
int index = j*gnet.batch + k;
|
||||
for(k = 0; k < gnet->batch; ++k){
|
||||
int index = j*gnet->batch + k;
|
||||
copy_cpu(imlayer.outputs, imlayer.output + k*imlayer.outputs, 1, generated.X.vals[index], 1);
|
||||
generated.y.vals[index][0] = .1;
|
||||
style.y.vals[index][0] = .9;
|
||||
@ -148,7 +148,7 @@ void train_lsd3(char *fcfg, char *fweight, char *gcfg, char *gweight, char *acfg
|
||||
|
||||
*/
|
||||
/*
|
||||
image sim = float_to_image(anet.w, anet.h, anet.c, style.X.vals[j]);
|
||||
image sim = float_to_image(anet->w, anet->h, anet->c, style.X.vals[j]);
|
||||
show_image(sim, "style");
|
||||
cvWaitKey(0);
|
||||
*/
|
||||
@ -208,16 +208,16 @@ void train_pix2pix(char *cfg, char *weight, char *acfg, char *aweight, int clear
|
||||
|
||||
int i, j, k;
|
||||
layer imlayer = {0};
|
||||
for (i = 0; i < net.n; ++i) {
|
||||
if (net.layers[i].out_c == 3) {
|
||||
imlayer = net.layers[i];
|
||||
for (i = 0; i < net->n; ++i) {
|
||||
if (net->layers[i].out_c == 3) {
|
||||
imlayer = net->layers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net.learning_rate, net.momentum, net.decay);
|
||||
int imgs = net.batch*net.subdivisions;
|
||||
i = *net.seen/imgs;
|
||||
printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay);
|
||||
int imgs = net->batch*net->subdivisions;
|
||||
i = *net->seen/imgs;
|
||||
data train, buffer;
|
||||
|
||||
|
||||
@ -226,21 +226,21 @@ void train_pix2pix(char *cfg, char *weight, char *acfg, char *aweight, int clear
|
||||
char **paths = (char **)list_to_array(plist);
|
||||
|
||||
load_args args = {0};
|
||||
args.w = net.w;
|
||||
args.h = net.h;
|
||||
args.w = net->w;
|
||||
args.h = net->h;
|
||||
args.paths = paths;
|
||||
args.n = imgs;
|
||||
args.m = plist->size;
|
||||
args.d = &buffer;
|
||||
|
||||
args.min = net.min_crop;
|
||||
args.max = net.max_crop;
|
||||
args.angle = net.angle;
|
||||
args.aspect = net.aspect;
|
||||
args.exposure = net.exposure;
|
||||
args.saturation = net.saturation;
|
||||
args.hue = net.hue;
|
||||
args.size = net.w;
|
||||
args.min = net->min_crop;
|
||||
args.max = net->max_crop;
|
||||
args.angle = net->angle;
|
||||
args.aspect = net->aspect;
|
||||
args.exposure = net->exposure;
|
||||
args.saturation = net->saturation;
|
||||
args.hue = net->hue;
|
||||
args.size = net->w;
|
||||
args.type = CLASSIFICATION_DATA;
|
||||
args.classes = 1;
|
||||
char *ls[1] = {"coco"};
|
||||
@ -252,7 +252,7 @@ void train_pix2pix(char *cfg, char *weight, char *acfg, char *aweight, int clear
|
||||
network_state gstate = {0};
|
||||
gstate.index = 0;
|
||||
gstate.net = net;
|
||||
int x_size = get_network_input_size(net)*net.batch;
|
||||
int x_size = get_network_input_size(net)*net->batch;
|
||||
int y_size = x_size;
|
||||
gstate.input = cuda_make_array(0, x_size);
|
||||
gstate.truth = cuda_make_array(0, y_size);
|
||||
@ -265,7 +265,7 @@ void train_pix2pix(char *cfg, char *weight, char *acfg, char *aweight, int clear
|
||||
network_state astate = {0};
|
||||
astate.index = 0;
|
||||
astate.net = anet;
|
||||
int ay_size = get_network_output_size(anet)*anet.batch;
|
||||
int ay_size = get_network_output_size(anet)*anet->batch;
|
||||
astate.input = 0;
|
||||
astate.truth = 0;
|
||||
astate.delta = 0;
|
||||
@ -280,7 +280,7 @@ void train_pix2pix(char *cfg, char *weight, char *acfg, char *aweight, int clear
|
||||
|
||||
//data generated = copy_data(train);
|
||||
|
||||
while (get_current_batch(net) < net.max_batches) {
|
||||
while (get_current_batch(net) < net->max_batches) {
|
||||
i += 1;
|
||||
time=clock();
|
||||
pthread_join(load_thread, 0);
|
||||
@ -291,31 +291,31 @@ void train_pix2pix(char *cfg, char *weight, char *acfg, char *aweight, int clear
|
||||
|
||||
data gray = copy_data(train);
|
||||
for(j = 0; j < imgs; ++j){
|
||||
image gim = float_to_image(net.w, net.h, net.c, gray.X.vals[j]);
|
||||
image gim = float_to_image(net->w, net->h, net->c, gray.X.vals[j]);
|
||||
grayscale_image_3c(gim);
|
||||
train.y.vals[j][0] = .9;
|
||||
|
||||
image yim = float_to_image(net.w, net.h, net.c, train.X.vals[j]);
|
||||
image yim = float_to_image(net->w, net->h, net->c, train.X.vals[j]);
|
||||
//rgb_to_yuv(yim);
|
||||
}
|
||||
time=clock();
|
||||
float gloss = 0;
|
||||
|
||||
for(j = 0; j < net.subdivisions; ++j){
|
||||
get_next_batch(train, net.batch, j*net.batch, pixs, y);
|
||||
get_next_batch(gray, net.batch, j*net.batch, graypixs, y);
|
||||
for(j = 0; j < net->subdivisions; ++j){
|
||||
get_next_batch(train, net->batch, j*net->batch, pixs, y);
|
||||
get_next_batch(gray, net->batch, j*net->batch, graypixs, y);
|
||||
cuda_push_array(gstate.input, graypixs, x_size);
|
||||
cuda_push_array(gstate.truth, pixs, y_size);
|
||||
*/
|
||||
/*
|
||||
image origi = float_to_image(net.w, net.h, 3, pixs);
|
||||
image grayi = float_to_image(net.w, net.h, 3, graypixs);
|
||||
image origi = float_to_image(net->w, net->h, 3, pixs);
|
||||
image grayi = float_to_image(net->w, net->h, 3, graypixs);
|
||||
show_image(grayi, "gray");
|
||||
show_image(origi, "orig");
|
||||
cvWaitKey(0);
|
||||
*/
|
||||
/*
|
||||
*net.seen += net.batch;
|
||||
*net->seen += net->batch;
|
||||
forward_network_gpu(net, gstate);
|
||||
|
||||
fill_gpu(imlayer.outputs, 0, imerror, 1);
|
||||
@ -325,22 +325,22 @@ void train_pix2pix(char *cfg, char *weight, char *acfg, char *aweight, int clear
|
||||
forward_network_gpu(anet, astate);
|
||||
backward_network_gpu(anet, astate);
|
||||
|
||||
scal_gpu(imlayer.outputs, .1, net.layers[net.n-1].delta_gpu, 1);
|
||||
scal_gpu(imlayer.outputs, .1, net->layers[net->n-1].delta_gpu, 1);
|
||||
|
||||
backward_network_gpu(net, gstate);
|
||||
|
||||
scal_gpu(imlayer.outputs, 1000, imerror, 1);
|
||||
|
||||
printf("realness %f\n", cuda_mag_array(imerror, imlayer.outputs));
|
||||
printf("features %f\n", cuda_mag_array(net.layers[net.n-1].delta_gpu, imlayer.outputs));
|
||||
printf("features %f\n", cuda_mag_array(net->layers[net->n-1].delta_gpu, imlayer.outputs));
|
||||
|
||||
axpy_gpu(imlayer.outputs, 1, imerror, 1, imlayer.delta_gpu, 1);
|
||||
|
||||
gloss += get_network_cost(net) /(net.subdivisions*net.batch);
|
||||
gloss += get_network_cost(net) /(net->subdivisions*net->batch);
|
||||
|
||||
cuda_pull_array(imlayer.output_gpu, imlayer.output, imlayer.outputs*imlayer.batch);
|
||||
for(k = 0; k < net.batch; ++k){
|
||||
int index = j*net.batch + k;
|
||||
for(k = 0; k < net->batch; ++k){
|
||||
int index = j*net->batch + k;
|
||||
copy_cpu(imlayer.outputs, imlayer.output + k*imlayer.outputs, 1, gray.X.vals[index], 1);
|
||||
gray.y.vals[index][0] = .1;
|
||||
}
|
||||
@ -385,11 +385,8 @@ void train_pix2pix(char *cfg, char *weight, char *acfg, char *aweight, int clear
|
||||
|
||||
void test_dcgan(char *cfgfile, char *weightfile)
|
||||
{
|
||||
network net = parse_network_cfg(cfgfile);
|
||||
if(weightfile){
|
||||
load_weights(&net, weightfile);
|
||||
}
|
||||
set_batch_network(&net, 1);
|
||||
network *net = load_network(cfgfile, weightfile, 0);
|
||||
set_batch_network(net, 1);
|
||||
srand(2222222);
|
||||
|
||||
clock_t time;
|
||||
@ -397,8 +394,8 @@ void test_dcgan(char *cfgfile, char *weightfile)
|
||||
char *input = buff;
|
||||
int i, imlayer = 0;
|
||||
|
||||
for (i = 0; i < net.n; ++i) {
|
||||
if (net.layers[i].out_c == 3) {
|
||||
for (i = 0; i < net->n; ++i) {
|
||||
if (net->layers[i].out_c == 3) {
|
||||
imlayer = i;
|
||||
printf("%d\n", i);
|
||||
break;
|
||||
@ -406,7 +403,7 @@ void test_dcgan(char *cfgfile, char *weightfile)
|
||||
}
|
||||
|
||||
while(1){
|
||||
image im = make_image(net.w, net.h, net.c);
|
||||
image im = make_image(net->w, net->h, net->c);
|
||||
int i;
|
||||
for(i = 0; i < im.w*im.h*im.c; ++i){
|
||||
im.data[i] = rand_normal();
|
||||
@ -449,23 +446,23 @@ void train_dcgan(char *cfg, char *weight, char *acfg, char *aweight, int clear,
|
||||
char *base = basecfg(cfg);
|
||||
char *abase = basecfg(acfg);
|
||||
printf("%s\n", base);
|
||||
network gnet = load_network(cfg, weight, clear);
|
||||
network anet = load_network(acfg, aweight, clear);
|
||||
//float orig_rate = anet.learning_rate;
|
||||
network *gnet = load_network(cfg, weight, clear);
|
||||
network *anet = load_network(acfg, aweight, clear);
|
||||
//float orig_rate = anet->learning_rate;
|
||||
|
||||
int start = 0;
|
||||
int i, j, k;
|
||||
layer imlayer = {0};
|
||||
for (i = 0; i < gnet.n; ++i) {
|
||||
if (gnet.layers[i].out_c == 3) {
|
||||
imlayer = gnet.layers[i];
|
||||
for (i = 0; i < gnet->n; ++i) {
|
||||
if (gnet->layers[i].out_c == 3) {
|
||||
imlayer = gnet->layers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", gnet.learning_rate, gnet.momentum, gnet.decay);
|
||||
int imgs = gnet.batch*gnet.subdivisions;
|
||||
i = *gnet.seen/imgs;
|
||||
printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", gnet->learning_rate, gnet->momentum, gnet->decay);
|
||||
int imgs = gnet->batch*gnet->subdivisions;
|
||||
i = *gnet->seen/imgs;
|
||||
data train, buffer;
|
||||
|
||||
|
||||
@ -487,20 +484,20 @@ void train_dcgan(char *cfg, char *weight, char *acfg, char *aweight, int clear,
|
||||
pthread_t load_thread = load_data_in_thread(args);
|
||||
clock_t time;
|
||||
|
||||
gnet.train = 1;
|
||||
anet.train = 1;
|
||||
gnet->train = 1;
|
||||
anet->train = 1;
|
||||
|
||||
int x_size = gnet.inputs*gnet.batch;
|
||||
int y_size = gnet.truths*gnet.batch;
|
||||
int x_size = gnet->inputs*gnet->batch;
|
||||
int y_size = gnet->truths*gnet->batch;
|
||||
float *imerror = cuda_make_array(0, y_size);
|
||||
|
||||
//int ay_size = anet.truths*anet.batch;
|
||||
//int ay_size = anet->truths*anet->batch;
|
||||
|
||||
float aloss_avg = -1;
|
||||
|
||||
//data generated = copy_data(train);
|
||||
|
||||
while (get_current_batch(gnet) < gnet.max_batches) {
|
||||
while (get_current_batch(gnet) < gnet->max_batches) {
|
||||
start += 1;
|
||||
i += 1;
|
||||
time=clock();
|
||||
@ -521,41 +518,41 @@ void train_dcgan(char *cfg, char *weight, char *acfg, char *aweight, int clear,
|
||||
}
|
||||
time=clock();
|
||||
|
||||
for(j = 0; j < gnet.subdivisions; ++j){
|
||||
get_next_batch(train, gnet.batch, j*gnet.batch, gnet.truth, 0);
|
||||
for(j = 0; j < gnet->subdivisions; ++j){
|
||||
get_next_batch(train, gnet->batch, j*gnet->batch, gnet->truth, 0);
|
||||
int z;
|
||||
for(z = 0; z < x_size; ++z){
|
||||
gnet.input[z] = rand_normal();
|
||||
gnet->input[z] = rand_normal();
|
||||
}
|
||||
|
||||
cuda_push_array(gnet.input_gpu, gnet.input, x_size);
|
||||
cuda_push_array(gnet.truth_gpu, gnet.truth, y_size);
|
||||
*gnet.seen += gnet.batch;
|
||||
cuda_push_array(gnet->input_gpu, gnet->input, x_size);
|
||||
cuda_push_array(gnet->truth_gpu, gnet->truth, y_size);
|
||||
*gnet->seen += gnet->batch;
|
||||
forward_network_gpu(gnet);
|
||||
|
||||
fill_gpu(imlayer.outputs*imlayer.batch, 0, imerror, 1);
|
||||
fill_gpu(anet.truths*anet.batch, .95, anet.truth_gpu, 1);
|
||||
copy_gpu(anet.inputs*anet.batch, imlayer.output_gpu, 1, anet.input_gpu, 1);
|
||||
anet.delta_gpu = imerror;
|
||||
fill_gpu(anet->truths*anet->batch, .95, anet->truth_gpu, 1);
|
||||
copy_gpu(anet->inputs*anet->batch, imlayer.output_gpu, 1, anet->input_gpu, 1);
|
||||
anet->delta_gpu = imerror;
|
||||
forward_network_gpu(anet);
|
||||
backward_network_gpu(anet);
|
||||
|
||||
float genaloss = *anet.cost / anet.batch;
|
||||
float genaloss = *anet->cost / anet->batch;
|
||||
printf("%f\n", genaloss);
|
||||
|
||||
scal_gpu(imlayer.outputs*imlayer.batch, 1, imerror, 1);
|
||||
scal_gpu(imlayer.outputs*imlayer.batch, .00, gnet.layers[gnet.n-1].delta_gpu, 1);
|
||||
scal_gpu(imlayer.outputs*imlayer.batch, .00, gnet->layers[gnet->n-1].delta_gpu, 1);
|
||||
|
||||
printf("realness %f\n", cuda_mag_array(imerror, imlayer.outputs*imlayer.batch));
|
||||
printf("features %f\n", cuda_mag_array(gnet.layers[gnet.n-1].delta_gpu, imlayer.outputs*imlayer.batch));
|
||||
printf("features %f\n", cuda_mag_array(gnet->layers[gnet->n-1].delta_gpu, imlayer.outputs*imlayer.batch));
|
||||
|
||||
axpy_gpu(imlayer.outputs*imlayer.batch, 1, imerror, 1, gnet.layers[gnet.n-1].delta_gpu, 1);
|
||||
axpy_gpu(imlayer.outputs*imlayer.batch, 1, imerror, 1, gnet->layers[gnet->n-1].delta_gpu, 1);
|
||||
|
||||
backward_network_gpu(gnet);
|
||||
|
||||
for(k = 0; k < gnet.batch; ++k){
|
||||
int index = j*gnet.batch + k;
|
||||
copy_cpu(gnet.outputs, gnet.output + k*gnet.outputs, 1, gen.X.vals[index], 1);
|
||||
for(k = 0; k < gnet->batch; ++k){
|
||||
int index = j*gnet->batch + k;
|
||||
copy_cpu(gnet->outputs, gnet->output + k*gnet->outputs, 1, gen.X.vals[index], 1);
|
||||
}
|
||||
}
|
||||
harmless_update_network_gpu(anet);
|
||||
@ -570,8 +567,8 @@ void train_dcgan(char *cfg, char *weight, char *acfg, char *aweight, int clear,
|
||||
//scale_image(im2, .5);
|
||||
#ifdef OPENCV
|
||||
if(display){
|
||||
image im = float_to_image(anet.w, anet.h, anet.c, gen.X.vals[0]);
|
||||
image im2 = float_to_image(anet.w, anet.h, anet.c, train.X.vals[0]);
|
||||
image im = float_to_image(anet->w, anet->h, anet->c, gen.X.vals[0]);
|
||||
image im2 = float_to_image(anet->w, anet->h, anet->c, train.X.vals[0]);
|
||||
show_image(im, "gen");
|
||||
show_image(im2, "train");
|
||||
cvWaitKey(50);
|
||||
@ -580,9 +577,9 @@ void train_dcgan(char *cfg, char *weight, char *acfg, char *aweight, int clear,
|
||||
|
||||
/*
|
||||
if(aloss < .1){
|
||||
anet.learning_rate = 0;
|
||||
anet->learning_rate = 0;
|
||||
} else if (aloss > .3){
|
||||
anet.learning_rate = orig_rate;
|
||||
anet->learning_rate = orig_rate;
|
||||
}
|
||||
*/
|
||||
|
||||
@ -627,21 +624,21 @@ void train_colorizer(char *cfg, char *weight, char *acfg, char *aweight, int cle
|
||||
char *base = basecfg(cfg);
|
||||
char *abase = basecfg(acfg);
|
||||
printf("%s\n", base);
|
||||
network net = load_network(cfg, weight, clear);
|
||||
network anet = load_network(acfg, aweight, clear);
|
||||
network *net = load_network(cfg, weight, clear);
|
||||
network *anet = load_network(acfg, aweight, clear);
|
||||
|
||||
int i, j, k;
|
||||
layer imlayer = {0};
|
||||
for (i = 0; i < net.n; ++i) {
|
||||
if (net.layers[i].out_c == 3) {
|
||||
imlayer = net.layers[i];
|
||||
for (i = 0; i < net->n; ++i) {
|
||||
if (net->layers[i].out_c == 3) {
|
||||
imlayer = net->layers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net.learning_rate, net.momentum, net.decay);
|
||||
int imgs = net.batch*net.subdivisions;
|
||||
i = *net.seen/imgs;
|
||||
printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay);
|
||||
int imgs = net->batch*net->subdivisions;
|
||||
i = *net->seen/imgs;
|
||||
data train, buffer;
|
||||
|
||||
|
||||
@ -663,17 +660,17 @@ void train_colorizer(char *cfg, char *weight, char *acfg, char *aweight, int cle
|
||||
pthread_t load_thread = load_data_in_thread(args);
|
||||
clock_t time;
|
||||
|
||||
int x_size = net.inputs*net.batch;
|
||||
int x_size = net->inputs*net->batch;
|
||||
//int y_size = x_size;
|
||||
net.delta = 0;
|
||||
net.train = 1;
|
||||
net->delta = 0;
|
||||
net->train = 1;
|
||||
float *pixs = calloc(x_size, sizeof(float));
|
||||
float *graypixs = calloc(x_size, sizeof(float));
|
||||
//float *y = calloc(y_size, sizeof(float));
|
||||
|
||||
//int ay_size = anet.outputs*anet.batch;
|
||||
anet.delta = 0;
|
||||
anet.train = 1;
|
||||
//int ay_size = anet->outputs*anet->batch;
|
||||
anet->delta = 0;
|
||||
anet->train = 1;
|
||||
|
||||
float *imerror = cuda_make_array(0, imlayer.outputs*imlayer.batch);
|
||||
|
||||
@ -682,7 +679,7 @@ void train_colorizer(char *cfg, char *weight, char *acfg, char *aweight, int cle
|
||||
|
||||
//data generated = copy_data(train);
|
||||
|
||||
while (get_current_batch(net) < net.max_batches) {
|
||||
while (get_current_batch(net) < net->max_batches) {
|
||||
i += 1;
|
||||
time=clock();
|
||||
pthread_join(load_thread, 0);
|
||||
@ -693,7 +690,7 @@ void train_colorizer(char *cfg, char *weight, char *acfg, char *aweight, int cle
|
||||
|
||||
data gray = copy_data(train);
|
||||
for(j = 0; j < imgs; ++j){
|
||||
image gim = float_to_image(net.w, net.h, net.c, gray.X.vals[j]);
|
||||
image gim = float_to_image(net->w, net->h, net->c, gray.X.vals[j]);
|
||||
grayscale_image_3c(gim);
|
||||
train.y.vals[j][0] = .95;
|
||||
gray.y.vals[j][0] = .05;
|
||||
@ -701,44 +698,44 @@ void train_colorizer(char *cfg, char *weight, char *acfg, char *aweight, int cle
|
||||
time=clock();
|
||||
float gloss = 0;
|
||||
|
||||
for(j = 0; j < net.subdivisions; ++j){
|
||||
get_next_batch(train, net.batch, j*net.batch, pixs, 0);
|
||||
get_next_batch(gray, net.batch, j*net.batch, graypixs, 0);
|
||||
cuda_push_array(net.input_gpu, graypixs, net.inputs*net.batch);
|
||||
cuda_push_array(net.truth_gpu, pixs, net.truths*net.batch);
|
||||
for(j = 0; j < net->subdivisions; ++j){
|
||||
get_next_batch(train, net->batch, j*net->batch, pixs, 0);
|
||||
get_next_batch(gray, net->batch, j*net->batch, graypixs, 0);
|
||||
cuda_push_array(net->input_gpu, graypixs, net->inputs*net->batch);
|
||||
cuda_push_array(net->truth_gpu, pixs, net->truths*net->batch);
|
||||
/*
|
||||
image origi = float_to_image(net.w, net.h, 3, pixs);
|
||||
image grayi = float_to_image(net.w, net.h, 3, graypixs);
|
||||
image origi = float_to_image(net->w, net->h, 3, pixs);
|
||||
image grayi = float_to_image(net->w, net->h, 3, graypixs);
|
||||
show_image(grayi, "gray");
|
||||
show_image(origi, "orig");
|
||||
cvWaitKey(0);
|
||||
*/
|
||||
*net.seen += net.batch;
|
||||
*net->seen += net->batch;
|
||||
forward_network_gpu(net);
|
||||
|
||||
fill_gpu(imlayer.outputs*imlayer.batch, 0, imerror, 1);
|
||||
copy_gpu(anet.inputs*anet.batch, imlayer.output_gpu, 1, anet.input_gpu, 1);
|
||||
fill_gpu(anet.inputs*anet.batch, .95, anet.truth_gpu, 1);
|
||||
anet.delta_gpu = imerror;
|
||||
copy_gpu(anet->inputs*anet->batch, imlayer.output_gpu, 1, anet->input_gpu, 1);
|
||||
fill_gpu(anet->inputs*anet->batch, .95, anet->truth_gpu, 1);
|
||||
anet->delta_gpu = imerror;
|
||||
forward_network_gpu(anet);
|
||||
backward_network_gpu(anet);
|
||||
|
||||
scal_gpu(imlayer.outputs*imlayer.batch, 1./100., net.layers[net.n-1].delta_gpu, 1);
|
||||
scal_gpu(imlayer.outputs*imlayer.batch, 1./100., net->layers[net->n-1].delta_gpu, 1);
|
||||
|
||||
scal_gpu(imlayer.outputs*imlayer.batch, 1, imerror, 1);
|
||||
|
||||
printf("realness %f\n", cuda_mag_array(imerror, imlayer.outputs*imlayer.batch));
|
||||
printf("features %f\n", cuda_mag_array(net.layers[net.n-1].delta_gpu, imlayer.outputs*imlayer.batch));
|
||||
printf("features %f\n", cuda_mag_array(net->layers[net->n-1].delta_gpu, imlayer.outputs*imlayer.batch));
|
||||
|
||||
axpy_gpu(imlayer.outputs*imlayer.batch, 1, imerror, 1, net.layers[net.n-1].delta_gpu, 1);
|
||||
axpy_gpu(imlayer.outputs*imlayer.batch, 1, imerror, 1, net->layers[net->n-1].delta_gpu, 1);
|
||||
|
||||
backward_network_gpu(net);
|
||||
|
||||
|
||||
gloss += *net.cost /(net.subdivisions*net.batch);
|
||||
gloss += *net->cost /(net->subdivisions*net->batch);
|
||||
|
||||
for(k = 0; k < net.batch; ++k){
|
||||
int index = j*net.batch + k;
|
||||
for(k = 0; k < net->batch; ++k){
|
||||
int index = j*net->batch + k;
|
||||
copy_cpu(imlayer.outputs, imlayer.output + k*imlayer.outputs, 1, gray.X.vals[index], 1);
|
||||
}
|
||||
}
|
||||
@ -752,8 +749,8 @@ void train_colorizer(char *cfg, char *weight, char *acfg, char *aweight, int cle
|
||||
|
||||
#ifdef OPENCV
|
||||
if(display){
|
||||
image im = float_to_image(anet.w, anet.h, anet.c, gray.X.vals[0]);
|
||||
image im2 = float_to_image(anet.w, anet.h, anet.c, train.X.vals[0]);
|
||||
image im = float_to_image(anet->w, anet->h, anet->c, gray.X.vals[0]);
|
||||
image im2 = float_to_image(anet->w, anet->h, anet->c, train.X.vals[0]);
|
||||
show_image(im, "gen");
|
||||
show_image(im2, "train");
|
||||
cvWaitKey(50);
|
||||
@ -801,27 +798,27 @@ void train_lsd2(char *cfgfile, char *weightfile, char *acfgfile, char *aweightfi
|
||||
if(weightfile){
|
||||
load_weights(&net, weightfile);
|
||||
}
|
||||
if(clear) *net.seen = 0;
|
||||
if(clear) *net->seen = 0;
|
||||
|
||||
char *abase = basecfg(acfgfile);
|
||||
network anet = parse_network_cfg(acfgfile);
|
||||
if(aweightfile){
|
||||
load_weights(&anet, aweightfile);
|
||||
}
|
||||
if(clear) *anet.seen = 0;
|
||||
if(clear) *anet->seen = 0;
|
||||
|
||||
int i, j, k;
|
||||
layer imlayer = {0};
|
||||
for (i = 0; i < net.n; ++i) {
|
||||
if (net.layers[i].out_c == 3) {
|
||||
imlayer = net.layers[i];
|
||||
for (i = 0; i < net->n; ++i) {
|
||||
if (net->layers[i].out_c == 3) {
|
||||
imlayer = net->layers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net.learning_rate, net.momentum, net.decay);
|
||||
int imgs = net.batch*net.subdivisions;
|
||||
i = *net.seen/imgs;
|
||||
printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay);
|
||||
int imgs = net->batch*net->subdivisions;
|
||||
i = *net->seen/imgs;
|
||||
data train, buffer;
|
||||
|
||||
|
||||
@ -830,21 +827,21 @@ void train_lsd2(char *cfgfile, char *weightfile, char *acfgfile, char *aweightfi
|
||||
char **paths = (char **)list_to_array(plist);
|
||||
|
||||
load_args args = {0};
|
||||
args.w = net.w;
|
||||
args.h = net.h;
|
||||
args.w = net->w;
|
||||
args.h = net->h;
|
||||
args.paths = paths;
|
||||
args.n = imgs;
|
||||
args.m = plist->size;
|
||||
args.d = &buffer;
|
||||
|
||||
args.min = net.min_crop;
|
||||
args.max = net.max_crop;
|
||||
args.angle = net.angle;
|
||||
args.aspect = net.aspect;
|
||||
args.exposure = net.exposure;
|
||||
args.saturation = net.saturation;
|
||||
args.hue = net.hue;
|
||||
args.size = net.w;
|
||||
args.min = net->min_crop;
|
||||
args.max = net->max_crop;
|
||||
args.angle = net->angle;
|
||||
args.aspect = net->aspect;
|
||||
args.exposure = net->exposure;
|
||||
args.saturation = net->saturation;
|
||||
args.hue = net->hue;
|
||||
args.size = net->w;
|
||||
args.type = CLASSIFICATION_DATA;
|
||||
args.classes = 1;
|
||||
char *ls[1] = {"coco"};
|
||||
@ -856,8 +853,8 @@ void train_lsd2(char *cfgfile, char *weightfile, char *acfgfile, char *aweightfi
|
||||
network_state gstate = {0};
|
||||
gstate.index = 0;
|
||||
gstate.net = net;
|
||||
int x_size = get_network_input_size(net)*net.batch;
|
||||
int y_size = 1*net.batch;
|
||||
int x_size = get_network_input_size(net)*net->batch;
|
||||
int y_size = 1*net->batch;
|
||||
gstate.input = cuda_make_array(0, x_size);
|
||||
gstate.truth = 0;
|
||||
gstate.delta = 0;
|
||||
@ -868,7 +865,7 @@ void train_lsd2(char *cfgfile, char *weightfile, char *acfgfile, char *aweightfi
|
||||
network_state astate = {0};
|
||||
astate.index = 0;
|
||||
astate.net = anet;
|
||||
int ay_size = get_network_output_size(anet)*anet.batch;
|
||||
int ay_size = get_network_output_size(anet)*anet->batch;
|
||||
astate.input = 0;
|
||||
astate.truth = 0;
|
||||
astate.delta = 0;
|
||||
@ -883,7 +880,7 @@ void train_lsd2(char *cfgfile, char *weightfile, char *acfgfile, char *aweightfi
|
||||
|
||||
//data generated = copy_data(train);
|
||||
|
||||
while (get_current_batch(net) < net.max_batches) {
|
||||
while (get_current_batch(net) < net->max_batches) {
|
||||
i += 1;
|
||||
time=clock();
|
||||
pthread_join(load_thread, 0);
|
||||
@ -896,10 +893,10 @@ void train_lsd2(char *cfgfile, char *weightfile, char *acfgfile, char *aweightfi
|
||||
time=clock();
|
||||
float gloss = 0;
|
||||
|
||||
for(j = 0; j < net.subdivisions; ++j){
|
||||
get_next_batch(train, net.batch, j*net.batch, X, y);
|
||||
for(j = 0; j < net->subdivisions; ++j){
|
||||
get_next_batch(train, net->batch, j*net->batch, X, y);
|
||||
cuda_push_array(gstate.input, X, x_size);
|
||||
*net.seen += net.batch;
|
||||
*net->seen += net->batch;
|
||||
forward_network_gpu(net, gstate);
|
||||
|
||||
fill_gpu(imlayer.outputs, 0, imerror, 1);
|
||||
@ -917,11 +914,11 @@ void train_lsd2(char *cfgfile, char *weightfile, char *acfgfile, char *aweightfi
|
||||
printf("features %f\n", cuda_mag_array(imlayer.delta_gpu, imlayer.outputs));
|
||||
printf("realness %f\n", cuda_mag_array(imerror, imlayer.outputs));
|
||||
|
||||
gloss += get_network_cost(net) /(net.subdivisions*net.batch);
|
||||
gloss += get_network_cost(net) /(net->subdivisions*net->batch);
|
||||
|
||||
cuda_pull_array(imlayer.output_gpu, imlayer.output, imlayer.outputs*imlayer.batch);
|
||||
for(k = 0; k < net.batch; ++k){
|
||||
int index = j*net.batch + k;
|
||||
for(k = 0; k < net->batch; ++k){
|
||||
int index = j*net->batch + k;
|
||||
copy_cpu(imlayer.outputs, imlayer.output + k*imlayer.outputs, 1, generated.X.vals[index], 1);
|
||||
generated.y.vals[index][0] = 0;
|
||||
}
|
||||
@ -977,10 +974,10 @@ void train_lsd(char *cfgfile, char *weightfile, int clear)
|
||||
if(weightfile){
|
||||
load_weights(&net, weightfile);
|
||||
}
|
||||
if(clear) *net.seen = 0;
|
||||
printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net.learning_rate, net.momentum, net.decay);
|
||||
int imgs = net.batch*net.subdivisions;
|
||||
int i = *net.seen/imgs;
|
||||
if(clear) *net->seen = 0;
|
||||
printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay);
|
||||
int imgs = net->batch*net->subdivisions;
|
||||
int i = *net->seen/imgs;
|
||||
data train, buffer;
|
||||
|
||||
|
||||
@ -989,21 +986,21 @@ void train_lsd(char *cfgfile, char *weightfile, int clear)
|
||||
char **paths = (char **)list_to_array(plist);
|
||||
|
||||
load_args args = {0};
|
||||
args.w = net.w;
|
||||
args.h = net.h;
|
||||
args.w = net->w;
|
||||
args.h = net->h;
|
||||
args.paths = paths;
|
||||
args.n = imgs;
|
||||
args.m = plist->size;
|
||||
args.d = &buffer;
|
||||
|
||||
args.min = net.min_crop;
|
||||
args.max = net.max_crop;
|
||||
args.angle = net.angle;
|
||||
args.aspect = net.aspect;
|
||||
args.exposure = net.exposure;
|
||||
args.saturation = net.saturation;
|
||||
args.hue = net.hue;
|
||||
args.size = net.w;
|
||||
args.min = net->min_crop;
|
||||
args.max = net->max_crop;
|
||||
args.angle = net->angle;
|
||||
args.aspect = net->aspect;
|
||||
args.exposure = net->exposure;
|
||||
args.saturation = net->saturation;
|
||||
args.hue = net->hue;
|
||||
args.size = net->w;
|
||||
args.type = CLASSIFICATION_DATA;
|
||||
args.classes = 1;
|
||||
char *ls[1] = {"coco"};
|
||||
@ -1012,7 +1009,7 @@ void train_lsd(char *cfgfile, char *weightfile, int clear)
|
||||
pthread_t load_thread = load_data_in_thread(args);
|
||||
clock_t time;
|
||||
//while(i*imgs < N*120){
|
||||
while(get_current_batch(net) < net.max_batches){
|
||||
while(get_current_batch(net) < net->max_batches){
|
||||
i += 1;
|
||||
time=clock();
|
||||
pthread_join(load_thread, 0);
|
||||
@ -1045,13 +1042,10 @@ void train_lsd(char *cfgfile, char *weightfile, int clear)
|
||||
}
|
||||
*/
|
||||
|
||||
void test_lsd(char *cfgfile, char *weightfile, char *filename, int gray)
|
||||
void test_lsd(char *cfg, char *weights, char *filename, int gray)
|
||||
{
|
||||
network net = parse_network_cfg(cfgfile);
|
||||
if(weightfile){
|
||||
load_weights(&net, weightfile);
|
||||
}
|
||||
set_batch_network(&net, 1);
|
||||
network *net = load_network(cfg, weights, 0);
|
||||
set_batch_network(net, 1);
|
||||
srand(2222222);
|
||||
|
||||
clock_t time;
|
||||
@ -1059,8 +1053,8 @@ void test_lsd(char *cfgfile, char *weightfile, char *filename, int gray)
|
||||
char *input = buff;
|
||||
int i, imlayer = 0;
|
||||
|
||||
for (i = 0; i < net.n; ++i) {
|
||||
if (net.layers[i].out_c == 3) {
|
||||
for (i = 0; i < net->n; ++i) {
|
||||
if (net->layers[i].out_c == 3) {
|
||||
imlayer = i;
|
||||
printf("%d\n", i);
|
||||
break;
|
||||
@ -1078,8 +1072,8 @@ void test_lsd(char *cfgfile, char *weightfile, char *filename, int gray)
|
||||
strtok(input, "\n");
|
||||
}
|
||||
image im = load_image_color(input, 0, 0);
|
||||
image resized = resize_min(im, net.w);
|
||||
image crop = crop_image(resized, (resized.w - net.w)/2, (resized.h - net.h)/2, net.w, net.h);
|
||||
image resized = resize_min(im, net->w);
|
||||
image crop = crop_image(resized, (resized.w - net->w)/2, (resized.h - net->h)/2, net->w, net->h);
|
||||
if(gray) grayscale_image_3c(crop);
|
||||
|
||||
float *X = crop.data;
|
||||
|
Reference in New Issue
Block a user