Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New warp example #1158

Merged
merged 3 commits into from
Oct 30, 2019
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
9 changes: 7 additions & 2 deletions dali/core/format_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@

namespace dali {

TEST(MakeStringTest, default_delimiter) {
TEST(MakeStringTest, no_delimiter) {
auto str = make_string("jeden", 2, 3);
ASSERT_EQ(str, "jeden23");
}

TEST(MakeStringTest, char_delimiter) {
auto str = make_string_delim(' ', "jeden", 2, 3);
ASSERT_EQ(str, "jeden 2 3");
}


TEST(MakeStringTest, custom_delimiter) {
TEST(MakeStringTest, string_delimiter) {
auto str = make_string_delim("a custom delimiter", "jeden", 2, 3);
ASSERT_EQ(str, "jedena custom delimiter2a custom delimiter3");
}
Expand Down
2 changes: 1 addition & 1 deletion dali/image/bmp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int number_of_channels(int bpp, int compression_type,
}

DALI_WARN(make_string(
"configuration not supported. bpp:", bpp, "compression_type:", compression_type,
"configuration not supported. bpp: ", bpp, " compression_type:", compression_type,
"ncolors:", ncolors));
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion dali/image/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class Image {
crop_window_generator_ = [crop_window](const TensorShape<>& shape,
const TensorLayout& shape_layout) {
DALI_ENFORCE(shape_layout == "HW",
make_string("Unexpected input shape layout:", shape_layout.c_str(), "vs HW"));
make_string("Unexpected input shape layout: ", shape_layout, " vs HW"));
DALI_ENFORCE(crop_window.IsInRange(shape),
"crop_window["
+ std::to_string(crop_window.anchor[1])
Expand Down
8 changes: 4 additions & 4 deletions dali/kernels/imgproc/pointwise/linear_transformation_gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ class LinearTransformationGpu {
"Provide ROIs either for all or none input tensors");
for (int i = 0; i < in.size(); i++) {
DALI_ENFORCE(in[i].shape.shape.back() == channels_in,
make_string("Unexpected number of channels at index", i,
"in InListGPU. Number of channels in every InListGPU has to match"
make_string("Unexpected number of channels at index ", i,
" in InListGPU. Number of channels in every InListGPU has to match"
" the number of channels, that the kernel is instantiated with"));
}
for (int i = 0; i < rois.size(); i++) {
DALI_ENFORCE(all_coords(rois[i].hi >= rois[i].lo),
make_string("Found invalid ROI at index", i,
"ROI doesn't follow {lo, hi} convention.", rois[i]));
make_string("Found invalid ROI at index ", i,
"ROI doesn't follow {lo, hi} convention. ", rois[i]));
}

gen_default_values(in.num_samples());
Expand Down
4 changes: 2 additions & 2 deletions dali/operators/color/brightness_contrast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ bool BrightnessContrastCpu::SetupImpl(std::vector<OutputDesc> &output_desc,
type.SetType<OutputType>(output_type_);
output_desc[0] = {shapes, type};
}
), DALI_FAIL(make_string("Unsupported output type:", output_type_))) // NOLINT
), DALI_FAIL(make_string("Unsupported input type:", input.type().id()))) // NOLINT
), DALI_FAIL(make_string("Unsupported output type: ", output_type_))) // NOLINT
), DALI_FAIL(make_string("Unsupported input type: ", input.type().id()))) // NOLINT
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions dali/operators/color/brightness_contrast.cu
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ bool BrightnessContrastGpu::SetupImpl(std::vector<OutputDesc> &output_desc,
type.SetType<OutputType>(output_type_);
output_desc[0] = {shapes, type};
}
), DALI_FAIL(make_string("Unsupported output type:", output_type_))) // NOLINT
), DALI_FAIL(make_string("Unsupported input type:", input.type().id()))) // NOLINT
), DALI_FAIL(make_string("Unsupported output type: ", output_type_))) // NOLINT
), DALI_FAIL(make_string("Unsupported input type: ", input.type().id()))) // NOLINT
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions dali/operators/color/hsv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ bool HsvCpu::SetupImpl(std::vector<OutputDesc> &output_desc, const workspace_t<C
type.SetType<OutputType>(output_type_);
output_desc[0] = {shapes, type};
}
), DALI_FAIL(make_string("Unsupported output type:", output_type_))) // NOLINT
), DALI_FAIL(make_string("Unsupported input type:", input.type().id()))) // NOLINT
), DALI_FAIL(make_string("Unsupported output type: ", output_type_))) // NOLINT
), DALI_FAIL(make_string("Unsupported input type: ", input.type().id()))) // NOLINT
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions dali/operators/color/hsv.cu
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ bool HsvGpu::SetupImpl(std::vector<OutputDesc> &output_desc, const workspace_t<G
type.SetType<OutputType>(output_type_);
output_desc[0] = {shapes, type};
}
), DALI_FAIL(make_string("Unsupported output type:", output_type_))) // NOLINT
), DALI_FAIL(make_string("Unsupported input type:", input.type().id()))) // NOLINT
), DALI_FAIL(make_string("Unsupported output type: ", output_type_))) // NOLINT
), DALI_FAIL(make_string("Unsupported input type: ", input.type().id()))) // NOLINT
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion dali/operators/crop/crop_attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class CropAttr {
[this, data_idx](const TensorShape<>& input_shape,
const TensorLayout& shape_layout) {
DALI_ENFORCE(shape_layout == "HW" || shape_layout == "DHW",
make_string("Unexpected input shape layout:", shape_layout.c_str(),
make_string("Unexpected input shape layout: ", shape_layout,
" (expected HW or DHW)"));
CropWindow crop_window;
if (input_shape.size() == 3) {
Expand Down
8 changes: 4 additions & 4 deletions dali/operators/crop/slice_attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ class SliceAttr {
for (auto axis_name : axis_names_) {
auto dim_idx = shape_layout.find(axis_name);
DALI_ENFORCE(dim_idx >= 0,
make_string("Requested to slice dimension", axis_name,
"which is not present in the shape layout", shape_layout.c_str()));
make_string("Requested to slice dimension ", axis_name,
" which is not present in the shape layout ", shape_layout));
axes.push_back(dim_idx);
}
}
Expand All @@ -117,7 +117,7 @@ class SliceAttr {
shape_val *= shape[dim];
int64_t slice_end = static_cast<int64_t>(anchor_val + shape_val);
DALI_ENFORCE(slice_end <= shape[dim],
make_string("Slice end for dim", dim, "is out of bounds:",
make_string("Slice end for dim ", dim, " is out of bounds:",
slice_end, ">", shape[dim]));
slice.anchor[dim] = static_cast<int64_t>(anchor_val);
slice.shape[dim] = slice_end - slice.anchor[dim];
Expand All @@ -134,7 +134,7 @@ class SliceAttr {
size_t args_size = volume(crop_anchor_shape);
auto axes_size = !axis_names_.empty() ? axis_names_.size() : axes_.size();
DALI_ENFORCE(args_size == axes_size,
make_string("Unexpected number of arguments", args_size, "vs", axes_size));
make_string("Unexpected number of arguments ", args_size, " vs ", axes_size));
}

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ImageDecoderCropTest_CPU : public DecodeTestBase<ImgType> {
return [this](const TensorShape<>& shape,
const TensorLayout& shape_layout) {
DALI_ENFORCE(shape_layout == "HW",
make_string("Unexpected input shape layout:", shape_layout.c_str(), "vs HW"));
make_string("Unexpected input shape layout: ", shape_layout, " vs HW"));
CropWindow crop_window;
crop_window.shape[0] = crop_H;
crop_window.shape[1] = crop_W;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ImageDecoderSliceTest_CPU : public DecodeTestBase<ImgType> {
return [this] (const TensorShape<>& shape,
const TensorLayout& shape_layout) {
DALI_ENFORCE(shape_layout == "HW",
make_string("Unexpected input shape layout:", shape_layout.c_str(), "vs HW"));
make_string("Unexpected input shape layout: ", shape_layout, " vs HW"));
CropWindow crop_window;
crop_window.anchor[0] = crop_y * shape[0];
crop_window.anchor[1] = crop_x * shape[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ImageDecoderCropTest_GPU : public DecodeTestBase<ImgType> {
return [this] (const TensorShape<>& shape,
const TensorLayout& shape_layout) {
DALI_ENFORCE(shape_layout == "HW",
make_string("Unexpected input shape layout:", shape_layout.c_str(), "vs HW"));
make_string("Unexpected input shape layout: ", shape_layout, " vs HW"));
CropWindow crop_window;
crop_window.shape[0] = crop_H;
crop_window.shape[1] = crop_W;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ImageDecoderSliceTest_GPU : public DecodeTestBase<ImgType> {
return [this] (const TensorShape<>& shape,
const TensorLayout& shape_layout) {
DALI_ENFORCE(shape_layout == "HW",
make_string("Unexpected input shape layout:", shape_layout.c_str(), "vs HW"));
make_string("Unexpected input shape layout: ", shape_layout, " vs HW"));
CropWindow crop_window;
crop_window.anchor[0] = crop_y * shape[0];
crop_window.anchor[1] = crop_x * shape[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ImageDecoderSplitCropTest_GPU : public DecodeTestBase<ImgType> {
return [this] (const TensorShape<>& shape,
const TensorLayout& shape_layout) {
DALI_ENFORCE(shape_layout == "HW",
make_string("Unexpected input shape layout:", shape_layout.c_str(), "vs HW"));
make_string("Unexpected input shape layout: ", shape_layout, " vs HW"));
CropWindow crop_window;
crop_window.shape[0] = crop_H;
crop_window.shape[1] = crop_W;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ImageDecoderSplitSliceTest_GPU : public DecodeTestBase<ImgType> {
return [this] (const TensorShape<>& shape,
const TensorLayout& shape_layout) {
DALI_ENFORCE(shape_layout == "HW",
make_string("Unexpected input shape layout:", shape_layout.c_str(), "vs HW"));
make_string("Unexpected input shape layout: ", shape_layout, " vs HW"));
CropWindow crop_window;
crop_window.anchor[0] = crop_y * shape[0];
crop_window.anchor[1] = crop_x * shape[1];
Expand Down
5 changes: 3 additions & 2 deletions dali/operators/displacement/rotate_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ inline TensorShape<2> RotatedCanvasSize(TensorShape<2> input_size, double angle)
int w_out = std::ceil(abs_cos * w + abs_sin * h - eps);
int h_out = std::ceil(abs_cos * h + abs_sin * w - eps);
if (abs_sin <= abs_cos) {
// if rotated by less than 45deg, maintain size parity to reduce blur
// if rotated by less than +/-45deg (or more than +/-135deg),
// maintain size parity to reduce blur
if (w_out % 2 != w % 2)
w_out++;
if (h_out % 2 != h % 2)
h_out++;
} else {
// if rotated by more than 45deg, swap size parity to reduce blur
// if rotated by +/-(45..135deg), swap size parity to reduce blur
if (h_out % 2 != w % 2)
h_out++;
if (w_out % 2 != h % 2)
Expand Down
12 changes: 6 additions & 6 deletions dali/operators/expressions/arithmetic.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ DLL_PUBLIC TensorLayout GetCommonLayout(ExprNode &expr, const workspace_t<Backen
}
DALI_ENFORCE(
result_layout == next_layout,
make_string("Layouts of subexpressions", i - 1, "and", i, "for atihmetic operation",
func.GetFuncName(), "do not match. Expected", result_layout.c_str(), "got",
next_layout.c_str(), "."));
make_string("Layouts of subexpressions ", i - 1, " and ", i, " for atihmetic operation",
func.GetFuncName(), " do not match. Expected ", result_layout, " got ",
next_layout, "."));
}
return result_layout;
}
Expand Down Expand Up @@ -161,9 +161,9 @@ inline TensorListShape<> ShapePromotion(std::string op, span<const TensorListSha
out_shape = shapes[i];
} else {
DALI_ENFORCE(*out_shape == *shapes[i],
make_string_delim("", "Input shapes of elemenetwise arithemtic operator \"", op,
"\" do not match. Expected equal shapes, got: ", op, "(",
*out_shape, ", ", *shapes[i], ")."));
make_string("Input shapes of elemenetwise arithemtic operator \"", op,
"\" do not match. Expected equal shapes, got: ", op, "(",
*out_shape, ", ", *shapes[i], ")."));
}
}
return out_shape ? *out_shape : TensorListShape<>{{1}};
Expand Down
22 changes: 11 additions & 11 deletions dali/operators/expressions/expression_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ ParseResult ParseExpr(const std::string &expr, int pos);

std::string ReportCharacter(char c) {
if (!std::isprint(c)) {
return make_string_delim("", "\"<non-printable>\", character code: 0x", std::hex,
static_cast<int>(c), std::dec);
return make_string("\"<non-printable>\", character code: 0x", std::hex,
static_cast<int>(c), std::dec);
}
return make_string_delim("", "\"", c, "\", character code: 0x", std::hex, static_cast<int>(c),
std::dec);
return make_string("\"", c, "\", character code: 0x", std::hex, static_cast<int>(c),
std::dec);
}

void EnforceNonEnd(const std::string &expr, int pos, const std::string &expected = "") {
DALI_ENFORCE(pos < static_cast<int>(expr.length()),
make_string_delim("", "Unexpected end of expression description, expected: ",
expected, " at position [", pos, "] in: ", expr));
make_string("Unexpected end of expression description, expected: ",
expected, " at position [", pos, "] in: ", expr));
}

int ExpectChar(const std::string &expr, int pos, char c) {
Expand All @@ -72,8 +72,8 @@ int ExpectChar(const std::string &expr, int pos, char c) {
return pos + 1;
}

DALI_FAIL(make_string_delim(
"", "Unrecognized token for expression description: ", ReportCharacter(expr[pos]),
DALI_FAIL(make_string(
"Unrecognized token for expression description: ", ReportCharacter(expr[pos]),
" at position [", pos, "], expected ", ReportCharacter(c), " in: ", expr));
}

Expand Down Expand Up @@ -106,16 +106,16 @@ std::tuple<int, int> ParseInt(const std::string &expr, int pos) {
int parsed = atoi(&expr[pos]);
int new_pos = SkipInt(expr, pos);
DALI_ENFORCE(pos != new_pos,
make_string_delim("", "Expected integer value at position [", pos, "] in: ", expr));
make_string("Expected integer value at position [", pos, "] in: ", expr));
return std::make_tuple(parsed, new_pos);
}

std::tuple<std::string, int> ParseName(const std::string &expr, int pos) {
EnforceNonEnd(expr, pos, "function name or input description starting with \"&\" or \"$\"");
DALI_ENFORCE(
std::isalpha(expr[pos]),
make_string_delim(
"", "Unrecognized token for expression description: ", ReportCharacter(expr[pos]),
make_string(
"Unrecognized token for expression description: ", ReportCharacter(expr[pos]),
" at position [", pos, "] in: \"", expr,
"\". Expected function name starting with alphabetic character or input description "
"starting with \"&\" or \"$\"."));
Expand Down
2 changes: 1 addition & 1 deletion dali/pipeline/operator/op_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class DLL_PUBLIC OpSchema {
if (l == layout)
return l;
std::stringstream ss;
ss << "The layout \"" << layout.c_str() << "\" does not match any of the allowed"
ss << "The layout \"" << layout << "\" does not match any of the allowed"
" layouts for input " << index << ". Valid layouts are:\n";
for (auto &l : input_layouts_[index])
ss << l.c_str() << "\n";
Expand Down
4 changes: 2 additions & 2 deletions dali/pipeline/operator/operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class DLL_PUBLIC OperatorBase {

DALI_ENFORCE(is_valid_shape,
make_string("`", argument_name, "` must be a 1xN or Nx1 (N = ", batch_size_,
") tensor list. Got: ", shape));
") tensor list. Got: ", shape));

output.resize(batch_size_);
auto *data = arg[0].template data<T>();
Expand All @@ -196,7 +196,7 @@ class DLL_PUBLIC OperatorBase {
shape.tensor_shape(0) == TensorShape<1>{1};
DALI_ENFORCE(is_valid_shape,
make_string("`", argument_name, "` must be a 1xN or Nx1 (N = ", batch_size_,
") tensor list. Got: ", shape));
") tensor list. Got: ", shape));

output.resize(batch_size_);
for (int i = 0; i < batch_size_; i++) {
Expand Down
8 changes: 7 additions & 1 deletion dali/pipeline/workspace/workspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,20 @@ class ArgumentWorkspace {
const TensorVector<CPUBackend>& ArgumentInput(const std::string &arg_name) const {
auto it = argument_inputs_.find(arg_name);
DALI_ENFORCE(it != argument_inputs_.end(), "Argument \"" + arg_name + "\" not found.");
if (it->second.should_update)
if (it->second.should_update) {
// the underlying tensor list might have changed - update the views
it->second.tvec->UpdateViews();
}
return *it->second.tvec;
}

protected:
struct ArgumentInputDesc {
shared_ptr<TensorVector<CPUBackend>> tvec;
// If true, the views in TensorBector are updated to reflect the underlying TensorList;
// this only happens if AddArgumentInput is called with a TensorList pointer - which for now
// is only when passing an argument input to a GPU stage when using separated queue policy
// (see queue_policy.h and pipeline.cc for details).
bool should_update = false;
};

Expand Down
23 changes: 10 additions & 13 deletions dali/test/python/test_operator_rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ def ToCVMatrix(matrix):
result[1][2] = offset[1] - 0.5
return result

def CVRotate(output_type, input_type, angle, fixed_size):
angle = math.radians(angle)
def warp_fn(img):
def CVRotate(output_type, input_type, fixed_size):
def warp_fn(img, angle):
in_size = img.shape[0:2]
angle = math.radians(angle[0])
out_size = fixed_size if fixed_size is not None else get_output_size(angle, in_size)
matrix = get_transform(angle, in_size, out_size)
matrix = ToCVMatrix(matrix)
Expand All @@ -104,10 +104,8 @@ def __init__(self, device, batch_size, output_type, input_type, fixed_size=None,
else:
self.cast = None

# TODO(michalz): When we move from Support to CPU operators, replace hardcoded angle
# with one taken from the distribution below
# self.uniform = ops.Uniform(range = (-180.0, 180.0), seed = 42);
self.rotate = ops.Rotate(device = device, size=fixed_size, angle = 30, fill_value = 42, output_dtype = output_type)
self.uniform = ops.Uniform(range = (-180.0, 180.0), seed = 42);
self.rotate = ops.Rotate(device = device, size=fixed_size, fill_value = 42, output_dtype = output_type)

def define_graph(self):
self.jpegs, self.labels = self.input(name = "Reader")
Expand All @@ -117,7 +115,7 @@ def define_graph(self):
if self.cast:
images = self.cast(images)

outputs = self.rotate(images)
outputs = self.rotate(images, angle = self.uniform())
return outputs

class CVPipeline(Pipeline):
Expand All @@ -126,16 +124,15 @@ def __init__(self, batch_size, output_type, input_type, fixed_size, num_threads=
self.name = "cv"
self.input = ops.CaffeReader(path = caffe_db_folder, shard_id = device_id, num_shards = num_gpus)
self.decode = ops.ImageDecoder(device = "cpu", output_type = types.RGB)
self.rotate = ops.PythonFunction(function=CVRotate(output_type, input_type, 30, fixed_size))
# TODO(michalz): When we move from Support to CPU operators, replace hardcoded angle
# with one taken from the distribution below
# self.uniform = ops.Uniform(range = (-180.0, 180.0), seed = 42);
self.rotate = ops.PythonFunction(function=CVRotate(output_type, input_type, fixed_size))
self.uniform = ops.Uniform(range = (-180.0, 180.0), seed = 42);
self.iter = 0

def define_graph(self):
self.jpegs, self.labels = self.input(name = "Reader")
images = self.decode(self.jpegs)
outputs = self.rotate(images);
angles = self.uniform()
outputs = self.rotate(images, angles);
return outputs


Expand Down
Loading