This repository has been archived by the owner on Feb 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
46 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
"use strict"; | ||
|
||
const leonardo = require('sap-leonardo'); | ||
|
||
// set the API_KEY in the console, e.g. export API_KEY=abc123 | ||
var imageFeatureExtraction = new leonardo.ImageFeatureExtraction(process.env.API_KEY); | ||
|
||
imageFeatureExtraction.featureExtraction("./testdata/chucks-153310_640.png") | ||
|
||
.then(body => { | ||
console.log("RESULT:", body.predictions[0].featureVectors.length, 'vectors') | ||
// RESULT: 2048 vectors | ||
.then((body) => { | ||
console.log("result:", body.predictions[0].featureVectors.length, 'vectors'); | ||
// result: 2048 vectors | ||
}) | ||
.catch(err => { console.error(err) }); | ||
.catch((err) => { console.error(err); }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
"use strict"; | ||
|
||
const leonardo = require('sap-leonardo'); | ||
|
||
// set the API_KEY in the console, e.g. export API_KEY=abc123 | ||
var imageclassification = new leonardo.Imageclassification(process.env.API_KEY); | ||
|
||
imageclassification.classification("./testdata/elephant-114543_640.jpg") | ||
.then(body => { | ||
console.log(JSON.stringify(body, null, " ")); | ||
.then((body) => { | ||
var firstResult = body.predictions[0].results[0]; | ||
console.log("RESULT:", firstResult.label, firstResult.score) | ||
// RESULT: tusker 0.7052137851715088 | ||
console.log("result:", firstResult.label, firstResult.score); | ||
// result: tusker 0.7052137851715088 | ||
}) | ||
.catch(err => { console.error(err) }); | ||
.catch((err) => { console.error(err); }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
"use strict"; | ||
|
||
const leonardo = require('sap-leonardo'); | ||
|
||
// set the API_KEY in the console, e.g. export API_KEY=abc123 | ||
var multiInstanceImageSegmentation = new leonardo.MultiInstanceImageSegmentation(process.env.API_KEY); | ||
|
||
multiInstanceImageSegmentation.instanceSegmentor("testdata/juice-1271881_640.jpg") | ||
.then(body => { | ||
//console.log(JSON.stringify(body, null, " ")); | ||
console.log("RESULT:", body.predictions[0].results.length, 'segmentations'); | ||
// RESULT: 4 segmentations | ||
.then((body) => { | ||
console.log("result:", body.predictions[0].results.length, 'segmentations'); | ||
// result: 4 segmentations | ||
}) | ||
.catch(err => { console.error(err) }); | ||
.catch((err) => { console.error(err); }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,49 @@ | ||
"use strict"; | ||
|
||
const leonardo = require('sap-leonardo'); | ||
|
||
// set the API_KEY in the console, e.g. export API_KEY=abc123 | ||
|
||
var similarityScoring = new leonardo.SimilarityScoring(process.env.API_KEY); | ||
|
||
const data = | ||
{ | ||
"0": [ | ||
{ | ||
"id": "vector_0", | ||
"vector": [0.28340766699907016, 0.9207926435655764, 0.26789935106091334, 0.318534020870441, 0.8788578877488213, 0.4509478663720774, 0.3771976033350821, 0.8324932893262449, 0.3125285189224729, 0.0012454795540639552] | ||
"vector": [ | ||
0.28340766699907016, | ||
0.9207926435655764, | ||
0.26789935106091334 | ||
] | ||
}, | ||
{ | ||
"id": "vector_1", | ||
"vector": [0.45833237104751445, 0.32694129428557406, 0.8764997717518421, 0.15381826488593253, 0.995488727839039, 0.5471706751917085, 0.702883336443525, 0.623838711091733, 0.12306071043362388, 0.004332364690005086] | ||
"vector": [ | ||
0.45833237104751445, | ||
0.32694129428557406, | ||
0.8764997717518421 | ||
] | ||
}, | ||
{ | ||
"id": "vector_2", | ||
"vector": [0.3556300142239819, 0.5045324288959441, 0.7577918039699381, 0.8632635582322563, 0.633311116403191, 0.2435334301982892, 0.6287482927751646, 0.7181573415502425, 0.5023501732127003, 0.18362374274429505] | ||
"vector": [ | ||
0.3556300142239819, | ||
0.5045324288959441, | ||
0.7577918039699381 | ||
] | ||
} | ||
] | ||
} | ||
}; | ||
|
||
const options = JSON.stringify({ "numSimilarVectors": 2 }); | ||
|
||
similarityScoring.similarityScoring(null, JSON.stringify(data), options) | ||
.then(body => { | ||
console.log(JSON.stringify(body, null, " ")); | ||
.then((body) => { | ||
console.log( | ||
"result:", | ||
body.predictions[0].id, | ||
body.predictions[0].similarVectors[0].id, | ||
body.predictions[0].similarVectors[0].score | ||
); | ||
|
||
var firstPrediction = body.predictions[0]; | ||
var firstSimilarVector = firstPrediction.similarVectors[0]; | ||
console.log("RESULT:", firstPrediction.id, firstSimilarVector.id, firstSimilarVector.score); | ||
// RESULT: RESULT: vector_0 vector_2 0.849864721937753 | ||
}) | ||
.catch(err => { console.error(err) }); | ||
// result: vector_0 vector_2 0.786171751770592 | ||
}) | ||
.catch((err) => { console.error(err); }); |