我利用SAP Leonardo机器学习服务里的图像相似度比较开发了一个应用

The overall achitecture of this project could be found below:

我利用SAP Leonardo机器学习服务里的图像相似度比较开发了一个应用

(1) we build a native mobile application for end users via React-Native technology.

(2) A restful API is deployed in SAP Cloud Platform’s Cloud Foundry Environment. This API is technically implemented by a nodejs application running in SAP Cloud Platform. Once end users make a photo by this application, the binary stream of photo will be sent to restful API, and it’s expected that the top three pictures which have the largest image similarity with the current photo are sent back.

(3) The restful API fulfills the image similarity calculation tasks by leveraging two Leonardo Machine Learning services in SAP Cloud Platform:

a. Image Feature Extraction
b. Image Similarity Scoring

The binary stream of photo taken by end users will be translated by SAP Leonardo Image Feature Extraction service into a series of feature vectors. You can find one example from SAP help below:
https://help.sap.com/viewer/b04a8fe9c04745b98ad8652ccd5d636f/1908B/en-US/fc373869f9e642d1a2f490501414ee75.html

我利用SAP Leonardo机器学习服务里的图像相似度比较开发了一个应用

The consumption of this service is implemented in the project by file “featureExtractionService.js” under folder “toolbox”.

我利用SAP Leonardo机器学习服务里的图像相似度比较开发了一个应用

The recognization of top 3 similar images is achieved by calling another Leonardo Machine Learning service: Image Similarity Scoring. In order to ease consumption of this service, the project exposes an endpoint /getSimilarImage defined in file “index.js”.

我利用SAP Leonardo机器学习服务里的图像相似度比较开发了一个应用

To consume it, you can simply specify the binary stream of a given image, and this API will call Leonardo Machine Learning “Image Similarity Scoring” to return the top 3 similar images.

The Similar Scoring service will compare the feature vector of the given image with a couple of prepared feature vectors stored in image repository of the project.

The image repository is maintained in the project consisting of two folders: refImages and refFeatureVectors, while the former stores each picture file itself, the latter stores its corresponding feature vector.

我利用SAP Leonardo机器学习服务里的图像相似度比较开发了一个应用

If it is required to involve more pictures, you can simply put the new picture to folder “refImages”, and its feature vector to folder “refFeatureVectors”, both should have the same incremental index. In the folder there is a tool “featureExtractor.js” which helps you get the corresponding feature vector of a given image by command line.

要获取更多Jerry的原创文章,请关注公众号"汪子熙":
我利用SAP Leonardo机器学习服务里的图像相似度比较开发了一个应用