Skip to content
Snippets Groups Projects
Commit 54c7dc75 authored by Michal Szczepanski's avatar Michal Szczepanski
Browse files

New version of Resieze operator, without NoRoi/NoScales/NoSizes

parent 9556387a
No related branches found
No related tags found
2 merge requests!152Update Aidge export to take a graph view has an argument instead of a...,!125Operator resize
......@@ -25,41 +25,35 @@
namespace Aidge {
enum class ResizeAttr { NoROI, NoScales, NoSizes };
// enum class ResizeAttr { };
class Resize_Op : public OperatorTensor,
public Registrable<Resize_Op, std::string, std::shared_ptr<OperatorImpl>(const Resize_Op&)>,
public StaticAttributes<ResizeAttr,
bool,
bool,
bool> {
public Registrable<Resize_Op, std::string, std::shared_ptr<OperatorImpl>(const Resize_Op&)>{
// public StaticAttributes<ResizeAttr,> {
public:
static const std::string Type;
Resize_Op() = delete;
// if attributes in arguments
// Resize_Op() = delete;
using Attributes_ = StaticAttributes<ResizeAttr,
bool,
bool,
bool>;
template <ResizeAttr e>
using attr = typename Attributes_::template attr<e>;
Resize_Op(const bool noROI, const bool noScales, const bool noSizes)
: OperatorTensor(Type, 1, 3, 1),
// input tensor, onnx optional input [roi/scales/sizes] *constant, output
Attributes_(attr<ResizeAttr::NoROI>(noROI),
attr<ResizeAttr::NoScales>(noScales),
attr<ResizeAttr::NoSizes>(noSizes)) {}
// using Attributes_ = StaticAttributes<ResizeAttr,>;
// template <ResizeAttr e> using attr = typename Attributes_::template attr<e>;
Resize_Op()
: OperatorTensor(Type, 4, 0, 1){}
// input tensor, onnx optional input [roi/scales/sizes] *constant, output
// Attributes_() {}
/**
* @brief Copy-constructor. Copy the operator attributes and its output tensor(s),
* but not its input tensors (the new operator has no input associated).
* @param op Operator to copy.
*/
Resize_Op(const Resize_Op& op)
: OperatorTensor(op),
Attributes_(op)
: OperatorTensor(op)
// Attributes_(op)
{
// copy an operator
if (!op.backend().empty()) {
......@@ -92,31 +86,22 @@ public:
}
};
inline std::shared_ptr<Node> Resize(const std::size_t nbInputDims,
const bool noROI,
const bool noScales,
const bool noSizes,
const std::string &name = "") {
inline std::shared_ptr<Node> Resize(const std::string &name = "") {
auto resize_node = std::make_shared<Node>(std::make_shared<Resize_Op>(noROI, noScales, noSizes), name);
return std::make_shared<Node>(std::make_shared<Resize_Op>(), name);
// create empty producers of the same as the rank of input size [nbInputDims]
addProducer(resize_node, 1, std::array<DimSize_t, 1>({noROI ? 0 : nbInputDims}), "roi"); // already sets roi dims
addProducer(resize_node, 2, std::array<DimSize_t, 1>({noScales ? 0 : nbInputDims}), "scales"); // already sets scales dims
addProducer(resize_node, 3, std::array<DimSize_t, 1>({noSizes ? 0 : nbInputDims}), "sizes"); // already sets sizes dims
return resize_node;
// addProducer(resize_node, 1, std::array<DimSize_t, 1>({noROI ? 0 : nbInputDims}), "roi"); // already sets roi dims
// addProducer(resize_node, 2, std::array<DimSize_t, 1>({noScales ? 0 : nbInputDims}), "scales"); // already sets scales dims
// addProducer(resize_node, 3, std::array<DimSize_t, 1>({noSizes ? 0 : nbInputDims}), "sizes"); // already sets sizes dims
// return resize_node;
}
} // namespace Aidge
namespace {
template <>
const char *const EnumStrings<Aidge::ResizeAttr>::data[] = {
"noROI",
"noScales",
"noSizes"
};
}
// namespace {
// template <>
// const char *const EnumStrings<Aidge::ResizeAttr>::data[] = {};
// }
#endif /* AIDGE_CORE_OPERATOR_Resize_H_ */
......@@ -27,8 +27,10 @@ const std::string Aidge::Resize_Op::Type = "Resize";
bool Aidge::Resize_Op::dimsForwarded() const {
// in case of ROI add getInput(1) condition
if ((getInput(2) && !getInput(2)->empty())
|| (getInput(3) && !getInput(3)->empty()))
if ((getInput(1) && !getInput(1)->empty())
|| (getInput(2) && !getInput(2)->empty())
|| (getInput(3) && !getInput(3)->empty())
)
{
// output dims are data dependent
return false;
......@@ -39,23 +41,42 @@ bool Aidge::Resize_Op::dimsForwarded() const {
bool Aidge::Resize_Op::forwardDims(bool allowDataDependency) {
fmt::print("forward dims\n");
// check inputs have been associated
if (!getInput(0)) {
AIDGE_THROW_OR_ABORT(std::runtime_error, "{}: input #0 should be associated with a Tensor", type());
}
AIDGE_ASSERT(getInput(0)->nbDims() == 4,\
"input tensor must have dimensions = 4 (batch, channel, height, width).");
"input tensor must have dimensions = 4 (batch, channel, height, width).");
for (size_t i = 0; i < 4; ++i) {
// check inputs ("data_input","roi", "scales", "data_input","sizes") has been associated
if (!getInput(i)) {
AIDGE_THROW_OR_ABORT(std::runtime_error, "{}: input #{} not provided", type(), i);
}
if (getInput(0)->empty()) {
return false;
}
if (this->template getAttr<ResizeAttr::NoROI>() && this->template getAttr<ResizeAttr::NoSizes>()) {
if (getInput(1) && !getInput(1)->empty()) {
AIDGE_THROW_OR_ABORT(std::runtime_error, "ROI input is not supported");
return false;
}
// for (size_t i = 0; i < 4; ++i) {
// // check inputs ("data_input","roi", "scales", "data_input","sizes") has been associated
// if (!getInput(i)) {
// AIDGE_THROW_OR_ABORT(std::runtime_error, "{}: input #{} not provided", type(), i);
// }
// }
if (getInput(2) && !getInput(2)->empty()) {
fmt::print("kernel 1\n");
/*
fmt::print("Condition scales: Input#0 and Input#2 must be provided and must have the same dimension,\
while Inputs#1 and #3 must not be provided.\n");
*/
if (!allowDataDependency) {
Log::warn("Resize_Op: unable to forwardDims() because output dims are data dependent\
on input#0 and input#2");
......@@ -75,10 +96,13 @@ bool Aidge::Resize_Op::forwardDims(bool allowDataDependency) {
outDims[dim] = inDims[dim]*static_cast<int64_t*>(scales.getImpl()->hostPtr())[dim];
}
mOutputs[0]->resize(outDims);
fmt::print("kernel 1 {}\n",outDims);
return true;
}
if (this->template getAttr<ResizeAttr::NoROI>() && this->template getAttr<ResizeAttr::NoScales>()) {
if (getInput(3) && !getInput(3)->empty()) {
fmt::print("kernel 2 \n");
/*
fmt::print("Condition sizes: Input#0 and Input#3 must be provided and must have the same dimension,\
......@@ -103,7 +127,8 @@ bool Aidge::Resize_Op::forwardDims(bool allowDataDependency) {
outDims[dim] = static_cast<int64_t*>(sizes.getImpl()->hostPtr())[dim];
}
mOutputs[0]->resize(outDims);
fmt::print("kernel 2 {}\n",outDims);
return true;
}
......@@ -115,7 +140,13 @@ void Aidge::Resize_Op::setBackend(const std::string& name, Aidge::DeviceIdx_t de
mOutputs[0]->setBackend(name, device);
// By default, automatically set backend for all inputs: roi, scales and sizes
getInput(1)->setBackend(name, device);
getInput(2)->setBackend(name, device);
getInput(3)->setBackend(name, device);
if(getInput(1)) {
getInput(1)->setBackend(name, device);
}
if(getInput(2)) {
getInput(2)->setBackend(name, device);
}
if(getInput(3)) {
getInput(3)->setBackend(name, device);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment