簡體   English   中英

在GPU Java上配置Tensorflow

[英]Configure Tensorflow on GPU Java

如何使用Java API為Tensorflow設置以下配置“ gpu_options.allow_growth = True”?

我以這種方式嘗試過:

model.session().runner()
                .setOptions("gpu_options.allow_growth = True".getBytes())
                .feed("image_tensor", input).fetch("detection_scores")
                .fetch("detection_classes").fetch("detection_boxes").fetch("num_detections").run();

我收到以下錯誤:無法解析的RunOptions原型。

我認為這是配置的方式:

      ConfigProto config = ConfigProto.newBuilder()
                .setGpuOptions(GPUOptions.newBuilder().setAllowGrowth(true))
                .build();

      model.session().runner()
                    .setOptions(config.toByteArray())
                    .feed("image_tensor", input).fetch("detection_scores")
                    .fetch("detection_classes").fetch("detection_boxes").fetch("num_detections").run();

API 文檔說:

公共Session.Runner setOptions(字節[]選項)

(實驗方法):為此運行設置選項(通常用於調試)。

選項顯示為序列化的RunOptions協議緩沖區。

仍然在尋找一個確切的例子,但是我認為:僅采取一個字符串並將其轉換為字節數組並不是您應該做的。

這些示例表明您需要以下內容:

Session.Run r = runner.setOptions(RunStats.runOptions()).runAndFetchMetadata();
fetchTensors = r.outputs;

if (runStats == null) {
  runStats = new RunStats();
}

長話短說:您必須深入研究RunStats才能弄清楚如何在其中獲取選項,然后向setOptions()方法提供該類的對象。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM