-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
119 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2011-2013 Maxim Milakov | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "noise_data_transformer.h" | ||
|
||
#include "neural_network_exception.h" | ||
|
||
#include <opencv2/core/core.hpp> | ||
#include <boost/format.hpp> | ||
|
||
namespace nnforge | ||
{ | ||
noise_data_transformer::noise_data_transformer( | ||
bool is_same_sequence_from_reset, | ||
unsigned int max_noise) | ||
: is_same_sequence_from_reset(is_same_sequence_from_reset) | ||
{ | ||
if (!is_same_sequence_from_reset) | ||
generator = rnd::get_random_generator(); | ||
|
||
max_noise_distribution = std::tr1::uniform_int<int>(-static_cast<int>(max_noise), static_cast<int>(max_noise)); | ||
} | ||
|
||
noise_data_transformer::~noise_data_transformer() | ||
{ | ||
} | ||
|
||
void noise_data_transformer::reset() | ||
{ | ||
if (is_same_sequence_from_reset) | ||
generator = rnd::get_random_generator(48576435); | ||
} | ||
|
||
void noise_data_transformer::transform( | ||
const void * input_data, | ||
void * output_data, | ||
neuron_data_type::input_type type, | ||
const layer_configuration_specific& original_config) | ||
{ | ||
if (type != neuron_data_type::type_byte) | ||
throw neural_network_exception("noise_data_transformer is implemented for data stored as bytes only"); | ||
|
||
unsigned char * data = static_cast<unsigned char *>(output_data); | ||
unsigned int elem_count = original_config.get_neuron_count(); | ||
|
||
for(unsigned char * data_it = data; data_it != (data + elem_count); data_it++) | ||
{ | ||
int shift = max_noise_distribution(generator); | ||
*data_it = static_cast<unsigned char>(std::min<int>(std::max<int>((shift + static_cast<int>(*data_it)), 0), 255)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2011-2013 Maxim Milakov | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "data_transformer.h" | ||
|
||
#include "rnd.h" | ||
|
||
#include <memory> | ||
|
||
namespace nnforge | ||
{ | ||
class noise_data_transformer : public data_transformer | ||
{ | ||
public: | ||
noise_data_transformer( | ||
bool is_same_sequence_from_reset, | ||
unsigned int max_noise); | ||
|
||
virtual ~noise_data_transformer(); | ||
|
||
virtual void transform( | ||
const void * input_data, | ||
void * output_data, | ||
neuron_data_type::input_type type, | ||
const layer_configuration_specific& original_config); | ||
|
||
virtual void reset(); | ||
|
||
protected: | ||
bool is_same_sequence_from_reset; | ||
random_generator generator; | ||
|
||
std::tr1::uniform_int<int> max_noise_distribution; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters