使用SAP Cloud Platform Leonardo机器学习提取图片的特征向量

阅读更多

这个机器学习服务的文档:https://help.sap.com/viewer/b04a8fe9c04745b98ad8652ccd5d636f/1907B/en-US/d6fee2fd184d48d5b221928a8db4c2fd.html?q=Customizable%20Image%20Feature%20Extraction

测试控制台:

使用SAP Cloud Platform Leonardo机器学习提取图片的特征向量_第1张图片
使用SAP Cloud Platform Leonardo机器学习提取图片的特征向量_第2张图片

输入是任意一个图片文件,
输出是一串特征矩阵,如下图所示:

使用SAP Cloud Platform Leonardo机器学习提取图片的特征向量_第3张图片

完整代码:

var app = require('express')();
var server = require('http').Server(app);
var request = require('request');
var defaultPort = 8081;
const fs = require('fs');
var port = process.env.PORT || defaultPort;

console.log("Server listens on port: " + port);
server.listen(port);

function print_env(){
  console.log(process.env);
}

app.get('/', function (req, res) {

  res.header("Access-Control-Allow-Origin", "*");
  var response = "Hello World: " + port;

  callFeatureExtractionAPI();
  res.send(response);
});

app.get('/env', function (req, res) {

  print_env();
  // res.sendFile(__dirname + '/index.html');
  var response = JSON.stringify(process.env);
  res.send(response);
});

function callFeatureExtractionAPI() {

  var url = "https://mlfproduction-image-feature-extractor.cfapps.eu10.hana.ondemand.com/api/v2/image/feature-extraction";
  var api = "eyKXPuZf__ANtBqpk";
  var oRequestOptions = {
        url: url,
        method: "POST",
        json:true,
        formData: {
          files: fs.createReadStream("./1.png")
        },
        headers: {
            "Authorization": "Bearer " + api
        }
  };

  return new Promise(function(resolve,reject){
      var requestC = request.defaults({jar: true});
      console.log("Step1: get picture feature via url: " + url );

      requestC(oRequestOptions,function(error,response,body){
        if(error){
          console.log("error occurred: " + error);
          reject(error);
        }
        debugger;

        console.log("Body:" + body);
        console.log("response: " + response);
        resolve(body);
      }); 
     });
}

要获取更多Jerry的原创文章,请关注公众号"汪子熙":
使用SAP Cloud Platform Leonardo机器学习提取图片的特征向量_第4张图片

你可能感兴趣的:(SAP,SAP,Cloud,Platform,SAP云平台,CloudFoundry)