[TF FE] Support HSVToRGB operation for TensorFlow (#24875)

### Details:
- Using #24033, implemented and registered loader for HSVToRGB using
already existing logic.
 - Created unit test test_tf_HSVToRGB.py

### Tickets:
 - #24791 
 
Currently, my pytest is saying that for the unit test and for
test_tf_AdjustHue.py and test_tf_AdjustSaturation.py the loader is not
found.

---------

Co-authored-by: Roman Kazantsev <roman.kazantsev@intel.com>
This commit is contained in:
Jorge Ragde 2024-06-10 00:56:08 -07:00 committed by GitHub
parent 79fc6bf79b
commit 8646aff9e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 114 additions and 5 deletions

View File

@ -487,7 +487,7 @@ A "supported operation" is one that TensorFlow Frontend can convert to the OpenV
| GroupByReducerDataset | NO | |
| GroupByWindowDataset | NO | |
| GuaranteeConst | NO | |
| HSVToRGB | NO | |
| HSVToRGB | YES | |
| HashTable | YES | |
| HashTableV2 | YES | |
| HistogramFixedWidth | NO | |

View File

@ -271,6 +271,7 @@ const std::map<std::string, CreatorFunction> get_supported_ops() {
{"Addons>GatherTree", CreatorFunction(translate_gather_tree_op)},
{"HashTable", CreatorFunction(translate_hash_table_op)},
{"HashTableV2", CreatorFunction(translate_hash_table_op)},
{"HSVToRGB", CreatorFunction(translate_hsv_to_rgb_op)},
{"Identity", CreatorFunction(translate_identity_op)},
{"IdentityN", CreatorFunction(translate_identity_n_op)},
{"Inv", CreatorFunction(translate_inv_op)},

View File

@ -87,6 +87,7 @@ OP_CONVERTER(translate_gather_v2_op);
OP_CONVERTER(translate_gather_nd_op);
OP_CONVERTER(translate_gather_tree_op);
OP_CONVERTER(translate_gelu_op);
OP_CONVERTER(translate_hsv_to_rgb_op);
OP_CONVERTER(translate_identity_op);
OP_CONVERTER(translate_identity_n_op);
OP_CONVERTER(translate_ifft_op);

View File

@ -158,9 +158,9 @@ ov::Output<ov::Node> compute_broadcast_args(const ov::Output<ov::Node>& shape1,
std::shared_ptr<std::tuple<std::shared_ptr<ov::Node>, std::shared_ptr<ov::Node>, std::shared_ptr<ov::Node>>> rgb_to_hsv(
const std::shared_ptr<ov::Node>& images);
std::shared_ptr<ov::Node> hsv_to_rgb(const std::shared_ptr<ov::Node>& h,
const std::shared_ptr<ov::Node>& s,
const std::shared_ptr<ov::Node>& v);
std::shared_ptr<ov::Node> hsv_to_rgb(const ov::Output<ov::Node>& h,
const ov::Output<ov::Node>& s,
const ov::Output<ov::Node>& v);
} // namespace tensorflow
} // namespace frontend

View File

@ -0,0 +1,40 @@
// Copyright (C) 2018-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "common_op_table.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/split.hpp"
#include "utils.hpp"
using namespace std;
using namespace ov;
using namespace ov::op;
namespace ov {
namespace frontend {
namespace tensorflow {
namespace op {
OutputVector translate_hsv_to_rgb_op(const NodeContext& node) {
default_op_checks(node, 1, {"HSVToRGB"});
auto images = node.get_input(0);
auto node_name = node.get_name();
auto const_minus_one_i = make_shared<v0::Constant>(element::i32, Shape{}, -1);
auto channels = make_shared<v1::Split>(images, const_minus_one_i, 3);
auto hh = channels->output(0);
auto ss = channels->output(1);
auto vv = channels->output(2);
auto new_images = hsv_to_rgb(hh, ss, vv);
set_node_name(node_name, new_images);
return {new_images};
}
} // namespace op
} // namespace tensorflow
} // namespace frontend
} // namespace ov

View File

@ -499,7 +499,9 @@ shared_ptr<tuple<shared_ptr<Node>, shared_ptr<Node>, shared_ptr<Node>>> rgb_to_h
return make_shared<tuple<shared_ptr<Node>, shared_ptr<Node>, shared_ptr<Node>>>(hh_final, ss, vv);
}
shared_ptr<Node> hsv_to_rgb(const shared_ptr<Node>& h, const shared_ptr<Node>& s, const shared_ptr<Node>& v) {
shared_ptr<Node> hsv_to_rgb(const ov::Output<ov::Node>& h,
const ov::Output<ov::Node>& s,
const ov::Output<ov::Node>& v) {
// image format conversion based on
// https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/kernels/image/adjust_saturation_op.cc
auto const_six_f_ = create_same_type_const_scalar<float>(h, 6.0f);

View File

@ -0,0 +1,65 @@
# Copyright (C) 2018-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import platform
import numpy as np
import pytest
import tensorflow as tf
from common.tf_layer_test_class import CommonTFLayerTest
class TestHSVToRGB(CommonTFLayerTest):
def _prepare_input(self, inputs_info):
assert 'images:0' in inputs_info
if self.special_case == "Black Image":
images_shape = inputs_info['images:0']
inputs_data = {}
inputs_data['images:0'] = np.zeros(images_shape).astype(self.input_type)
elif self.special_case == "Grayscale Image":
images_shape = inputs_info['images:0']
inputs_data = {}
inputs_data['images:0'] = np.ones(images_shape).astype(self.input_type) * np.random.rand()
else:
images_shape = inputs_info['images:0']
inputs_data = {}
inputs_data['images:0'] = np.random.rand(*images_shape).astype(self.input_type)
return inputs_data
def create_hsv_to_rgb_net(self, input_shape, input_type, special_case=False):
self.special_case = special_case
self.input_type = input_type
tf.compat.v1.reset_default_graph()
# Create the graph and model
with tf.compat.v1.Session() as sess:
images = tf.compat.v1.placeholder(input_type, input_shape, 'images')
tf.raw_ops.HSVToRGB(images=images)
tf.compat.v1.global_variables_initializer()
tf_net = sess.graph_def
return tf_net, None
# Each input is a tensor of with values in [0,1].
# The last dimension must be size 3.
test_data_basic = [
dict(input_shape=[7, 7, 3], input_type=np.float32, special_case="Black Image"),
dict(input_shape=[7, 7, 3], input_type=np.float32, special_case="Grayscale Image"),
dict(input_shape=[5, 5, 3], input_type=np.float32),
dict(input_shape=[5, 23, 27, 3], input_type=np.float64),
dict(input_shape=[3, 4, 13, 15, 3], input_type=np.float64),
]
@pytest.mark.parametrize("params", test_data_basic)
@pytest.mark.precommit
@pytest.mark.nightly
@pytest.mark.xfail(condition=platform.system() in ('Darwin', 'Linux') and platform.machine() in ['arm', 'armv7l',
'aarch64',
'arm64', 'ARM64'],
reason='Ticket - 126314, 132699')
def test_hsv_to_rgb_basic(self, params, ie_device, precision, ir_version, temp_dir,
use_legacy_frontend):
if ie_device == 'GPU':
pytest.skip("Accuracy mismatch on GPU")
self._test(*self.create_hsv_to_rgb_net(**params),
ie_device, precision, ir_version, temp_dir=temp_dir,
use_legacy_frontend=use_legacy_frontend)