 
             free(predecessor_map);
 
-            const size_t num_filters_current_layer = fp->layers[predecessor1]->output_size[2];
+            const size_t num_filters_current_layer = fp->layers[k]->output_size[2];
 
             float_type* copy_linf_coeff;
             float_type* copy_lsup_coeff;

    layer_t* layer = (layer_t*) malloc(sizeof(layer_t));

    layer->num_out_neurons = num_neurons;
    layer->num_in_neurons = 0;

    layer->type = type;
    layer->activation = activation;

                std::swap(shift_y, copy_shift_y);
            }

            add_coeffs_and_csts_sparse<<<dim3(fp->layers[layerno]->output_size[0], fp->layers[layerno]->output_size[1], fp->layers[layerno]->output_size[2]/num_chunks), 1>>>(linf_coeff, lsup_coeff, linf_cst, lsup_cst, copy_linf_coeff, copy_lsup_coeff, copy_linf_cst, copy_lsup_cst, length_x, length_y, copy_length_x, copy_length_y,  fp->layers[common_predecessor]->output_size[2], copy_offset_x - offset_x, copy_offset_y - offset_y);
            add_coeffs_and_csts_sparse<<<dim3(fp->layers[layerno]->output_size[0], fp->layers[layerno]->output_size[1], fp->layers[layerno]->output_size[2]/num_chunks), 1>>>(uinf_coeff, usup_coeff, uinf_cst, usup_cst, copy_uinf_coeff, copy_usup_coeff, copy_uinf_cst, copy_usup_cst, length_x, length_y, copy_length_x, copy_length_y,  fp->layers[common_predecessor]->output_size[2], copy_offset_x - offset_x, copy_offset_y - offset_y);
            // Assume at least one non-residual layer between two residual layers

            cudaFree(copy_linf_coeff);
