mirror of
https://github.com/pjreddie/darknet.git
synced 2023-08-10 21:13:14 +03:00
Optimized resizing of network for random=1
This commit is contained in:
@ -359,6 +359,8 @@ void test_convolutional_layer()
|
|||||||
|
|
||||||
void resize_convolutional_layer(convolutional_layer *l, int w, int h)
|
void resize_convolutional_layer(convolutional_layer *l, int w, int h)
|
||||||
{
|
{
|
||||||
|
int old_w = l->w;
|
||||||
|
int old_h = l->h;
|
||||||
l->w = w;
|
l->w = w;
|
||||||
l->h = h;
|
l->h = h;
|
||||||
int out_w = convolutional_out_width(*l);
|
int out_w = convolutional_out_width(*l);
|
||||||
@ -378,6 +380,7 @@ void resize_convolutional_layer(convolutional_layer *l, int w, int h)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef GPU
|
#ifdef GPU
|
||||||
|
if (old_w < w || old_h < h) {
|
||||||
cuda_free(l->delta_gpu);
|
cuda_free(l->delta_gpu);
|
||||||
cuda_free(l->output_gpu);
|
cuda_free(l->output_gpu);
|
||||||
|
|
||||||
@ -391,6 +394,7 @@ void resize_convolutional_layer(convolutional_layer *l, int w, int h)
|
|||||||
l->x_gpu = cuda_make_array(l->output, l->batch*l->outputs);
|
l->x_gpu = cuda_make_array(l->output, l->batch*l->outputs);
|
||||||
l->x_norm_gpu = cuda_make_array(l->output, l->batch*l->outputs);
|
l->x_norm_gpu = cuda_make_array(l->output, l->batch*l->outputs);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#ifdef CUDNN
|
#ifdef CUDNN
|
||||||
cudnn_convolutional_setup(l);
|
cudnn_convolutional_setup(l);
|
||||||
#endif
|
#endif
|
||||||
|
@ -328,6 +328,12 @@ int resize_network(network *net, int w, int h)
|
|||||||
cuda_set_device(net->gpu_index);
|
cuda_set_device(net->gpu_index);
|
||||||
if(gpu_index >= 0){
|
if(gpu_index >= 0){
|
||||||
cuda_free(net->workspace);
|
cuda_free(net->workspace);
|
||||||
|
if (net->input_gpu) {
|
||||||
|
cuda_free(*net->input_gpu);
|
||||||
|
*net->input_gpu = 0;
|
||||||
|
cuda_free(*net->truth_gpu);
|
||||||
|
*net->truth_gpu = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
int i;
|
int i;
|
||||||
@ -340,6 +346,7 @@ int resize_network(network *net, int w, int h)
|
|||||||
//fflush(stderr);
|
//fflush(stderr);
|
||||||
for (i = 0; i < net->n; ++i){
|
for (i = 0; i < net->n; ++i){
|
||||||
layer l = net->layers[i];
|
layer l = net->layers[i];
|
||||||
|
printf(" %d: layer = %d,", i, l.type);
|
||||||
if(l.type == CONVOLUTIONAL){
|
if(l.type == CONVOLUTIONAL){
|
||||||
resize_convolutional_layer(&l, w, h);
|
resize_convolutional_layer(&l, w, h);
|
||||||
}else if(l.type == CROP){
|
}else if(l.type == CROP){
|
||||||
@ -371,13 +378,8 @@ int resize_network(network *net, int w, int h)
|
|||||||
}
|
}
|
||||||
#ifdef GPU
|
#ifdef GPU
|
||||||
if(gpu_index >= 0){
|
if(gpu_index >= 0){
|
||||||
if(net->input_gpu) {
|
|
||||||
cuda_free(*net->input_gpu);
|
|
||||||
*net->input_gpu = 0;
|
|
||||||
cuda_free(*net->truth_gpu);
|
|
||||||
*net->truth_gpu = 0;
|
|
||||||
}
|
|
||||||
net->workspace = cuda_make_array(0, (workspace_size-1)/sizeof(float)+1);
|
net->workspace = cuda_make_array(0, (workspace_size-1)/sizeof(float)+1);
|
||||||
|
printf(" CUDA allocate done! \n");
|
||||||
}else {
|
}else {
|
||||||
free(net->workspace);
|
free(net->workspace);
|
||||||
net->workspace = calloc(1, workspace_size);
|
net->workspace = calloc(1, workspace_size);
|
||||||
|
Reference in New Issue
Block a user