From 9e8ee746ea494c49be5fc40f34ee8404de8cb1ee Mon Sep 17 00:00:00 2001 From: AnastasiaTuchina Date: Fri, 14 Jul 2023 20:23:33 +0200 Subject: [PATCH 1/4] KI-40 [core] Add Size operator --- .../operators/KIOperatorFactory.kt | 1 + .../kinference.core/operators/tensor/Size.kt | 57 ++++++++++++++++++ .../operators/operations/SizeTest.kt | 19 ++++++ .../resources/size/test_size/descriptor.txt | 2 + .../resources/size/test_size/model.onnx | Bin 0 -> 85 bytes .../size/test_size/test_data_set_0/input_0.pb | 1 + .../test_size/test_data_set_0/output_0.pb | Bin 0 -> 16 bytes .../size/test_size_example/descriptor.txt | 2 + .../size/test_size_example/model.onnx | Bin 0 -> 89 bytes .../test_data_set_0/input_0.pb | Bin 0 -> 44 bytes .../test_data_set_0/output_0.pb | Bin 0 -> 16 bytes 11 files changed, 82 insertions(+) create mode 100644 inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/tensor/Size.kt create mode 100644 inference/inference-core/src/commonTest/kotlin/io/kinference/operators/operations/SizeTest.kt create mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size/descriptor.txt create mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size/model.onnx create mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size/test_data_set_0/input_0.pb create mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size/test_data_set_0/output_0.pb create mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size_example/descriptor.txt create mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size_example/model.onnx create mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size_example/test_data_set_0/input_0.pb create mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size_example/test_data_set_0/output_0.pb diff --git a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/KIOperatorFactory.kt b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/KIOperatorFactory.kt index 534b24bda..7faa59fef 100755 --- a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/KIOperatorFactory.kt +++ b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/KIOperatorFactory.kt @@ -126,6 +126,7 @@ object KIOperatorFactory : OperatorFactory> { "ScatterND" -> ScatterND(name, version, attributes, inputs, outputs) "Shape" -> Shape(name, version, attributes, inputs, outputs) "Sigmoid" -> Sigmoid(name, version, attributes, inputs, outputs) + "Size" -> Size(name, version, attributes, inputs, outputs) "SkipLayerNormalization" -> SkipLayerNormalization(name, version, attributes, inputs, outputs) "Slice" -> Slice(name, version, attributes, inputs, outputs) "Softmax" -> Softmax(name, version, attributes, inputs, outputs) diff --git a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/tensor/Size.kt b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/tensor/Size.kt new file mode 100644 index 000000000..316be4c02 --- /dev/null +++ b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/tensor/Size.kt @@ -0,0 +1,57 @@ +package io.kinference.core.operators.tensor + +import io.kinference.attribute.Attribute +import io.kinference.core.data.tensor.KITensor +import io.kinference.core.data.tensor.asTensor +import io.kinference.data.ONNXData +import io.kinference.graph.Contexts +import io.kinference.ndarray.arrays.* +import io.kinference.operator.* + +sealed class Size( + name: String, + info: OperatorInfo, + attributes: Map>, + inputs: List, + outputs: List +) : Operator(name, info, attributes, inputs, outputs) { + companion object { + private val DEFAULT_VERSION = VersionInfo(sinceVersion = 1) + + operator fun invoke(name: String, version: Int?, attributes: Map>, inputs: List, outputs: List): Size { + return when (version ?: DEFAULT_VERSION.sinceVersion) { + in SizeVer1.VERSION.asRange() -> SizeVer1(name, attributes, inputs, outputs) + else -> error("Unsupported version of Size operator: $version") + } + } + } +} + + +class SizeVer1( + name: String, + attributes: Map>, + inputs: List, + outputs: List +) : Size(name, INFO, attributes, inputs, outputs) { + companion object { + private val ATTRIBUTES_INFO = emptyList() + + private val INPUTS_INFO = listOf( + IOInfo(0, PRIMITIVE_DATA_TYPES, "data", differentiable = true, optional = false) + ) + + private val OUTPUTS_INFO = listOf( + IOInfo(0, PRIMITIVE_DATA_TYPES, "size", differentiable = true, optional = false) + ) + + internal val VERSION = VersionInfo(sinceVersion = 1) + private val INFO = OperatorInfo("Size", ATTRIBUTES_INFO, INPUTS_INFO, OUTPUTS_INFO, VERSION, OperatorInfo.DEFAULT_DOMAIN) + } + + override suspend fun > apply(contexts: Contexts, inputs: List): List { + val inputSize = inputs[0]!!.data.linearSize + val dataSize = LongNDArray.scalar(inputSize.toLong()) + return listOf(dataSize.asTensor("size")) + } +} diff --git a/inference/inference-core/src/commonTest/kotlin/io/kinference/operators/operations/SizeTest.kt b/inference/inference-core/src/commonTest/kotlin/io/kinference/operators/operations/SizeTest.kt new file mode 100644 index 000000000..a6efe7f8f --- /dev/null +++ b/inference/inference-core/src/commonTest/kotlin/io/kinference/operators/operations/SizeTest.kt @@ -0,0 +1,19 @@ +package io.kinference.operators.operations + +import io.kinference.KITestEngine +import io.kinference.utils.TestRunner +import kotlin.test.Test + +class SizeTest { + private fun getTargetPath(dirName: String) = "size/$dirName/" + + @Test + fun test_size() = TestRunner.runTest { + KITestEngine.KIAccuracyRunner.runFromResources(getTargetPath("test_size")) + } + + @Test + fun test_acos_example() = TestRunner.runTest { + KITestEngine.KIAccuracyRunner.runFromResources(getTargetPath("test_size_example")) + } +} diff --git a/utils/utils-testing/src/commonMain/resources/size/test_size/descriptor.txt b/utils/utils-testing/src/commonMain/resources/size/test_size/descriptor.txt new file mode 100644 index 000000000..887e1c1e4 --- /dev/null +++ b/utils/utils-testing/src/commonMain/resources/size/test_size/descriptor.txt @@ -0,0 +1,2 @@ +test_data_set_0/input_0.pb +test_data_set_0/output_0.pb diff --git a/utils/utils-testing/src/commonMain/resources/size/test_size/model.onnx b/utils/utils-testing/src/commonMain/resources/size/test_size/model.onnx new file mode 100644 index 0000000000000000000000000000000000000000..11c8ac69c3db235f7d50c78534a5b49b03e3f529 GIT binary patch literal 85 zcmd;J7UD@tOwLZtOVKS!EiSRL=i=dFtPo��z?�j@$ �?�.z��8s?b��hdӽ�9�>(�>�%�?^�B?�0�= B�>]ת>�=�?R�iJ�>�Z�/d#��S'?�K]?��=��C@�(��Hm;= �?�2�?��?��>���>�Ec������!��� >*z�?��?�Oƾmǚ��6��&õ�gڿ��?�x�FKྙ[��� G?4�ο��Y�L=e��> �����k��QN�>.:�=�ݚ>�b"�6��� diff --git a/utils/utils-testing/src/commonMain/resources/size/test_size/test_data_set_0/output_0.pb b/utils/utils-testing/src/commonMain/resources/size/test_size/test_data_set_0/output_0.pb new file mode 100644 index 0000000000000000000000000000000000000000..11cedb8738b9efc9be129d1acc5f8ab549d538f2 GIT binary patch literal 16 ScmWe&cVevc;;>? lAO(C}JRFQd99&EsOhC+>#LdN6Da6Lb!oe=Y;KU@r2>|tZ5|sb| literal 0 HcmV?d00001 diff --git a/utils/utils-testing/src/commonMain/resources/size/test_size_example/test_data_set_0/input_0.pb b/utils/utils-testing/src/commonMain/resources/size/test_size_example/test_data_set_0/input_0.pb new file mode 100644 index 0000000000000000000000000000000000000000..94cb2bd42d55cde9e2dfc7de734ad24d39c1675e GIT binary patch literal 44 kcmd;J;$RkFbYiUVl3-wXzkjbi0|SEt5CJieheC1z0Ns5Ixc~qF literal 0 HcmV?d00001 diff --git a/utils/utils-testing/src/commonMain/resources/size/test_size_example/test_data_set_0/output_0.pb b/utils/utils-testing/src/commonMain/resources/size/test_size_example/test_data_set_0/output_0.pb new file mode 100644 index 0000000000000000000000000000000000000000..24ca6754e7f6c38905413106d08fcc4ddadec3f1 GIT binary patch literal 16 ScmWe&cVevc;$UNd04@Lyi~%+P literal 0 HcmV?d00001 From aec6ea5fdcc0ea0da62940f93a47ac555d734f60 Mon Sep 17 00:00:00 2001 From: AnastasiaTuchina Date: Fri, 14 Jul 2023 20:37:58 +0200 Subject: [PATCH 2/4] KI-40 [tfjs] Add Size operator --- .../kinference.core/operators/tensor/Size.kt | 3 +- .../operators/operations/SizeTest.kt | 19 ------ .../operators/TFJSOperatorFactory.kt | 1 + .../operators/tensor/Size.kt | 58 ++++++++++++++++++ .../resources/size/test_size/descriptor.txt | 2 - .../resources/size/test_size/model.onnx | Bin 85 -> 0 bytes .../size/test_size/test_data_set_0/input_0.pb | 1 - .../test_size/test_data_set_0/output_0.pb | Bin 16 -> 0 bytes .../size/test_size_example/descriptor.txt | 2 - .../size/test_size_example/model.onnx | Bin 89 -> 0 bytes .../test_data_set_0/input_0.pb | Bin 44 -> 0 bytes .../test_data_set_0/output_0.pb | Bin 16 -> 0 bytes 12 files changed, 61 insertions(+), 25 deletions(-) delete mode 100644 inference/inference-core/src/commonTest/kotlin/io/kinference/operators/operations/SizeTest.kt create mode 100644 inference/inference-tfjs/src/jsMain/kotlin/io.kinference.tfjs/operators/tensor/Size.kt delete mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size/descriptor.txt delete mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size/model.onnx delete mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size/test_data_set_0/input_0.pb delete mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size/test_data_set_0/output_0.pb delete mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size_example/descriptor.txt delete mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size_example/model.onnx delete mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size_example/test_data_set_0/input_0.pb delete mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size_example/test_data_set_0/output_0.pb diff --git a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/tensor/Size.kt b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/tensor/Size.kt index 316be4c02..ee3bc7ec8 100644 --- a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/tensor/Size.kt +++ b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/tensor/Size.kt @@ -7,6 +7,7 @@ import io.kinference.data.ONNXData import io.kinference.graph.Contexts import io.kinference.ndarray.arrays.* import io.kinference.operator.* +import io.kinference.protobuf.message.TensorProto sealed class Size( name: String, @@ -42,7 +43,7 @@ class SizeVer1( ) private val OUTPUTS_INFO = listOf( - IOInfo(0, PRIMITIVE_DATA_TYPES, "size", differentiable = true, optional = false) + IOInfo(0, setOf(TensorProto.DataType.INT64), "size", differentiable = true, optional = false) ) internal val VERSION = VersionInfo(sinceVersion = 1) diff --git a/inference/inference-core/src/commonTest/kotlin/io/kinference/operators/operations/SizeTest.kt b/inference/inference-core/src/commonTest/kotlin/io/kinference/operators/operations/SizeTest.kt deleted file mode 100644 index a6efe7f8f..000000000 --- a/inference/inference-core/src/commonTest/kotlin/io/kinference/operators/operations/SizeTest.kt +++ /dev/null @@ -1,19 +0,0 @@ -package io.kinference.operators.operations - -import io.kinference.KITestEngine -import io.kinference.utils.TestRunner -import kotlin.test.Test - -class SizeTest { - private fun getTargetPath(dirName: String) = "size/$dirName/" - - @Test - fun test_size() = TestRunner.runTest { - KITestEngine.KIAccuracyRunner.runFromResources(getTargetPath("test_size")) - } - - @Test - fun test_acos_example() = TestRunner.runTest { - KITestEngine.KIAccuracyRunner.runFromResources(getTargetPath("test_size_example")) - } -} diff --git a/inference/inference-tfjs/src/jsMain/kotlin/io.kinference.tfjs/operators/TFJSOperatorFactory.kt b/inference/inference-tfjs/src/jsMain/kotlin/io.kinference.tfjs/operators/TFJSOperatorFactory.kt index b2cd50abf..54b67727a 100755 --- a/inference/inference-tfjs/src/jsMain/kotlin/io.kinference.tfjs/operators/TFJSOperatorFactory.kt +++ b/inference/inference-tfjs/src/jsMain/kotlin/io.kinference.tfjs/operators/TFJSOperatorFactory.kt @@ -109,6 +109,7 @@ object TFJSOperatorFactory : OperatorFactory> { "ScatterND" -> ScatterND(name, version, attributes, inputs, outputs) "Shape" -> Shape(name, version, attributes, inputs, outputs) "Sigmoid" -> Sigmoid(name, version, attributes, inputs, outputs) + "Size" -> Size(name, version, attributes, inputs, outputs) "SkipLayerNormalization" -> SkipLayerNormalization(name, version, attributes, inputs, outputs) "Slice" -> Slice(name, version, attributes, inputs, outputs) "Softmax" -> Softmax(name, version, attributes, inputs, outputs) diff --git a/inference/inference-tfjs/src/jsMain/kotlin/io.kinference.tfjs/operators/tensor/Size.kt b/inference/inference-tfjs/src/jsMain/kotlin/io.kinference.tfjs/operators/tensor/Size.kt new file mode 100644 index 000000000..5198463aa --- /dev/null +++ b/inference/inference-tfjs/src/jsMain/kotlin/io.kinference.tfjs/operators/tensor/Size.kt @@ -0,0 +1,58 @@ +package io.kinference.tfjs.operators.tensor + +import io.kinference.attribute.Attribute +import io.kinference.data.ONNXData +import io.kinference.graph.Contexts +import io.kinference.ndarray.arrays.NDArrayTFJS +import io.kinference.operator.* +import io.kinference.protobuf.message.TensorProto +import io.kinference.tfjs.data.tensors.TFJSTensor +import io.kinference.tfjs.data.tensors.asTensor + +sealed class Size( + name: String, + info: OperatorInfo, + attributes: Map>, + inputs: List, + outputs: List +) : Operator(name, info, attributes, inputs, outputs) { + companion object { + private val DEFAULT_VERSION = VersionInfo(sinceVersion = 1) + + operator fun invoke(name: String, version: Int?, attributes: Map>, inputs: List, outputs: List): Size { + return when (version ?: DEFAULT_VERSION.sinceVersion) { + in SizeVer1.VERSION.asRange() -> SizeVer1(name, attributes, inputs, outputs) + else -> error("Unsupported version of Size operator: $version") + } + } + } +} + + +class SizeVer1( + name: String, + attributes: Map>, + inputs: List, + outputs: List +) : Size(name, INFO, attributes, inputs, outputs) { + companion object { + private val ATTRIBUTES_INFO = emptyList() + + private val INPUTS_INFO = listOf( + IOInfo(0, PRIMITIVE_DATA_TYPES, "data", differentiable = true, optional = false) + ) + + private val OUTPUTS_INFO = listOf( + IOInfo(0, setOf(TensorProto.DataType.INT64), "size", differentiable = true, optional = false) + ) + + internal val VERSION = VersionInfo(sinceVersion = 1) + private val INFO = OperatorInfo("Size", ATTRIBUTES_INFO, INPUTS_INFO, OUTPUTS_INFO, VERSION, OperatorInfo.DEFAULT_DOMAIN) + } + + override suspend fun > apply(contexts: Contexts, inputs: List): List { + val inputSize = inputs[0]!!.data.linearSize + val dataSize = NDArrayTFJS.intScalar(inputSize.toLong()) + return listOf(dataSize.asTensor("size")) + } +} diff --git a/utils/utils-testing/src/commonMain/resources/size/test_size/descriptor.txt b/utils/utils-testing/src/commonMain/resources/size/test_size/descriptor.txt deleted file mode 100644 index 887e1c1e4..000000000 --- a/utils/utils-testing/src/commonMain/resources/size/test_size/descriptor.txt +++ /dev/null @@ -1,2 +0,0 @@ -test_data_set_0/input_0.pb -test_data_set_0/output_0.pb diff --git a/utils/utils-testing/src/commonMain/resources/size/test_size/model.onnx b/utils/utils-testing/src/commonMain/resources/size/test_size/model.onnx deleted file mode 100644 index 11c8ac69c3db235f7d50c78534a5b49b03e3f529..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 85 zcmd;J7UD@tOwLZtOVKS!EiSRL=i=dFtPo��z?�j@$ �?�.z��8s?b��hdӽ�9�>(�>�%�?^�B?�0�= B�>]ת>�=�?R�iJ�>�Z�/d#��S'?�K]?��=��C@�(��Hm;= �?�2�?��?��>���>�Ec������!��� >*z�?��?�Oƾmǚ��6��&õ�gڿ��?�x�FKྙ[��� G?4�ο��Y�L=e��> �����k��QN�>.:�=�ݚ>�b"�6��� diff --git a/utils/utils-testing/src/commonMain/resources/size/test_size/test_data_set_0/output_0.pb b/utils/utils-testing/src/commonMain/resources/size/test_size/test_data_set_0/output_0.pb deleted file mode 100644 index 11cedb8738b9efc9be129d1acc5f8ab549d538f2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16 ScmWe&cVevc;;>? lAO(C}JRFQd99&EsOhC+>#LdN6Da6Lb!oe=Y;KU@r2>|tZ5|sb| diff --git a/utils/utils-testing/src/commonMain/resources/size/test_size_example/test_data_set_0/input_0.pb b/utils/utils-testing/src/commonMain/resources/size/test_size_example/test_data_set_0/input_0.pb deleted file mode 100644 index 94cb2bd42d55cde9e2dfc7de734ad24d39c1675e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 44 kcmd;J;$RkFbYiUVl3-wXzkjbi0|SEt5CJieheC1z0Ns5Ixc~qF diff --git a/utils/utils-testing/src/commonMain/resources/size/test_size_example/test_data_set_0/output_0.pb b/utils/utils-testing/src/commonMain/resources/size/test_size_example/test_data_set_0/output_0.pb deleted file mode 100644 index 24ca6754e7f6c38905413106d08fcc4ddadec3f1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16 ScmWe&cVevc;$UNd04@Lyi~%+P From 058c22c08a65a30883c1f35dcdd476ad9b91e3dd Mon Sep 17 00:00:00 2001 From: AnastasiaTuchina Date: Fri, 14 Jul 2023 20:44:33 +0200 Subject: [PATCH 3/4] KI-40 [core, tfjs] Add missing tests for Size operator --- .../operators/activations/TanTest.kt | 4 ++-- .../operators/operations/SizeTest.kt | 19 ++++++++++++++++++ .../tfjs/operators/activations/TanTest.kt | 4 ++-- .../tfjs/operators/tensor/SizeTest.kt | 19 ++++++++++++++++++ .../resources/size/test_size/descriptor.txt | 2 ++ .../resources/size/test_size/model.onnx | Bin 0 -> 87 bytes .../size/test_size/test_data_set_0/input_0.pb | 1 + .../test_size/test_data_set_0/output_0.pb | Bin 0 -> 15 bytes .../size/test_size_example/descriptor.txt | 2 ++ .../size/test_size_example/model.onnx | Bin 0 -> 91 bytes .../test_data_set_0/input_0.pb | Bin 0 -> 35 bytes .../test_data_set_0/output_0.pb | Bin 0 -> 15 bytes 12 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 inference/inference-core/src/commonTest/kotlin/io/kinference/operators/operations/SizeTest.kt create mode 100644 inference/inference-tfjs/src/jsTest/kotlin/io/kinference/tfjs/operators/tensor/SizeTest.kt create mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size/descriptor.txt create mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size/model.onnx create mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size/test_data_set_0/input_0.pb create mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size/test_data_set_0/output_0.pb create mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size_example/descriptor.txt create mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size_example/model.onnx create mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size_example/test_data_set_0/input_0.pb create mode 100644 utils/utils-testing/src/commonMain/resources/size/test_size_example/test_data_set_0/output_0.pb diff --git a/inference/inference-core/src/commonTest/kotlin/io/kinference/operators/activations/TanTest.kt b/inference/inference-core/src/commonTest/kotlin/io/kinference/operators/activations/TanTest.kt index a9366b052..b4dc5ddcd 100644 --- a/inference/inference-core/src/commonTest/kotlin/io/kinference/operators/activations/TanTest.kt +++ b/inference/inference-core/src/commonTest/kotlin/io/kinference/operators/activations/TanTest.kt @@ -8,12 +8,12 @@ class TanTest { private fun getTargetPath(dirName: String) = "tan/$dirName/" @Test - fun test_tanh_example() = TestRunner.runTest { + fun test_tan_example() = TestRunner.runTest { KITestEngine.KIAccuracyRunner.runFromResources(getTargetPath("test_tan_example")) } @Test - fun test_tanh() = TestRunner.runTest { + fun test_tan() = TestRunner.runTest { KITestEngine.KIAccuracyRunner.runFromResources(getTargetPath("test_tan")) } } diff --git a/inference/inference-core/src/commonTest/kotlin/io/kinference/operators/operations/SizeTest.kt b/inference/inference-core/src/commonTest/kotlin/io/kinference/operators/operations/SizeTest.kt new file mode 100644 index 000000000..5b9281012 --- /dev/null +++ b/inference/inference-core/src/commonTest/kotlin/io/kinference/operators/operations/SizeTest.kt @@ -0,0 +1,19 @@ +package io.kinference.operators.operations + +import io.kinference.KITestEngine +import io.kinference.utils.TestRunner +import kotlin.test.Test + +class SizeTest { + private fun getTargetPath(dirName: String) = "size/$dirName/" + + @Test + fun test_size_example() = TestRunner.runTest { + KITestEngine.KIAccuracyRunner.runFromResources(getTargetPath("test_size_example")) + } + + @Test + fun test_size() = TestRunner.runTest { + KITestEngine.KIAccuracyRunner.runFromResources(getTargetPath("test_size")) + } +} diff --git a/inference/inference-tfjs/src/jsTest/kotlin/io/kinference/tfjs/operators/activations/TanTest.kt b/inference/inference-tfjs/src/jsTest/kotlin/io/kinference/tfjs/operators/activations/TanTest.kt index 84aa3099f..35dae8ec6 100644 --- a/inference/inference-tfjs/src/jsTest/kotlin/io/kinference/tfjs/operators/activations/TanTest.kt +++ b/inference/inference-tfjs/src/jsTest/kotlin/io/kinference/tfjs/operators/activations/TanTest.kt @@ -8,12 +8,12 @@ class TanTest { private fun getTargetPath(dirName: String) = "tan/$dirName/" @Test - fun test_tanh_example() = TestRunner.runTest { + fun test_tan_example() = TestRunner.runTest { TFJSAccuracyRunner.runFromResources(getTargetPath("test_tan_example")) } @Test - fun test_tanh() = TestRunner.runTest { + fun test_tan() = TestRunner.runTest { TFJSAccuracyRunner.runFromResources(getTargetPath("test_tan")) } } diff --git a/inference/inference-tfjs/src/jsTest/kotlin/io/kinference/tfjs/operators/tensor/SizeTest.kt b/inference/inference-tfjs/src/jsTest/kotlin/io/kinference/tfjs/operators/tensor/SizeTest.kt new file mode 100644 index 000000000..8976ba6fd --- /dev/null +++ b/inference/inference-tfjs/src/jsTest/kotlin/io/kinference/tfjs/operators/tensor/SizeTest.kt @@ -0,0 +1,19 @@ +package io.kinference.tfjs.operators.tensor + +import io.kinference.tfjs.runners.TFJSTestEngine.TFJSAccuracyRunner +import io.kinference.utils.TestRunner +import kotlin.test.Test + +class SizeTest { + private fun getTargetPath(dirName: String) = "size/$dirName/" + + @Test + fun test_size_example() = TestRunner.runTest { + TFJSAccuracyRunner.runFromResources(getTargetPath("test_size_example")) + } + + @Test + fun test_size() = TestRunner.runTest { + TFJSAccuracyRunner.runFromResources(getTargetPath("test_size")) + } +} diff --git a/utils/utils-testing/src/commonMain/resources/size/test_size/descriptor.txt b/utils/utils-testing/src/commonMain/resources/size/test_size/descriptor.txt new file mode 100644 index 000000000..7967d1896 --- /dev/null +++ b/utils/utils-testing/src/commonMain/resources/size/test_size/descriptor.txt @@ -0,0 +1,2 @@ +test_data_set_0/input_0.pb +test_data_set_0/output_0.pb \ No newline at end of file diff --git a/utils/utils-testing/src/commonMain/resources/size/test_size/model.onnx b/utils/utils-testing/src/commonMain/resources/size/test_size/model.onnx new file mode 100644 index 0000000000000000000000000000000000000000..215968302d2e504c8c61457b247c0b32fd276961 GIT binary patch literal 87 zcmdVE|zQ4}|~# literal 0 HcmV?d00001 diff --git a/utils/utils-testing/src/commonMain/resources/size/test_size/test_data_set_0/input_0.pb b/utils/utils-testing/src/commonMain/resources/size/test_size/test_data_set_0/input_0.pb new file mode 100644 index 000000000..bae0ffd63 --- /dev/null +++ b/utils/utils-testing/src/commonMain/resources/size/test_size/test_data_set_0/input_0.pb @@ -0,0 +1 @@ +BxJx?h>z?j@$ ?.z8s?bhdӽ9>(>%?^B?0= B>]ת>=?RiJ>Z/d#S'?K]?=C@(Hm;= ?2??>>Ec! >*z??Oƾmǚ6&õgڿ?xFKྙ[ G?4οYL=e> kQN>.:=ݚ>b"6 \ No newline at end of file diff --git a/utils/utils-testing/src/commonMain/resources/size/test_size/test_data_set_0/output_0.pb b/utils/utils-testing/src/commonMain/resources/size/test_size/test_data_set_0/output_0.pb new file mode 100644 index 0000000000000000000000000000000000000000..2355ec3529179531024828ca7269a594b283081a GIT binary patch literal 15 RcmWe&cVevc;;>? nAO(C}JRFQd99&EsOhC+>#LdN6Da6Lb!oe=Y;KahkARr6?9M}@E literal 0 HcmV?d00001 diff --git a/utils/utils-testing/src/commonMain/resources/size/test_size_example/test_data_set_0/input_0.pb b/utils/utils-testing/src/commonMain/resources/size/test_size_example/test_data_set_0/input_0.pb new file mode 100644 index 0000000000000000000000000000000000000000..9a18aeeb9b9f8631811af432db90c04fb5d6450e GIT binary patch literal 35 kcmd;J;$RkFbYiUVl3-wHuxDUkZ~!78ZUEv1KzzUf08BasV*mgE literal 0 HcmV?d00001 diff --git a/utils/utils-testing/src/commonMain/resources/size/test_size_example/test_data_set_0/output_0.pb b/utils/utils-testing/src/commonMain/resources/size/test_size_example/test_data_set_0/output_0.pb new file mode 100644 index 0000000000000000000000000000000000000000..6ca8cb761aa3c909f02f6081b80a8cc57bc0b28b GIT binary patch literal 15 RcmWe&cVevc;$UNd000eE0W1Ij literal 0 HcmV?d00001 From fa5a47c1fe157f545ad156ffbe301901e8abf206 Mon Sep 17 00:00:00 2001 From: AnastasiaTuchina Date: Mon, 17 Jul 2023 15:11:50 +0200 Subject: [PATCH 4/4] KI-40 [tfjs] Remove casting of output data in Size operator --- .../jsMain/kotlin/io.kinference.tfjs/operators/tensor/Size.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inference/inference-tfjs/src/jsMain/kotlin/io.kinference.tfjs/operators/tensor/Size.kt b/inference/inference-tfjs/src/jsMain/kotlin/io.kinference.tfjs/operators/tensor/Size.kt index 5198463aa..744557d46 100644 --- a/inference/inference-tfjs/src/jsMain/kotlin/io.kinference.tfjs/operators/tensor/Size.kt +++ b/inference/inference-tfjs/src/jsMain/kotlin/io.kinference.tfjs/operators/tensor/Size.kt @@ -52,7 +52,7 @@ class SizeVer1( override suspend fun > apply(contexts: Contexts, inputs: List): List { val inputSize = inputs[0]!!.data.linearSize - val dataSize = NDArrayTFJS.intScalar(inputSize.toLong()) + val dataSize = NDArrayTFJS.intScalar(inputSize) return listOf(dataSize.asTensor("size")) } }