【问题标题】:TensorFlow image recognition output format c++TensorFlow图像识别输出格式c++
【发布时间】:2017-04-19 14:22:27
【问题描述】:

我使用 tensorflow 从main.cc 进行图像识别,使用命令:

bazel-bin/tensorflow/examples/label_image/label_image

终端当前输出格式为:

2017-04-19:I tensorflow/.../main.cc:206] 军装(653):0.834307

2017-04-19:I tensorflow/.../main.cc:206] 砂浆板(668):0.0218693

2017-04-19: I tensorflow/.../main.cc:206] 学术袍 (401): 0.010358

2017-04-19: I tensorflow/.../main.cc:206] pickelhaube (716): 0.00800809

2017-04-19: I tensorflow/.../main.cc:206] 防弹背心 (466): 0.00535086

输出函数为:

// this prints out the top five highest-scoring values.
Status PrintTopLabels(const std::vector<Tensor>& outputs,
                      string labels_file_name) {
  std::vector<string> labels;
  size_t label_count;
  Status read_labels_status =
      ReadLabelsFile(labels_file_name, &labels, &label_count);
  if (!read_labels_status.ok()) {
    LOG(ERROR) << read_labels_status;
    return read_labels_status;
  }
  const int how_many_labels = std::min(5, static_cast<int>(label_count));
  Tensor indices;
  Tensor scores;
  TF_RETURN_IF_ERROR(GetTopLabels(outputs, how_many_labels, &indices, &scores));
  tensorflow::TTypes<float>::Flat scores_flat = scores.flat<float>();
  tensorflow::TTypes<int32>::Flat indices_flat = indices.flat<int32>();
  for (int pos = 0; pos < how_many_labels; ++pos) {
    const int label_index = indices_flat(pos);
    const float score = scores_flat(pos);
    LOG(INFO) << labels[label_index] << " (" << label_index << "): " << score;
  }
  return Status::OK();
}

问题是,我希望输出是这样的列表:

军装、迫击炮、学术长袍、pickelhaube、防弹背心

有可能有这样的输出吗?

【问题讨论】:

  • 执行这个命令有什么问题吗?:bazel build tensorflow/examples/label_image/...

标签: c++ tensorflow


【解决方案1】:

是的,我认为这是可能的。替换:

LOG(INFO) << labels[label_index] << " (" << label_index << "): " << score;

std::cout << label[label_index] << ",";

好的,现在多了一个逗号,超出了我们的需要。所以我们之前检查它是否是最后一个概念,如果是,我们把逗号去掉。

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 2019-07-06
    • 2018-01-13
    • 2017-12-22
    • 2013-10-28
    • 1970-01-01
    • 2013-06-17
    • 2017-12-16
    • 2013-06-12
    • 2016-08-10
    相关资源
    最近更新 更多