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

Implemented getOutputElementType #25760

Merged
merged 42 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
7d6a2c7
implemented getOutputElementType
Pey-crypto Jul 14, 2024
acfffa7
Fixed errors in variable names
Pey-crypto Jul 14, 2024
9a67e56
Fixed Error in error string
Pey-crypto Jul 15, 2024
7c671cc
Merge branch 'master' into master
Pey-crypto Jul 16, 2024
74122ce
Update src/bindings/js/node/include/model_wrap.hpp
Pey-crypto Jul 17, 2024
f301d12
Update src/bindings/js/node/lib/addon.ts
Pey-crypto Jul 17, 2024
2718d0b
Update src/bindings/js/node/src/model_wrap.cpp
Pey-crypto Jul 17, 2024
950ab0d
Updates to get_output_element_type
Pey-crypto Jul 17, 2024
a38ccf1
Merge branch 'openvinotoolkit:master' into master
Pey-crypto Jul 17, 2024
9fd778e
Updated
Pey-crypto Jul 20, 2024
4ea1ba6
Merge branch 'openvinotoolkit:master' into master
Pey-crypto Jul 20, 2024
5e961c5
Fixed allowed signatures and used the format described in type_valida…
Pey-crypto Jul 20, 2024
285a94a
addon.ts
Pey-crypto Jul 20, 2024
350cbea
Updated the method to use the type_validation.
Pey-crypto Jul 24, 2024
be5b9a6
Updates to method and tests.
Pey-crypto Jul 26, 2024
2b824e7
Resolved merge conflicts
Pey-crypto Jul 27, 2024
12fa8f7
Fixed formatting error
Pey-crypto Jul 27, 2024
1a77dbb
Fixed allowed signatures and used the format described in type_valida…
Pey-crypto Jul 20, 2024
01bca61
Fixed addon.ts
Pey-crypto Jul 20, 2024
7cf0c70
Updated the method to use the type_validation.
Pey-crypto Jul 24, 2024
1dca9e4
Updates to method and tests.
Pey-crypto Jul 26, 2024
2b9d119
Fixed formatting error
Pey-crypto Jul 27, 2024
46cf4fd
Merge branch 'outputDataType' of https://github.com/Pey-crypto/openvi…
Pey-crypto Jul 27, 2024
118807c
Revert changes in package-lock.json and model.test.js to resolve merg…
Pey-crypto Jul 27, 2024
84d8256
fixing merge errors
Pey-crypto Jul 27, 2024
368b990
Merge branch 'outputDataType' of https://github.com/Pey-crypto/openvi…
Pey-crypto Jul 27, 2024
94dea69
resolved error functions
Pey-crypto Jul 27, 2024
a8778d4
Reverted changes committed to open_model_zoo to the previous state
Pey-crypto Jul 28, 2024
4e8ceaa
Removed the correct package-lock file.
Pey-crypto Jul 28, 2024
9a235eb
Updated files to the last commit.
Pey-crypto Jul 28, 2024
fb72d48
Merge branch 'master' into outputDataType
Pey-crypto Jul 29, 2024
933dfb6
Applied suggestions:
Pey-crypto Jul 29, 2024
78d899d
Merge branch 'master' into outputDataType
Pey-crypto Jul 30, 2024
4447083
deleted file
Pey-crypto Jul 30, 2024
7568016
Merge branch 'openvinotoolkit:master' into outputDataType
Pey-crypto Jul 30, 2024
10d3865
Applied suggestions
Pey-crypto Aug 1, 2024
b96f04c
Merge branch 'outputDataType' of https://github.com/Pey-crypto/openvi…
Pey-crypto Aug 1, 2024
954a72e
Fixed merge issue
Pey-crypto Aug 1, 2024
2f2827a
Merge branch 'master' into outputDataType
Pey-crypto Aug 1, 2024
d50c812
Merge branch 'master' into outputDataType
Pey-crypto Aug 2, 2024
54b6e28
Fix documentation comment
almilosz Aug 2, 2024
5bc3023
Update src/bindings/js/node/lib/addon.ts
almilosz Aug 2, 2024
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
7 changes: 7 additions & 0 deletions src/bindings/js/node/include/model_wrap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ class ModelWrap : public Napi::ObjectWrap<ModelWrap> {
* @return Napi::Array containing a shape of requested output.
*/
Napi::Value get_output_shape(const Napi::CallbackInfo& info);

/**
* @brief Helper function to access model output elements types.
* @return Napi::String representing the element type of the requested output.
*
*/
Napi::Value get_output_element_type(const Napi::CallbackInfo& info);

private:
std::shared_ptr<ov::Model> _model;
Expand Down
5 changes: 5 additions & 0 deletions src/bindings/js/node/lib/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ interface Model {
* It returns the number of the model outputs.
*/
getOutputSize(): number;
/**
* It gets the element type of a specific output of the model.
* @param index The index of the output.
*/
getOutputElementType(index: number): string;
/**
* It gets the input of the model.
* If a model has more than one input, this method throws an exception.
Expand Down
18 changes: 18 additions & 0 deletions src/bindings/js/node/src/model_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "node/include/errors.hpp"
#include "node/include/helper.hpp"
#include "node/include/node_output.hpp"
#include "node/include/type_validation.hpp"

ModelWrap::ModelWrap(const Napi::CallbackInfo& info)
: Napi::ObjectWrap<ModelWrap>(info),
Expand All @@ -25,6 +26,7 @@ Napi::Function ModelWrap::get_class(Napi::Env env) {
InstanceMethod("setFriendlyName", &ModelWrap::set_friendly_name),
InstanceMethod("getFriendlyName", &ModelWrap::get_friendly_name),
InstanceMethod("getOutputShape", &ModelWrap::get_output_shape),
InstanceMethod("getOutputElementType", &ModelWrap::get_output_element_type),
InstanceAccessor<&ModelWrap::get_inputs>("inputs"),
InstanceAccessor<&ModelWrap::get_outputs>("outputs")});
}
Expand Down Expand Up @@ -171,3 +173,19 @@ Napi::Value ModelWrap::get_output_shape(const Napi::CallbackInfo& info) {
return info.Env().Undefined();
}
}

Napi::Value ModelWrap::get_output_element_type(const Napi::CallbackInfo& info) {
std::vector<std::string> allowed_signatures;
try {
if (ov::js::validate<int>(info, allowed_signatures)) {
auto idx = info[0].As<Napi::Number>().Int32Value();
const auto& output = _model->output(idx);
return cpp_to_js<ov::element::Type_t, Napi::String>(info, output.get_element_type());
} else {
OPENVINO_THROW("'getOutputElementType'", ov::js::get_parameters_error_msg(info, allowed_signatures));
}
} catch (const std::exception& e) {
reportError(info.Env(), e.what());
return info.Env().Undefined();
}
}
45 changes: 45 additions & 0 deletions src/bindings/js/node/tests/unit/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,48 @@ describe('Model.getOutputSize()', () => {
assert.strictEqual(model.getOutputSize(), 1, 'Expected getOutputSize to return 1 for the default model');
});
});

describe('Model.getOutputElementType()', () => {
it('should return a string for the element type ', () => {
const result = model.getOutputElementType(0);
assert.strictEqual(typeof result, 'string',
'getOutputElementType() should return a string');
});

it('should accept a single integer argument', () => {
assert.throws(() => {
model.getOutputElementType();
}, /'getOutputElementType' method called with incorrect parameters/,
'Should throw when called without arguments');

assert.throws(() => {
model.getOutputElementType('unexpected argument');
}, /'getOutputElementType' method called with incorrect parameters/,
'Should throw on non-number argument');

assert.throws(() => {
model.getOutputElementType(0, 1);
}, /'getOutputElementType' method called with incorrect parameters/,
'Should throw on multiple arguments');

assert.throws(() => {
model.getOutputElementType(3.14);
}, /'getOutputElementType' method called with incorrect parameters/,
'Should throw on non-integer number');
});

it('should return a valid element type for the default model', () => {
const elementType = model.getOutputElementType(0);
assert.ok(typeof elementType === 'string' && elementType.length > 0,
`Expected a non-empty string, got ${elementType}`);
});

it('should throw an error for out-of-range index', () => {
const outputSize = model.getOutputSize();
assert.throws(
() => { model.getOutputElementType(outputSize); },
/^Error: /,
'Should throw for out-of-range index'
);
});
});
Loading