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); } }
void gtsrb_toolset::write_folder( nnforge::supervised_data_stream_writer& writer, const boost::filesystem::path& relative_subfolder_path, const char * annotation_file_name, bool jitter) { boost::filesystem::path subfolder_path = get_input_data_folder() / relative_subfolder_path; boost::filesystem::path annotation_file_path = subfolder_path / annotation_file_name; std::cout << "Reading input data from " << subfolder_path.string() << std::endl; boost::filesystem::ifstream file_input(annotation_file_path, std::ios_base::in); nnforge::random_generator generator = nnforge::rnd::get_random_generator(); std::tr1::uniform_real<float> rotate_angle_distribution(-max_rotation_angle_in_degrees, max_rotation_angle_in_degrees); std::tr1::uniform_real<float> scale_distribution(1.0F / max_scale_factor, max_scale_factor); std::tr1::uniform_real<float> shift_distribution(-max_shift, max_shift); std::tr1::uniform_real<float> contrast_distribution(1.0F / max_contrast_factor, max_contrast_factor); std::tr1::uniform_real<float> brightness_shift_distribution(-max_brightness_shift, max_brightness_shift); std::string str; std::getline(file_input, str); // read the header while (true) { std::getline(file_input, str); std::vector<std::string> strs; boost::split(strs, str, boost::is_any_of(";")); if (strs.size() != 8) break; std::string file_name = strs[0]; boost::filesystem::path absolute_file_path = subfolder_path / file_name; char* end; unsigned int top_left_x = static_cast<unsigned int>(strtol(strs[3].c_str(), &end, 10)); unsigned int top_left_y = static_cast<unsigned int>(strtol(strs[4].c_str(), &end, 10)); unsigned int bottom_right_x = static_cast<unsigned int>(strtol(strs[5].c_str(), &end, 10)); unsigned int bottom_right_y = static_cast<unsigned int>(strtol(strs[6].c_str(), &end, 10)); unsigned int class_id = static_cast<unsigned int>(strtol(strs[7].c_str(), &end, 10)); if (jitter) { for(int i = 0; i < random_sample_count; ++i) { float rotation_angle = rotate_angle_distribution(generator); float scale = scale_distribution(generator); float shift_x = shift_distribution(generator); float shift_y = shift_distribution(generator); float contrast = contrast_distribution(generator); float brightness_shift = brightness_shift_distribution(generator); write_single_entry( writer, absolute_file_path, class_id, top_left_x, top_left_y, bottom_right_x, bottom_right_y, rotation_angle, scale, shift_x, shift_y, contrast, brightness_shift); } } else { write_single_entry( writer, absolute_file_path, class_id, top_left_x, top_left_y, bottom_right_x, bottom_right_y); } } }