2017-04-19 66 views
1

我使用tensorflow圖像識別從main.cc,用命令:TensorFlow圖像識別輸出格式C++

巴澤勒濱/ tensorflow /示例/ label_image/label_image

電流輸出格式中終端是:

2017年4月19日:我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年4月19日:我tensorflow /.../ main.cc:206]釘盔(716):0.00800809

2017年4月19日:我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(); 
} 

問題是,我所要的輸出是一個列表,如:

軍裝,鏝,學術袍,釘盔,防彈背心

有可能有這樣的輸出?

+0

執行此命令是否有任何問題?:bazel build tensorflow/examples/label_image/... –

回答

1

是的,我認爲這是可能的。替換:

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

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

還好現在有一個逗號多於我們所需要的。所以我們檢查一下,如果它是最後一個概念,並且我們將逗號留下。

我希望有幫助。