本文整理汇总了C++中layer_configuration_specific::get_neuron_count_per_feature_map方法的典型用法代码示例。如果您正苦于以下问题:C++ layer_configuration_specific::get_neuron_count_per_feature_map方法的具体用法?C++ layer_configuration_specific::get_neuron_count_per_feature_map怎么用?C++ layer_configuration_specific::get_neuron_count_per_feature_map使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类layer_configuration_specific
的用法示例。
在下文中一共展示了layer_configuration_specific::get_neuron_count_per_feature_map方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: neural_network_exception
void flip_2d_data_sampler_transformer::transform(
const void * data,
void * data_transformed,
neuron_data_type::input_type type,
const layer_configuration_specific& original_config,
unsigned int sample_id)
{
if (type != neuron_data_type::type_byte)
throw neural_network_exception("flip_2d_data_sampler_transformer is implemented for data stored as bytes only");
if (original_config.dimension_sizes.size() != 2)
throw neural_network_exception((boost::format("flip_2d_data_sampler_transformer is processing 2d data only, data is passed with number of dimensions %1%") % original_config.dimension_sizes.size()).str());
unsigned int neuron_count_per_feature_map = original_config.get_neuron_count_per_feature_map();
for(unsigned int feature_map_id = 0; feature_map_id < original_config.feature_map_count; ++feature_map_id)
{
cv::Mat1b src_image(static_cast<int>(original_config.dimension_sizes[1]), static_cast<int>(original_config.dimension_sizes[0]), const_cast<unsigned char *>(static_cast<const unsigned char *>(data)) + (neuron_count_per_feature_map * feature_map_id));
cv::Mat1b image(static_cast<int>(original_config.dimension_sizes[1]), static_cast<int>(original_config.dimension_sizes[0]), static_cast<unsigned char *>(data_transformed) + (neuron_count_per_feature_map * feature_map_id));
memcpy(
((unsigned char *)data_transformed) + neuron_count_per_feature_map * feature_map_id,
((unsigned char *)data) + neuron_count_per_feature_map * feature_map_id,
neuron_count_per_feature_map * neuron_data_type::get_input_size(type));
if (sample_id == 1)
{
data_transformer_util::flip(
image,
(flip_around_dimension_id == 0),
(flip_around_dimension_id == 1));
}
}
}
示例2: configure
void layer_updater_cuda::configure(
const std::vector<layer_configuration_specific>& input_configuration_specific_list,
const layer_configuration_specific& output_configuration_specific,
layer::const_ptr layer_schema,
cuda_running_configuration::const_ptr cuda_config,
const std::set<layer_action>& actions)
{
this->layer_schema = layer_schema;
this->input_configuration_specific_list = input_configuration_specific_list;
this->output_configuration_specific = output_configuration_specific;
this->cuda_config = cuda_config;
this->actions = actions;
input_elem_count_per_entry_list.resize(input_configuration_specific_list.size());
input_elem_count_per_feature_map_list.resize(input_configuration_specific_list.size());
for(int i = 0; i < input_configuration_specific_list.size(); ++i)
{
input_elem_count_per_entry_list[i] = input_configuration_specific_list[i].get_neuron_count();
input_elem_count_per_feature_map_list[i] = input_configuration_specific_list[i].get_neuron_count_per_feature_map();
}
output_elem_count_per_entry = output_configuration_specific.get_neuron_count();
output_elem_count_per_feature_map = output_configuration_specific.get_neuron_count_per_feature_map();
updater_configured();
}
示例3: run_forward_propagation
void rgb_to_yuv_convert_layer_tester_plain::run_forward_propagation(
plain_buffer::ptr output_buffer,
const std::vector<plain_buffer::const_ptr>& input_buffers,
plain_buffer::ptr temporary_working_fixed_buffer,
plain_buffer::ptr temporary_working_per_entry_buffer,
plain_running_configuration::const_ptr plain_config,
layer::const_ptr layer_schema,
layer_data::const_ptr data,
layer_data_custom::const_ptr data_custom,
const std::vector<layer_configuration_specific>& input_configuration_specific_list,
const layer_configuration_specific& output_configuration_specific,
unsigned int entry_count) const
{
const float * const in_it = *input_buffers[0];
float * const out_it = *output_buffer;
nnforge_shared_ptr<const rgb_to_yuv_convert_layer> layer_derived = nnforge_dynamic_pointer_cast<const rgb_to_yuv_convert_layer>(layer_schema);
const unsigned int color_feature_map_config_count = static_cast<unsigned int>(layer_derived->color_feature_map_config_list.size());
if ((out_it != in_it) && ((color_feature_map_config_count * 3) != output_configuration_specific.feature_map_count))
memcpy(out_it, in_it, output_configuration_specific.get_neuron_count() * entry_count * sizeof(float));
const int total_workload = static_cast<int>(entry_count * color_feature_map_config_count);
const unsigned int input_neuron_count = output_configuration_specific.get_neuron_count();
const unsigned int input_neuron_count_per_feature_map = output_configuration_specific.get_neuron_count_per_feature_map();
const std::vector<color_feature_map_config>::const_iterator cfm_it = layer_derived->color_feature_map_config_list.begin();
#pragma omp parallel for default(none) schedule(guided) num_threads(plain_config->openmp_thread_count)
for(int workload_id = 0; workload_id < total_workload; ++workload_id)
{
int entry_id = workload_id / color_feature_map_config_count;
int color_feature_map_config_id = workload_id - entry_id * color_feature_map_config_count;
const color_feature_map_config& cfm = *(cfm_it + color_feature_map_config_id);
const float * in_it_red_and_y = in_it + (entry_id * input_neuron_count) + (cfm.red_and_y_feature_map_id * input_neuron_count_per_feature_map);
const float * in_it_green_and_u = in_it + (entry_id * input_neuron_count) + (cfm.green_and_u_feature_map_id * input_neuron_count_per_feature_map);
const float * in_it_blue_and_v = in_it + (entry_id * input_neuron_count) + (cfm.blue_and_v_feature_map_id * input_neuron_count_per_feature_map);
float * out_it_red_and_y = out_it + (entry_id * input_neuron_count) + (cfm.red_and_y_feature_map_id * input_neuron_count_per_feature_map);
float * out_it_green_and_u = out_it + (entry_id * input_neuron_count) + (cfm.green_and_u_feature_map_id * input_neuron_count_per_feature_map);
float * out_it_blue_and_v = out_it + (entry_id * input_neuron_count) + (cfm.blue_and_v_feature_map_id * input_neuron_count_per_feature_map);
for(unsigned int i = 0; i < input_neuron_count_per_feature_map; ++i)
{
float red = in_it_red_and_y[i];
float green = in_it_green_and_u[i];
float blue = in_it_blue_and_v[i];
float y = w_r * red + w_g * green + w_b * blue;
float u = u_mult * (blue - y);
float v = v_mult * (red - y);
out_it_red_and_y[i] = y;
out_it_green_and_u[i] = u;
out_it_blue_and_v[i] = v;
}
}
}
示例4: neural_network_exception
void intensity_2d_data_transformer::transform(
const void * data,
void * data_transformed,
neuron_data_type::input_type type,
const layer_configuration_specific& original_config)
{
if (type != neuron_data_type::type_byte)
throw neural_network_exception("intensity_2d_data_transformer is implemented for data stored as bytes only");
if (original_config.dimension_sizes.size() != 2)
throw neural_network_exception((boost::format("intensity_2d_data_transformer is processing 2d data only, data is passed with number of dimensions %1%") % original_config.dimension_sizes.size()).str());
float contrast = contrast_distribution(generator);
float brightness_shift = brightness_shift_distribution(generator) * 255.0F;
unsigned int neuron_count_per_feature_map = original_config.get_neuron_count_per_feature_map();
for(unsigned int feature_map_id = 0; feature_map_id < original_config.feature_map_count; ++feature_map_id)
{
cv::Mat1b image(static_cast<int>(original_config.dimension_sizes[1]), static_cast<int>(original_config.dimension_sizes[0]), static_cast<unsigned char *>(data_transformed) + (neuron_count_per_feature_map * feature_map_id));
data_transformer_util::change_brightness_and_contrast(
image,
contrast,
brightness_shift);
}
}
示例5: transform
void convert_to_polar_data_transformer::transform(
const void * data,
void * data_transformed,
neuron_data_type::input_type type,
const layer_configuration_specific& original_config,
unsigned int sample_id)
{
if (type != neuron_data_type::type_byte)
throw neural_network_exception("convert_to_polar_data_transformer is implemented for data stored as bytes only");
if (original_config.dimension_sizes.size() != 2)
throw neural_network_exception((boost::format("convert_to_polar_data_transformer is processing 2D data only, data is passed with number of dimensions %1%") % original_config.dimension_sizes.size()).str());
if (original_config.dimension_sizes != input_window_sizes)
throw neural_network_exception("convert_to_polar_data_transformer: input window size mismatch between creation and actual transform");
unsigned int original_neuron_count_per_feature_map = original_config.get_neuron_count_per_feature_map();
unsigned int transformed_neuron_count_per_feature_map = get_transformed_configuration(original_config).get_neuron_count_per_feature_map();
for(unsigned int feature_map_id = 0; feature_map_id < original_config.feature_map_count; ++feature_map_id)
{
cv::Mat1b original_image(static_cast<int>(original_config.dimension_sizes[1]), static_cast<int>(original_config.dimension_sizes[0]), const_cast<unsigned char *>(static_cast<const unsigned char *>(data)) + (original_neuron_count_per_feature_map * feature_map_id));
cv::Mat1b dest_image(static_cast<int>(output_window_sizes[1]), static_cast<int>(output_window_sizes[0]), static_cast<unsigned char *>(data_transformed) + (transformed_neuron_count_per_feature_map * feature_map_id));
// Should try INTER_CUBIC and INTER_LANCZOS4 as well
cv::remap(original_image, dest_image, map_x, map_y, cv::INTER_LINEAR, cv::BORDER_CONSTANT, border_value);
}
}
示例6: test
void softmax_layer_hessian_plain::test(
const_additional_buffer_smart_ptr input_buffer,
additional_buffer_smart_ptr output_buffer,
std::vector<additional_buffer_smart_ptr>& additional_buffers,
plain_running_configuration_const_smart_ptr plain_config,
const_layer_smart_ptr layer_schema,
const_layer_data_smart_ptr data,
const_layer_data_custom_smart_ptr data_custom,
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
unsigned int entry_count) const
{
const unsigned int input_neuron_count = input_configuration_specific.get_neuron_count();
const unsigned int input_neuron_count_per_feature_map = input_configuration_specific.get_neuron_count_per_feature_map();
const unsigned int feature_map_count = static_cast<unsigned int>(input_configuration_specific.feature_map_count);
const std::vector<float>::const_iterator input_buffer_it = input_buffer->begin();
const std::vector<float>::iterator output_buffer_it = output_buffer->begin();
const int total_workload = entry_count * input_neuron_count_per_feature_map;
const int openmp_thread_count = plain_config->openmp_thread_count;
#pragma omp parallel default(none) shared(additional_buffers) num_threads(openmp_thread_count)
{
int thread_id = 0;
#ifdef _OPENMP
thread_id = omp_get_thread_num();
#endif
std::vector<float>& local_additional_buffer = *(additional_buffers[thread_id]);
#pragma omp for schedule(guided)
for(int workload_id = 0; workload_id < total_workload; ++workload_id)
{
int entry_id = workload_id / input_neuron_count_per_feature_map;
int neuron_id = workload_id - (entry_id * input_neuron_count_per_feature_map);
const std::vector<float>::const_iterator in_it = input_buffer_it + (entry_id * input_neuron_count) + neuron_id;
const std::vector<float>::iterator out_it = output_buffer_it + (entry_id * input_neuron_count) + neuron_id;
float max_val = -1.0e+37F;
for(unsigned int feature_map_id = 0; feature_map_id < feature_map_count; ++feature_map_id)
{
float val = *(in_it + (feature_map_id * input_neuron_count_per_feature_map));
max_val = std::max(max_val, val);
}
float sum = 0.0F;
for(unsigned int feature_map_id = 0; feature_map_id < feature_map_count; ++feature_map_id)
{
float val = expf((*(in_it + (feature_map_id * input_neuron_count_per_feature_map))) - max_val);
sum += val;
local_additional_buffer[feature_map_id] = val;
}
float mult = 1.0F / sum;
for(unsigned int feature_map_id = 0; feature_map_id < feature_map_count; ++feature_map_id)
*(out_it + (feature_map_id * input_neuron_count_per_feature_map)) = local_additional_buffer[feature_map_id] * mult;
} // for(int workload_id
} // #pragma parallel
}
示例7: transform
void uniform_intensity_data_transformer::transform(
const float * data,
float * data_transformed,
const layer_configuration_specific& original_config,
unsigned int sample_id)
{
if (original_config.feature_map_count != shift_distribution_list.size())
throw neural_network_exception((boost::format("uniform_intensity_data_transformer was initialized with %1% distributions and data provided has %2% feature maps") % shift_distribution_list.size() % original_config.feature_map_count).str());
std::vector<float> shift_list(original_config.feature_map_count);
{
boost::lock_guard<boost::mutex> lock(gen_stream_mutex);
for(unsigned int feature_map_id = 0; feature_map_id < original_config.feature_map_count; ++feature_map_id)
{
nnforge_uniform_real_distribution<float>& dist = shift_distribution_list[feature_map_id];
float shift = dist.min();
if (dist.max() > dist.min())
shift = dist(generator);
shift_list[feature_map_id] = shift;
}
}
unsigned int neuron_count_per_feature_map = original_config.get_neuron_count_per_feature_map();
for(unsigned int feature_map_id = 0; feature_map_id < original_config.feature_map_count; ++feature_map_id)
{
float shift = shift_list[feature_map_id];
const float * src_data = data + feature_map_id * neuron_count_per_feature_map;
float * dest_data = data_transformed + feature_map_id * neuron_count_per_feature_map;
for(unsigned int i = 0; i < neuron_count_per_feature_map; ++i)
dest_data[i] = src_data[i] + shift;
}
}
示例8: backprop
void softmax_layer_hessian_plain::backprop(
additional_buffer_smart_ptr input_errors,
const_additional_buffer_smart_ptr output_errors,
const_additional_buffer_smart_ptr output_neurons,
std::vector<additional_buffer_smart_ptr>& additional_buffers,
plain_running_configuration_const_smart_ptr plain_config,
const_layer_smart_ptr layer_schema,
const_layer_data_smart_ptr data,
const_layer_data_custom_smart_ptr data_custom,
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
unsigned int entry_count) const
{
const unsigned int input_neuron_count = input_configuration_specific.get_neuron_count();
const unsigned int input_neuron_count_per_feature_map = input_configuration_specific.get_neuron_count_per_feature_map();
const unsigned int feature_map_count = static_cast<unsigned int>(input_configuration_specific.feature_map_count);
const std::vector<float>::iterator input_errors_it = input_errors->begin();
const std::vector<float>::const_iterator output_errors_it = output_errors->begin();
const std::vector<float>::const_iterator output_neurons_it = output_neurons->begin();
const int total_workload = entry_count * input_neuron_count_per_feature_map;
const int openmp_thread_count = plain_config->openmp_thread_count;
#pragma omp parallel default(none) shared(additional_buffers) num_threads(openmp_thread_count)
{
int thread_id = 0;
#ifdef _OPENMP
thread_id = omp_get_thread_num();
#endif
#pragma omp for schedule(guided)
for(int workload_id = 0; workload_id < total_workload; ++workload_id)
{
int entry_id = workload_id / input_neuron_count_per_feature_map;
int neuron_id = workload_id - (entry_id * input_neuron_count_per_feature_map);
const std::vector<float>::iterator in_errors_it = input_errors_it + (entry_id * input_neuron_count) + neuron_id;
const std::vector<float>::const_iterator out_errors_it = output_errors_it + (entry_id * input_neuron_count) + neuron_id;
const std::vector<float>::const_iterator out_neurons_it = output_neurons_it + (entry_id * input_neuron_count) + neuron_id;
float sum = 0.0F;
for(unsigned int feature_map_id = 0; feature_map_id < feature_map_count; ++feature_map_id)
{
unsigned int offset = feature_map_id * input_neuron_count_per_feature_map;
float val = (*(out_neurons_it + offset));
sum += val * val * (*(out_errors_it + offset));
}
for(unsigned int feature_map_id = 0; feature_map_id < feature_map_count; ++feature_map_id)
{
unsigned int offset = feature_map_id * input_neuron_count_per_feature_map;
float y = *(out_neurons_it + offset);
float y2 = y * y;
*(in_errors_it + offset) = y2 * ((*(out_errors_it + offset)) * (2.0F * (y2 - y) + 1.0F) - sum);
}
} // for(int workload_id
} // #pragma parallel
}
示例9: get_temporary_working_fixed_buffer_size
size_t local_contrast_subtractive_layer_updater_plain::get_temporary_working_fixed_buffer_size(
const layer_action& action,
const std::set<layer_action>& actions,
plain_running_configuration::const_ptr plain_config,
layer::const_ptr layer_schema,
const std::vector<layer_configuration_specific>& input_configuration_specific_list,
const layer_configuration_specific& output_configuration_specific) const
{
unsigned int elem_count_per_intermediate_elem = output_configuration_specific.get_neuron_count_per_feature_map();
return elem_count_per_intermediate_elem * plain_config->openmp_thread_count * (output_configuration_specific.dimension_sizes.size() > 1 ? 2 : 1) * sizeof(float);
}
示例10: configure
void layer_hessian_cuda::configure(
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
const_layer_smart_ptr layer_schema,
cuda_running_configuration_const_smart_ptr cuda_config,
bool backprop_required)
{
this->layer_schema = layer_schema;
this->input_configuration_specific = input_configuration_specific;
this->output_configuration_specific = output_configuration_specific;
this->cuda_config = cuda_config;
this->backprop_required = backprop_required;
input_elem_count_per_entry = input_configuration_specific.get_neuron_count();
output_elem_count_per_entry = output_configuration_specific.get_neuron_count();
input_elem_count_per_feature_map = input_configuration_specific.get_neuron_count_per_feature_map();
output_elem_count_per_feature_map = output_configuration_specific.get_neuron_count_per_feature_map();
hessian_configured();
}
示例11: run_forward_propagation
void maxout_layer_tester_plain::run_forward_propagation(
plain_buffer::ptr output_buffer,
const std::vector<plain_buffer::const_ptr>& input_buffers,
plain_buffer::ptr temporary_working_fixed_buffer,
plain_buffer::ptr temporary_working_per_entry_buffer,
plain_running_configuration::const_ptr plain_config,
layer::const_ptr layer_schema,
layer_data::const_ptr data,
layer_data_custom::const_ptr data_custom,
const std::vector<layer_configuration_specific>& input_configuration_specific_list,
const layer_configuration_specific& output_configuration_specific,
unsigned int entry_count) const
{
const float * const in_it_global = *input_buffers[0];
float * const out_it_global = *output_buffer;
const unsigned int input_neuron_count = input_configuration_specific_list[0].get_neuron_count();
const unsigned int input_neuron_count_per_feature_map = input_configuration_specific_list[0].get_neuron_count_per_feature_map();
const unsigned int output_neuron_count = output_configuration_specific.get_neuron_count();
const unsigned int output_neuron_count_per_feature_map = output_configuration_specific.get_neuron_count_per_feature_map();
nnforge_shared_ptr<const maxout_layer> layer_derived = nnforge_dynamic_pointer_cast<const maxout_layer>(layer_schema);
const unsigned int feature_map_subsampling_size = layer_derived->feature_map_subsampling_size;
const int output_feature_map_count = output_configuration_specific.feature_map_count;
const int total_workload = entry_count * output_feature_map_count;
#pragma omp parallel default(none) num_threads(plain_config->openmp_thread_count)
{
#pragma omp for schedule(guided)
for(int workload_id = 0; workload_id < total_workload; ++workload_id)
{
int entry_id = workload_id / output_feature_map_count;
int output_feature_map_id = workload_id - (entry_id * output_feature_map_count);
const float * in_it_base = in_it_global + (entry_id * input_neuron_count) + (output_feature_map_id * input_neuron_count_per_feature_map);
float * out_it_base = out_it_global + (entry_id * output_neuron_count) + (output_feature_map_id * output_neuron_count_per_feature_map);
for(float * out_it = out_it_base; out_it != out_it_base + output_neuron_count_per_feature_map; ++out_it, ++in_it_base)
{
const float * in_it = in_it_base;
float current_max = *in_it;
for(unsigned int i = 1; i < feature_map_subsampling_size; ++i)
{
in_it += output_feature_map_count * output_neuron_count_per_feature_map;
float new_val = *in_it;
current_max = std::max(new_val, current_max);
}
*out_it = current_max;
}
}
}
}
示例12: run_forward_propagation
void prefix_sum_layer_tester_plain::run_forward_propagation(
plain_buffer::ptr output_buffer,
const std::vector<plain_buffer::const_ptr>& input_buffers,
plain_buffer::ptr temporary_working_fixed_buffer,
plain_buffer::ptr temporary_working_per_entry_buffer,
plain_running_configuration::const_ptr plain_config,
layer::const_ptr layer_schema,
layer_data::const_ptr data,
layer_data_custom::const_ptr data_custom,
const std::vector<layer_configuration_specific>& input_configuration_specific_list,
const layer_configuration_specific& output_configuration_specific,
unsigned int entry_count) const
{
const float * const in_it_global = *input_buffers[0];
float * const out_it_global = *output_buffer;
const unsigned int neuron_count = output_configuration_specific.get_neuron_count();
std::shared_ptr<const prefix_sum_layer> layer_derived = std::dynamic_pointer_cast<const prefix_sum_layer>(layer_schema);
const unsigned int feature_map_segment_length = layer_derived->feature_map_segment_length;
const unsigned int feature_map_segment_count = output_configuration_specific.feature_map_count / feature_map_segment_length;
const unsigned int neuron_count_per_feature_map = output_configuration_specific.get_neuron_count_per_feature_map();
const float clamp_min = layer_derived->clamp_min;
const float clamp_max = layer_derived->clamp_max;
const int total_workload = entry_count * feature_map_segment_count * neuron_count_per_feature_map;
#pragma omp parallel default(none) num_threads(plain_config->openmp_thread_count)
{
#pragma omp for schedule(guided)
for(int workload_id = 0; workload_id < total_workload; ++workload_id)
{
int entry_id = workload_id / (feature_map_segment_count * neuron_count_per_feature_map);
int tt = workload_id - entry_id * feature_map_segment_count * neuron_count_per_feature_map;
int feature_map_segment_id = tt / neuron_count_per_feature_map;
int neuron_id = tt - feature_map_segment_id * neuron_count_per_feature_map;
int offset = entry_id * neuron_count + feature_map_segment_id * feature_map_segment_length * neuron_count_per_feature_map + neuron_id;
float running_sum = 0.0F;
for(unsigned int i = 0; i < feature_map_segment_length; ++i, offset += neuron_count_per_feature_map)
{
running_sum += in_it_global[offset];
out_it_global[offset] = std::min(std::max(running_sum, clamp_min), clamp_max);
}
}
}
}
示例13: test_non_tiling
void max_subsampling_layer_tester_plain::test_non_tiling(
plain_buffer::ptr output_buffer,
plain_buffer::const_ptr input_buffer,
plain_running_configuration::const_ptr plain_config,
layer::const_ptr layer_schema,
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
unsigned int entry_count) const
{
std::vector<unsigned int> input_dimension_sizes = input_configuration_specific.dimension_sizes;
if (input_dimension_sizes.empty())
input_dimension_sizes.push_back(1);
std::vector<unsigned int> output_dimension_sizes = output_configuration_specific.dimension_sizes;
if (output_dimension_sizes.empty())
output_dimension_sizes.push_back(1);
std::shared_ptr<const max_subsampling_layer> layer_derived = std::dynamic_pointer_cast<const max_subsampling_layer>(layer_schema);
for(std::vector<bool>::const_iterator it = layer_derived->round_ups.begin(); it != layer_derived->round_ups.end(); ++it)
if (*it)
throw neural_network_exception("round up is not implemented for max_subsampling_layer_tester_plain");
const float * const in_it_global = *input_buffer;
float * const out_it_global = *output_buffer;
const unsigned int input_neuron_count = input_configuration_specific.get_neuron_count();
const unsigned int input_neuron_count_per_feature_map = input_configuration_specific.get_neuron_count_per_feature_map();
const unsigned int output_neuron_count = output_configuration_specific.get_neuron_count();
const unsigned int output_neuron_count_per_feature_map = output_configuration_specific.get_neuron_count_per_feature_map();
std::vector<unsigned int> strides = layer_derived->strides;
if (strides.empty())
strides.push_back(1);
std::vector<unsigned int> subsampling_sizes = layer_derived->subsampling_sizes;
if (subsampling_sizes.empty())
subsampling_sizes.push_back(1);
const unsigned int feature_map_subsampling_size = layer_derived->feature_map_subsampling_size;
subsampling_sizes.push_back(feature_map_subsampling_size);
const unsigned int entry_subsampling_size = layer_derived->entry_subsampling_size;
subsampling_sizes.push_back(entry_subsampling_size);
const unsigned int subsampling_dimension_count = static_cast<unsigned int>(subsampling_sizes.size());
const unsigned int spatial_dimension_count = static_cast<unsigned int>(output_dimension_sizes.size());
std::vector<unsigned int> input_slices(subsampling_sizes.size());
input_slices[0] = 1;
for(unsigned int i = 0; i < subsampling_dimension_count - 1; ++i)
{
int dimension_size = (i < spatial_dimension_count) ? input_dimension_sizes[i] : input_configuration_specific.feature_map_count;
input_slices[i + 1] = input_slices[i] * dimension_size;
}
unsigned int subsampling_elem_count = 1;
for(unsigned int i = 0; i < subsampling_dimension_count; ++i)
subsampling_elem_count *= subsampling_sizes[i];
const unsigned int const_subsampling_elem_count = subsampling_elem_count;
const float mult = 1.0F / static_cast<float>(subsampling_elem_count);
const unsigned int output_feature_map_count = output_configuration_specific.feature_map_count;
const bool is_min = layer_derived->is_min;
std::vector<unsigned int> current_local_input_position(subsampling_dimension_count, 0);
std::vector<unsigned int> offset_list(subsampling_elem_count);
for(unsigned int i = 1; i < subsampling_elem_count; ++i)
{
int offset = 0;
for(unsigned int j = 0; j < subsampling_dimension_count; ++j)
{
offset += static_cast<int>(input_slices[j]);
if ((++current_local_input_position[j]) < subsampling_sizes[j])
{
offset_list[i] = offset_list[i-1] + offset;
break;
}
current_local_input_position[j] = 0;
offset -= static_cast<int>(subsampling_sizes[j] * input_slices[j]);
}
}
const int total_workload = entry_count * output_configuration_specific.feature_map_count;
const std::vector<unsigned int>::const_iterator dimension_sizes_it = output_dimension_sizes.begin();
const std::vector<unsigned int>::const_iterator strides_it = strides.begin();
const std::vector<unsigned int>::const_iterator input_slices_it = input_slices.begin();
const std::vector<unsigned int>::const_iterator offset_list_it = offset_list.begin();
#pragma omp parallel default(none) num_threads(plain_config->openmp_thread_count)
{
std::array<unsigned int, max_dimension_count> current_output_position;
#pragma omp for schedule(guided)
for(int workload_id = 0; workload_id < total_workload; ++workload_id)
{
int output_entry_id = workload_id / output_feature_map_count;
int output_feature_map_id = workload_id - (output_entry_id * output_feature_map_count);
const float * in_it_base = in_it_global + (output_entry_id * entry_subsampling_size * input_neuron_count) + (output_feature_map_id * feature_map_subsampling_size * input_neuron_count_per_feature_map);
float * out_it_base = out_it_global + (output_entry_id * output_neuron_count) + (output_feature_map_id * output_neuron_count_per_feature_map);
std::fill_n(current_output_position.begin(), spatial_dimension_count, 0);
for(float * out_it = out_it_base; out_it != out_it_base + output_neuron_count_per_feature_map; ++out_it)
{
// Define the starting position of the first input elem
const float * in_it = in_it_base;
for(unsigned int i = 0; i < spatial_dimension_count; ++i)
in_it += current_output_position[i] * (*(strides_it + i)) * (*(input_slices_it + i));
//.........这里部分代码省略.........
示例14: test
void local_contrast_subtractive_layer_updater_plain::test(
const_additional_buffer_smart_ptr input_buffer,
additional_buffer_smart_ptr output_buffer,
std::vector<additional_buffer_smart_ptr>& additional_buffers,
plain_running_configuration_const_smart_ptr plain_config,
const_layer_smart_ptr layer_schema,
const_layer_data_smart_ptr data,
const_layer_data_custom_smart_ptr data_custom,
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
unsigned int updater_count,
unsigned int offset_input_entry_id) const
{
if (offset_input_entry_id > 0)
throw neural_network_exception("local_contrast_subtractive_layer_updater_plain is not able to run using offset");
const unsigned int input_neuron_count = input_configuration_specific.get_neuron_count();
const unsigned int input_neuron_count_per_feature_map = input_configuration_specific.get_neuron_count_per_feature_map();
const unsigned int output_neuron_count = output_configuration_specific.get_neuron_count();
const unsigned int output_neuron_count_per_feature_map = output_configuration_specific.get_neuron_count_per_feature_map();
nnforge_shared_ptr<const local_contrast_subtractive_layer> layer_derived = nnforge_dynamic_pointer_cast<const local_contrast_subtractive_layer>(layer_schema);
const std::vector<std::vector<float> >& window_weights_list = layer_derived->window_weights_list;
const std::vector<unsigned int>& feature_maps_affected = layer_derived->feature_maps_affected;
const std::vector<unsigned int>& feature_maps_unaffected = layer_derived->feature_maps_unaffected;
const unsigned int dimension_count = static_cast<unsigned int>(window_weights_list.size());
std::vector<unsigned int> input_slices(input_configuration_specific.dimension_sizes.size());
input_slices[0] = 1;
for(unsigned int i = 0; i < dimension_count - 1; ++i)
input_slices[i + 1] = input_slices[i] * input_configuration_specific.dimension_sizes[i];
const std::vector<unsigned int>::const_iterator dimension_sizes_it = output_configuration_specific.dimension_sizes.begin();
const unsigned int feature_maps_affected_count = static_cast<unsigned int>(feature_maps_affected.size());
const unsigned int feature_maps_unaffected_count = static_cast<unsigned int>(feature_maps_affected.size());
const std::vector<unsigned int>::const_iterator input_slices_it = input_slices.begin();
const std::vector<unsigned int>::const_iterator feature_maps_affected_it = feature_maps_affected.begin();
const std::vector<float>::const_iterator input_buffer_it = input_buffer->begin();
const std::vector<float>::iterator output_buffer_it = output_buffer->begin();
const std::vector<std::vector<float> >::const_iterator window_weights_list_it = window_weights_list.begin();
const int total_workload = updater_count * feature_maps_affected_count;
const int openmp_thread_count = plain_config->openmp_thread_count;
#pragma omp parallel default(none) shared(additional_buffers) num_threads(openmp_thread_count)
{
std::vector<additional_buffer_smart_ptr> local_additional_buffers;
int thread_id = 0;
#ifdef _OPENMP
thread_id = omp_get_thread_num();
#endif
local_additional_buffers.push_back(additional_buffers[thread_id]);
if (dimension_count > 1)
local_additional_buffers.push_back(additional_buffers[openmp_thread_count + thread_id]);
#pragma omp for schedule(guided)
for(int workload_id = 0; workload_id < total_workload; ++workload_id)
{
int entry_id = workload_id / feature_maps_affected_count;
int affected_feature_map_id = workload_id - (entry_id * feature_maps_affected_count);
unsigned int current_output_buffer_index = 0;
unsigned int feature_map_id = *(feature_maps_affected_it + affected_feature_map_id);
for(unsigned int dimension_id = 0; dimension_id < dimension_count; ++dimension_id)
{
std::vector<float>::iterator out_it_base = local_additional_buffers[current_output_buffer_index]->begin();
std::vector<float>::const_iterator in_it;
if (dimension_id > 0)
in_it = local_additional_buffers[1 - current_output_buffer_index]->begin();
else
in_it = input_buffer_it + (entry_id * input_neuron_count) + (feature_map_id * input_neuron_count_per_feature_map);
int max_output_size = *(dimension_sizes_it + dimension_id);
int input_slice_size = *(input_slices_it + dimension_id);
std::vector<unsigned int> current_output_position(dimension_count, 0);
for(std::vector<float>::iterator out_it = out_it_base; out_it != out_it_base + output_neuron_count_per_feature_map; ++out_it, ++in_it)
{
const std::vector<float>& current_window_weights_list = *(window_weights_list_it + dimension_id);
float sum = *in_it * current_window_weights_list[0];
int current_position = static_cast<int>(current_output_position[dimension_id]);
int dest_forward = current_position;
int dest_backward = dest_forward;
for (std::vector<float>::const_iterator it = current_window_weights_list.begin() + 1; it != current_window_weights_list.end(); ++it)
{
dest_forward++;
dest_backward--;
int dest_forward_actual = (dest_forward < max_output_size) ? dest_forward : (((max_output_size << 1) - 1) - dest_forward);
int dest_backward_actual = (dest_backward >= 0) ? dest_backward : (-1 - dest_backward);
int offset_forward = ((dest_forward_actual - current_position) * input_slice_size);
int offset_backward = ((dest_backward_actual - current_position) * input_slice_size);
sum += (*(in_it + offset_forward) + *(in_it + offset_backward)) * (*it);
}
*out_it = sum;
// Go to the next output element
for(unsigned int i = 0; i < dimension_count; ++i)
{
if ((++current_output_position[i]) < *(dimension_sizes_it + i))
break;
//.........这里部分代码省略.........
示例15: test
void sparse_convolution_layer_updater_plain::test(
const_additional_buffer_smart_ptr input_buffer,
additional_buffer_smart_ptr output_buffer,
std::vector<additional_buffer_smart_ptr>& additional_buffers,
plain_running_configuration_const_smart_ptr plain_config,
const_layer_smart_ptr layer_schema,
const_layer_data_smart_ptr data,
const_layer_data_custom_smart_ptr data_custom,
const layer_configuration_specific& input_configuration_specific,
const layer_configuration_specific& output_configuration_specific,
unsigned int updater_count,
unsigned int offset_input_entry_id) const
{
const unsigned int input_neuron_count = input_configuration_specific.get_neuron_count();
const unsigned int input_neuron_count_per_feature_map = input_configuration_specific.get_neuron_count_per_feature_map();
const unsigned int output_neuron_count = output_configuration_specific.get_neuron_count();
const unsigned int output_neuron_count_per_feature_map = output_configuration_specific.get_neuron_count_per_feature_map();
const std::vector<float>::const_iterator in_it_global = input_buffer->begin() + input_neuron_count * offset_input_entry_id;
const std::vector<float>::iterator out_it_global = output_buffer->begin();
nnforge_shared_ptr<const sparse_convolution_layer> layer_derived = nnforge_dynamic_pointer_cast<const sparse_convolution_layer>(layer_schema);
const std::vector<unsigned int>& window_sizes = layer_derived->window_sizes;
const unsigned int dimension_count = static_cast<unsigned int>(window_sizes.size());
std::vector<unsigned int> input_slices(input_configuration_specific.dimension_sizes.size());
input_slices[0] = 1;
for(unsigned int i = 0; i < dimension_count - 1; ++i)
input_slices[i + 1] = input_slices[i] * input_configuration_specific.dimension_sizes[i];
unsigned int window_elem_count = 1;
for(unsigned int i = 0; i < dimension_count; ++i)
window_elem_count *= window_sizes[i];
const unsigned int const_window_elem_count = window_elem_count;
const std::vector<float>::const_iterator weights = (*data)[0].begin();
const std::vector<float>::const_iterator biases = (*data)[1].begin();
const std::vector<int>::const_iterator column_indices = (*data_custom)[0].begin();
const std::vector<int>::const_iterator row_indices = (*data_custom)[1].begin();
std::vector<unsigned int> current_local_input_position(dimension_count, 0);
std::vector<unsigned int> offset_list(window_elem_count);
for(unsigned int i = 1; i < window_elem_count; ++i)
{
int offset = 0;
for(unsigned int j = 0; j < dimension_count; ++j)
{
offset += static_cast<int>(input_slices[j]);
if ((++current_local_input_position[j]) < window_sizes[j])
{
offset_list[i] = offset_list[i-1] + offset;
break;
}
current_local_input_position[j] = 0;
offset -= static_cast<int>(window_sizes[j] * input_slices[j]);
}
}
const unsigned int output_feature_map_count = output_configuration_specific.feature_map_count;
const unsigned int input_feature_map_count = input_configuration_specific.feature_map_count;
const int total_workload = updater_count * output_feature_map_count;
const std::vector<unsigned int>::const_iterator output_dimension_sizes_it = output_configuration_specific.dimension_sizes.begin();
const std::vector<unsigned int>::const_iterator input_slices_it = input_slices.begin();
const std::vector<unsigned int>::const_iterator offset_list_it = offset_list.begin();
#pragma omp parallel default(none) num_threads(plain_config->openmp_thread_count)
{
nnforge_array<unsigned int, max_dimension_count> current_output_position;
#pragma omp for schedule(guided)
for(int workload_id = 0; workload_id < total_workload; ++workload_id)
{
int entry_id = workload_id / output_feature_map_count;
int output_feature_map_id = workload_id - (entry_id * output_feature_map_count);
std::vector<float>::iterator out_it_base = out_it_global + (entry_id * output_neuron_count) + (output_feature_map_id * output_neuron_count_per_feature_map);
std::vector<float>::const_iterator in_it_base = in_it_global + entry_id * input_neuron_count;
const int start_column_index = row_indices[output_feature_map_id];
const int end_column_index = row_indices[output_feature_map_id + 1];
std::fill_n(current_output_position.begin(), dimension_count, 0);
for(std::vector<float>::iterator out_it = out_it_base; out_it != out_it_base + output_neuron_count_per_feature_map; ++out_it)
{
float sum = *(biases + output_feature_map_id);
std::vector<float>::const_iterator weights_it = weights + start_column_index * const_window_elem_count;
std::vector<float>::const_iterator in_it_base2 = in_it_base;
for(unsigned int i = 0; i < dimension_count; ++i)
in_it_base2 += current_output_position[i] * (*(input_slices_it + i));
for(int column_index = start_column_index; column_index < end_column_index; ++column_index)
{
int input_feature_map_id = column_indices[column_index];
// Define the starting position of the first input elem
std::vector<float>::const_iterator in_it = in_it_base2 + (input_feature_map_id * input_neuron_count_per_feature_map);
for(unsigned int i = 0; i < const_window_elem_count; ++i)
{
sum += (*(in_it + *(offset_list_it + i))) * (*weights_it);
++weights_it;
}
}
//.........这里部分代码省略.........