float linear_sampler_layer::get_flops_per_entry(
		const std::vector<layer_configuration_specific>& input_configuration_specific_list,
		const layer_action& action) const
	{
		switch (action.get_action_type())
		{
		case layer_action::forward:
			{
				layer_configuration_specific output_config = get_output_layer_configuration_specific(input_configuration_specific_list);
				unsigned int neuron_count_per_feature_map = output_config.get_neuron_count_per_feature_map();
				unsigned int per_feature_map_work = 7;
				unsigned int constant_work = 12;
				return static_cast<float>(neuron_count_per_feature_map) * static_cast<float>(constant_work + per_feature_map_work * output_config.feature_map_count);
			}
		case layer_action::backward_data:
			{
				layer_configuration_specific output_config = get_output_layer_configuration_specific(input_configuration_specific_list);
				unsigned int neuron_count_per_feature_map = output_config.get_neuron_count_per_feature_map();
				unsigned int per_feature_map_work = 8;
				unsigned int constant_work = 18;
				return static_cast<float>(neuron_count_per_feature_map) * static_cast<float>(constant_work + per_feature_map_work * output_config.feature_map_count);
			}
		case layer_action::backward_weights:
		default:
			return 0.0F;
		}
	}
	float convolution_layer::get_weights_update_flops_2nd(const layer_configuration_specific& input_configuration_specific) const
	{
		unsigned int neuron_count = get_output_layer_configuration_specific(input_configuration_specific).get_neuron_count();
		unsigned int per_item_flops = input_feature_map_count * 2;
		std::for_each(window_sizes.begin(), window_sizes.end(), per_item_flops *= boost::lambda::_1);

		return (static_cast<float>(neuron_count) * static_cast<float>(per_item_flops)) + static_cast<float>(input_configuration_specific.get_neuron_count());
	}
	float average_subsampling_layer::get_forward_flops(const layer_configuration_specific& input_configuration_specific) const
	{
		unsigned int neuron_count = get_output_layer_configuration_specific(input_configuration_specific).get_neuron_count();
		unsigned int per_item_flops = 1;
		std::for_each(subsampling_sizes.begin(), subsampling_sizes.end(), per_item_flops *= boost::lambda::_1);

		return static_cast<float>(neuron_count) * static_cast<float>(per_item_flops);
	}
Beispiel #4
0
	float accuracy_layer::get_flops_per_entry(
		const std::vector<layer_configuration_specific>& input_configuration_specific_list,
		const layer_action& action) const
	{
		switch (action.get_action_type())
		{
		case layer_action::forward:
			{
				unsigned int neuron_count = get_output_layer_configuration_specific(input_configuration_specific_list).get_neuron_count();
				unsigned int per_item_flops = input_configuration_specific_list[0].feature_map_count * 2;
				return static_cast<float>(neuron_count) * static_cast<float>(per_item_flops);
			}
		case layer_action::backward_data:
			throw neural_network_exception("get_backward_flops is not implemented for accuracy_layer");
		default:
			return 0.0F;
		}
	}
	float max_subsampling_layer::get_flops_per_entry(
		const std::vector<layer_configuration_specific>& input_configuration_specific_list,
		const layer_action& action) const
	{
		switch (action.get_action_type())
		{
		case layer_action::forward:
			{
				unsigned int neuron_count = get_output_layer_configuration_specific(input_configuration_specific_list).get_neuron_count();
				unsigned int per_item_flops = feature_map_subsampling_size * entry_subsampling_size;
				std::for_each(subsampling_sizes.begin(), subsampling_sizes.end(), [&per_item_flops] (unsigned int x) { per_item_flops *= x; });
				per_item_flops -= 1;
				return static_cast<float>(neuron_count) * static_cast<float>(per_item_flops);
			}
		case layer_action::backward_data:
			return 0.0F;
		default:
			return 0.0F;
		}
	}
	float negative_log_likelihood_layer::get_flops_per_entry(
		const std::vector<layer_configuration_specific>& input_configuration_specific_list,
		const layer_action& action) const
	{
		switch (action.get_action_type())
		{
		case layer_action::forward:
			{
				unsigned int neuron_count = get_output_layer_configuration_specific(input_configuration_specific_list).get_neuron_count();
				unsigned int per_item_flops = input_configuration_specific_list[0].feature_map_count * 3;
				return static_cast<float>(neuron_count) * static_cast<float>(per_item_flops);
			}
		case layer_action::backward_data:
			{
				unsigned int neuron_count = input_configuration_specific_list[action.get_backprop_index()].get_neuron_count();
				unsigned int per_item_flops = 2;
				return static_cast<float>(neuron_count) * static_cast<float>(per_item_flops);
			}
		default:
			return 0.0F;
		}
	}
	float average_subsampling_layer::get_backward_flops(const layer_configuration_specific& input_configuration_specific) const
	{
		unsigned int neuron_count = get_output_layer_configuration_specific(input_configuration_specific).get_neuron_count();

		return static_cast<float>(neuron_count);
	}