Skip to content
This repository was archived by the owner on Dec 21, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace one_shot_object_detection {
namespace data_augmentation {

flex_dict build_annotation(ParameterSampler &parameter_sampler,
std::string label,
const std::string &label,
size_t object_width, size_t object_height,
size_t background_width, size_t background_height,
size_t seed, size_t row_number) {
Expand Down Expand Up @@ -150,7 +150,7 @@ create_synthetic_image_from_background_and_starter(ParameterSampler &parameter_s
reinterpret_cast<const boost::gil::rgba8_pixel_t *>(
rgba_flex_image.get_image_data()),
rgba_flex_image.m_channels *
rgba_flex_image.m_width // row length in bytes
rgba_flex_image.m_width // row length in bytes
);

boost::gil::rgb8_image_t::const_view_t background_view = interleaved_view(
Expand Down Expand Up @@ -210,7 +210,7 @@ gl_sframe augment_data(const gl_sframe &data,
* Replacing the `for` with a `parallel_for` fails the export_coreml unit test
* with an EXC_BAD_ACCESS in the function call to boost::gil::resample_pixels
*/
for (const auto &row : decompressed_data.range_iterator()) {
for (const sframe_rows::row &row : decompressed_data.range_iterator()) {
// go through all the starter images and create augmented images for
// all starter images and the respective chunk of background images
const flex_image &object = row[image_column_index].get<flex_image>();
Expand All @@ -222,7 +222,7 @@ gl_sframe augment_data(const gl_sframe &data,
size_t segment_start = (segment_id * backgrounds.size()) / nsegments;
size_t segment_end = ((segment_id + 1) * backgrounds.size()) / nsegments;
size_t row_number = segment_start;
for (const auto &background_ft :
for (const flexible_type &background_ft :
backgrounds.range_iterator(segment_start, segment_end)) {
row_number++;
flex_image flex_background =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include <core/data/image/numeric_extension/perspective_projection.hpp>
#include <core/logging/assertions.hpp>
#include <limits>

#include <toolkits/object_detection/one_shot_object_detection/util/parameter_sampler.hpp>
Expand Down Expand Up @@ -62,6 +63,12 @@ void ParameterSampler::set_warped_corners(
warped_corners_[3] = warped_corners[2];
}

int generate_random_index(std::mt19937 engine, int range) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not copy the engine, otherwise you're actually going to get the same random values every time. Here you must pass the engine by reference or as a pointer. Your goal is to reuse the same engine across all the random draws for a single row, not produce draws from individual copies of the original engine.

DASSERT_GT(range, 0);
std::uniform_int_distribution<int> index_distribution(0, range-1);
return index_distribution(engine);
}

/* Function to sample all the parameters needed to build a transform, and
* then also build the transform.
*/
Expand All @@ -71,15 +78,14 @@ void ParameterSampler::sample(size_t background_width, size_t background_height,
std::seed_seq seed_seq = {static_cast<int>(seed), static_cast<int>(row_number)};
std::mt19937 engine(seed_seq);

std::uniform_int_distribution<int> index_distribution(0, INT_MAX);
theta_mean = theta_means_[index_distribution(engine) % theta_means_.size()];
phi_mean = phi_means_[index_distribution(engine) % phi_means_.size()];
gamma_mean = gamma_means_[index_distribution(engine) % gamma_means_.size()];
theta_mean = theta_means_[generate_random_index(engine, theta_means_.size())];
phi_mean = phi_means_[generate_random_index(engine, phi_means_.size())];
gamma_mean = gamma_means_[generate_random_index(engine, gamma_means_.size())];

std::normal_distribution<double> theta_distribution(theta_mean, angle_stdev_);
std::normal_distribution<double> phi_distribution(phi_mean, angle_stdev_);
std::normal_distribution<double> gamma_distribution(gamma_mean, angle_stdev_);
std::normal_distribution<double> focal_distribution((double)background_width,
std::normal_distribution<double> focal_distribution(static_cast<double>(background_width),
focal_stdev_);
theta_ = theta_distribution(engine);
phi_ = phi_distribution(engine);
Expand Down