【问题标题】:Classifying Images using Bluemix使用 Bluemix 对图像进行分类
【发布时间】:2016-05-25 23:01:53
【问题描述】:

经过深入研究,我决定使用 Bluemix 对图像进行分类和识别。

我有一个关于如何使用 node.js 运行时开始编程的入门问题。

我尝试关注this 教程。但是,这只是代码的 sn-ps。您如何运行它们并查看它在 Bluemix 环境中的工作情况?

我的进步:
- 我在 Bluemix 中启动了 node.js 启动器应用程序。
-我添加了以下代码,app.js 看起来是这样的:

    /*eslint-env node*/

//--------------------------------------------------------------------------
// node.js starter application for Bluemix
//--------------------------------------------------------------------------

// This application uses express as its web server
// for more info, see: http://expressjs.com
var express = require('express');

// cfenv provides access to your Cloud Foundry environment
// for more info, see: https://www.npmjs.com/package/cfenv
var cfenv = require('cfenv');

// create a new express server
var app = express();

// serve the files out of ./public as our main files
app.use(express.static(__dirname + '/public'));

// get the app environment from Cloud Foundry
var appEnv = cfenv.getAppEnv();

// start server on the specified port and binding host
app.listen(appEnv.port, '0.0.0.0', function() {
  // print a message when the server starts listening
  console.log("server starting on " + appEnv.url);
});

var watson = require('watson-developer-cloud');
var fs = require('fs');

/*var visual_recognition = watson.visual_recognition({
  username: '<username>',
  password: '<password>',
  version: 'v2-beta',
  version_date: '2015-12-02'
});*/

 var visualRecognition = watson.visual_recognition({
   version: 'v3',
   api_key: process.env.API_KEY || 'my api key',
   version_date: '2015-05-19'
 });

var params = {
  images_file: fs.createReadStream('./resources/car.png')
};

visualRecognition.classify(params, function(err, res) {
  if (err)
    console.log(err);
  else
    console.log(JSON.stringify(res, null, 2));
});

我正在尝试在 Bluemix 环境(实时编辑模式)中而不是在本地运行代码。当我点击运行代码时,部署停止,我什至无法找到导致这种情况发生的代码行。当我访问网页时,我收到以下错误:

404 Not Found:请求的路由('myvisualapp.mybluemix.net')不存在。

我不明白出了什么问题以及如何调试代码。

作者级别:初学者

【问题讨论】:

  • 你能告诉我你提到的“运行代码”按钮在哪里吗?

标签: node.js ibm-cloud ibm-watson visual-recognition


【解决方案1】:
  1. 您需要快速“路由”(或至少拦截)客户端请求。现在,该请求没有处理程序。为此目的使用 app.get() 调用
  2. 您的 watson 服务调用现在不受用户请求的限制。您需要通过用户请求将其汇集起来。

例如:

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

// invoke watson services
// get the result.
// write back the result through the response object, res

}

【讨论】:

    【解决方案2】:

    您可以查看https://github.com/watson-developer-cloud/visual-recognition-nodejs 的演示代码并从这里开始。

    此外,您可以从命令行查看使用

    部署到 bluemix 中的应用程序的日志

    $ cf logs YOURAPPNAME --recent

    其中 YOURAPPNAME 是您推送到 bluemix 的应用程序的名称。您可以使用

    获取名称

    $ cf apps

    如果您忘记了您使用的名称(这一直发生在我身上)。

    【讨论】:

      猜你喜欢
      • 2020-02-09
      • 2016-01-21
      • 2016-07-22
      • 2017-12-22
      • 2012-06-29
      • 2016-09-13
      • 2018-07-23
      • 1970-01-01
      • 2014-05-12
      相关资源
      最近更新 更多