|
|
@ -30,25 +30,30 @@ namespace transforms {
|
|
|
|
// (In alphabetical order)
|
|
|
|
// (In alphabetical order)
|
|
|
|
|
|
|
|
|
|
|
|
// Constructor to Compose.
|
|
|
|
// Constructor to Compose.
|
|
|
|
Compose::Compose(const std::vector<TensorTransform *> &transforms) {
|
|
|
|
struct Compose::Data {
|
|
|
|
|
|
|
|
std::vector<std::shared_ptr<TensorOperation>> transforms_;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Compose::Compose(const std::vector<TensorTransform *> &transforms) : data_(std::make_shared<Data>()) {
|
|
|
|
(void)std::transform(
|
|
|
|
(void)std::transform(
|
|
|
|
transforms.begin(), transforms.end(), std::back_inserter(transforms_),
|
|
|
|
transforms.begin(), transforms.end(), std::back_inserter(data_->transforms_),
|
|
|
|
[](TensorTransform *op) -> std::shared_ptr<TensorOperation> { return op != nullptr ? op->Parse() : nullptr; });
|
|
|
|
[](TensorTransform *op) -> std::shared_ptr<TensorOperation> { return op != nullptr ? op->Parse() : nullptr; });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Compose::Compose(const std::vector<std::shared_ptr<TensorTransform>> &transforms) {
|
|
|
|
Compose::Compose(const std::vector<std::shared_ptr<TensorTransform>> &transforms) : data_(std::make_shared<Data>()) {
|
|
|
|
(void)std::transform(transforms.begin(), transforms.end(), std::back_inserter(transforms_),
|
|
|
|
(void)std::transform(transforms.begin(), transforms.end(), std::back_inserter(data_->transforms_),
|
|
|
|
[](std::shared_ptr<TensorTransform> op) -> std::shared_ptr<TensorOperation> {
|
|
|
|
[](std::shared_ptr<TensorTransform> op) -> std::shared_ptr<TensorOperation> {
|
|
|
|
return op != nullptr ? op->Parse() : nullptr;
|
|
|
|
return op != nullptr ? op->Parse() : nullptr;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Compose::Compose(const std::vector<std::reference_wrapper<TensorTransform>> &transforms) {
|
|
|
|
Compose::Compose(const std::vector<std::reference_wrapper<TensorTransform>> &transforms)
|
|
|
|
(void)std::transform(transforms.begin(), transforms.end(), std::back_inserter(transforms_),
|
|
|
|
: data_(std::make_shared<Data>()) {
|
|
|
|
|
|
|
|
(void)std::transform(transforms.begin(), transforms.end(), std::back_inserter(data_->transforms_),
|
|
|
|
[](TensorTransform &op) -> std::shared_ptr<TensorOperation> { return op.Parse(); });
|
|
|
|
[](TensorTransform &op) -> std::shared_ptr<TensorOperation> { return op.Parse(); });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<TensorOperation> Compose::Parse() { return std::make_shared<ComposeOperation>(transforms_); }
|
|
|
|
std::shared_ptr<TensorOperation> Compose::Parse() { return std::make_shared<ComposeOperation>(data_->transforms_); }
|
|
|
|
|
|
|
|
|
|
|
|
// Constructor to Duplicate
|
|
|
|
// Constructor to Duplicate
|
|
|
|
Duplicate::Duplicate() {}
|
|
|
|
Duplicate::Duplicate() {}
|
|
|
@ -56,59 +61,87 @@ Duplicate::Duplicate() {}
|
|
|
|
std::shared_ptr<TensorOperation> Duplicate::Parse() { return std::make_shared<DuplicateOperation>(); }
|
|
|
|
std::shared_ptr<TensorOperation> Duplicate::Parse() { return std::make_shared<DuplicateOperation>(); }
|
|
|
|
|
|
|
|
|
|
|
|
// Constructor to OneHot
|
|
|
|
// Constructor to OneHot
|
|
|
|
OneHot::OneHot(int32_t num_classes) : num_classes_(num_classes) {}
|
|
|
|
struct OneHot::Data {
|
|
|
|
|
|
|
|
explicit Data(int32_t num_classes) : num_classes_(num_classes) {}
|
|
|
|
|
|
|
|
float num_classes_;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OneHot::OneHot(int32_t num_classes) : data_(std::make_shared<Data>(num_classes)) {}
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<TensorOperation> OneHot::Parse() { return std::make_shared<OneHotOperation>(num_classes_); }
|
|
|
|
std::shared_ptr<TensorOperation> OneHot::Parse() { return std::make_shared<OneHotOperation>(data_->num_classes_); }
|
|
|
|
|
|
|
|
|
|
|
|
// Constructor to RandomApply.
|
|
|
|
// Constructor to RandomApply.
|
|
|
|
RandomApply::RandomApply(const std::vector<TensorTransform *> &transforms, double prob) : prob_(prob) {
|
|
|
|
struct RandomApply::Data {
|
|
|
|
|
|
|
|
std::vector<std::shared_ptr<TensorOperation>> transforms_;
|
|
|
|
|
|
|
|
double prob_;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RandomApply::RandomApply(const std::vector<TensorTransform *> &transforms, double prob)
|
|
|
|
|
|
|
|
: data_(std::make_shared<Data>()) {
|
|
|
|
(void)std::transform(
|
|
|
|
(void)std::transform(
|
|
|
|
transforms.begin(), transforms.end(), std::back_inserter(transforms_),
|
|
|
|
transforms.begin(), transforms.end(), std::back_inserter(data_->transforms_),
|
|
|
|
[](TensorTransform *op) -> std::shared_ptr<TensorOperation> { return op != nullptr ? op->Parse() : nullptr; });
|
|
|
|
[](TensorTransform *op) -> std::shared_ptr<TensorOperation> { return op != nullptr ? op->Parse() : nullptr; });
|
|
|
|
|
|
|
|
data_->prob_ = prob;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RandomApply::RandomApply(const std::vector<std::shared_ptr<TensorTransform>> &transforms, double prob) : prob_(prob) {
|
|
|
|
RandomApply::RandomApply(const std::vector<std::shared_ptr<TensorTransform>> &transforms, double prob)
|
|
|
|
(void)std::transform(transforms.begin(), transforms.end(), std::back_inserter(transforms_),
|
|
|
|
: data_(std::make_shared<Data>()) {
|
|
|
|
|
|
|
|
(void)std::transform(transforms.begin(), transforms.end(), std::back_inserter(data_->transforms_),
|
|
|
|
[](std::shared_ptr<TensorTransform> op) -> std::shared_ptr<TensorOperation> {
|
|
|
|
[](std::shared_ptr<TensorTransform> op) -> std::shared_ptr<TensorOperation> {
|
|
|
|
return op != nullptr ? op->Parse() : nullptr;
|
|
|
|
return op != nullptr ? op->Parse() : nullptr;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
data_->prob_ = prob;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RandomApply::RandomApply(const std::vector<std::reference_wrapper<TensorTransform>> &transforms, double prob)
|
|
|
|
RandomApply::RandomApply(const std::vector<std::reference_wrapper<TensorTransform>> &transforms, double prob)
|
|
|
|
: prob_(prob) {
|
|
|
|
: data_(std::make_shared<Data>()) {
|
|
|
|
(void)std::transform(transforms.begin(), transforms.end(), std::back_inserter(transforms_),
|
|
|
|
(void)std::transform(transforms.begin(), transforms.end(), std::back_inserter(data_->transforms_),
|
|
|
|
[](TensorTransform &op) -> std::shared_ptr<TensorOperation> { return op.Parse(); });
|
|
|
|
[](TensorTransform &op) -> std::shared_ptr<TensorOperation> { return op.Parse(); });
|
|
|
|
|
|
|
|
data_->prob_ = prob;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<TensorOperation> RandomApply::Parse() {
|
|
|
|
std::shared_ptr<TensorOperation> RandomApply::Parse() {
|
|
|
|
return std::make_shared<RandomApplyOperation>(transforms_, prob_);
|
|
|
|
return std::make_shared<RandomApplyOperation>(data_->transforms_, data_->prob_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Constructor to RandomChoice.
|
|
|
|
// Constructor to RandomChoice.
|
|
|
|
RandomChoice::RandomChoice(const std::vector<TensorTransform *> &transforms) {
|
|
|
|
struct RandomChoice::Data {
|
|
|
|
|
|
|
|
std::vector<std::shared_ptr<TensorOperation>> transforms_;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RandomChoice::RandomChoice(const std::vector<TensorTransform *> &transforms) : data_(std::make_shared<Data>()) {
|
|
|
|
(void)std::transform(
|
|
|
|
(void)std::transform(
|
|
|
|
transforms.begin(), transforms.end(), std::back_inserter(transforms_),
|
|
|
|
transforms.begin(), transforms.end(), std::back_inserter(data_->transforms_),
|
|
|
|
[](TensorTransform *op) -> std::shared_ptr<TensorOperation> { return op != nullptr ? op->Parse() : nullptr; });
|
|
|
|
[](TensorTransform *op) -> std::shared_ptr<TensorOperation> { return op != nullptr ? op->Parse() : nullptr; });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RandomChoice::RandomChoice(const std::vector<std::shared_ptr<TensorTransform>> &transforms) {
|
|
|
|
RandomChoice::RandomChoice(const std::vector<std::shared_ptr<TensorTransform>> &transforms)
|
|
|
|
(void)std::transform(transforms.begin(), transforms.end(), std::back_inserter(transforms_),
|
|
|
|
: data_(std::make_shared<Data>()) {
|
|
|
|
|
|
|
|
(void)std::transform(transforms.begin(), transforms.end(), std::back_inserter(data_->transforms_),
|
|
|
|
[](std::shared_ptr<TensorTransform> op) -> std::shared_ptr<TensorOperation> {
|
|
|
|
[](std::shared_ptr<TensorTransform> op) -> std::shared_ptr<TensorOperation> {
|
|
|
|
return op != nullptr ? op->Parse() : nullptr;
|
|
|
|
return op != nullptr ? op->Parse() : nullptr;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RandomChoice::RandomChoice(const std::vector<std::reference_wrapper<TensorTransform>> &transforms) {
|
|
|
|
RandomChoice::RandomChoice(const std::vector<std::reference_wrapper<TensorTransform>> &transforms)
|
|
|
|
(void)std::transform(transforms.begin(), transforms.end(), std::back_inserter(transforms_),
|
|
|
|
: data_(std::make_shared<Data>()) {
|
|
|
|
|
|
|
|
(void)std::transform(transforms.begin(), transforms.end(), std::back_inserter(data_->transforms_),
|
|
|
|
[](TensorTransform &op) -> std::shared_ptr<TensorOperation> { return op.Parse(); });
|
|
|
|
[](TensorTransform &op) -> std::shared_ptr<TensorOperation> { return op.Parse(); });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<TensorOperation> RandomChoice::Parse() { return std::make_shared<RandomChoiceOperation>(transforms_); }
|
|
|
|
std::shared_ptr<TensorOperation> RandomChoice::Parse() {
|
|
|
|
|
|
|
|
return std::make_shared<RandomChoiceOperation>(data_->transforms_);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Constructor to TypeCast
|
|
|
|
// Constructor to TypeCast
|
|
|
|
TypeCast::TypeCast(std::string data_type) : data_type_(data_type) {}
|
|
|
|
struct TypeCast::Data {
|
|
|
|
|
|
|
|
explicit Data(const std::vector<char> &data_type) : data_type_(CharToString(data_type)) {}
|
|
|
|
|
|
|
|
std::string data_type_;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TypeCast::TypeCast(const std::vector<char> &data_type) : data_(std::make_shared<Data>(data_type)) {}
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<TensorOperation> TypeCast::Parse() { return std::make_shared<TypeCastOperation>(data_type_); }
|
|
|
|
std::shared_ptr<TensorOperation> TypeCast::Parse() { return std::make_shared<TypeCastOperation>(data_->data_type_); }
|
|
|
|
|
|
|
|
|
|
|
|
// Constructor to Unique
|
|
|
|
// Constructor to Unique
|
|
|
|
Unique::Unique() {}
|
|
|
|
Unique::Unique() {}
|
|
|
|