2016-06-02 23 views
5

Sto provando a creare un progetto che utilizza TensorFlow Serving, quindi ho creato una directory my_dir con un file WORKSPACE, clonato il repository di servizio, messo i miei file personalizzati in una directory my_project, configurato in tensorflow all'interno di tensorflow_serving , costruita tensorflow servire da my_dir/porzione conProgetti nidificati Bazel

bazel build //tensorflow_serving/... 

tutto costruisce bene lì, quindi cerco di creare un file python imita mnist_export e metterlo in my_dir e fare un build file

py_binary(
    name = "export_cnn", 
    srcs = [ 
     "export_cnn.py", 
    ], 
    deps = [ 
     "@tf//tensorflow:tensorflow_py", 
     "@tf_serving//tensorflow_serving/session_bundle:exporter", 
    ], 
) 

Tuttavia, quando corro

bazel build //my_project:export_cnn 

ottengo i seguenti errori:

ERROR: 

.../bazel/_bazel_me/3ef3308a843af155635e839105e8da5c/external/tf/tensorflow/core/BUILD:92:1: null failed: protoc failed: error executing command bazel-out/host/bin/external/tf/google/protobuf/protoc '--cpp_out=bazel-out/local_linux-fastbuild/genfiles/external/tf' -Iexternal/tf -Iexternal/tf/google/protobuf/src ... (remaining 1 argument(s) skipped). 
tensorflow/core/framework/step_stats.proto: File not found. 
tensorflow/core/framework/device_attributes.proto: File not found. 
tensorflow/core/framework/graph.proto: File not found. 
tensorflow/core/framework/tensor.proto: File not found. 
tensorflow/core/protobuf/config.proto: File not found. 
tensorflow/core/protobuf/worker.proto: Import "tensorflow/core/framework/step_stats.proto" was not found or had errors. 
tensorflow/core/protobuf/worker.proto: Import "tensorflow/core/framework/device_attributes.proto" was not found or had errors. 
tensorflow/core/protobuf/worker.proto: Import "tensorflow/core/framework/graph.proto" was not found or had errors. 
tensorflow/core/protobuf/worker.proto: Import "tensorflow/core/framework/tensor.proto" was not found or had errors. 
tensorflow/core/protobuf/worker.proto: Import "tensorflow/core/protobuf/config.proto" was not found or had errors. 
tensorflow/core/protobuf/worker.proto:41:12: "DeviceAttributes" is not defined. 
tensorflow/core/protobuf/worker.proto:64:3: "GraphDef" is not defined. 
tensorflow/core/protobuf/worker.proto:72:3: "GraphOptions" is not defined. 
tensorflow/core/protobuf/worker.proto:141:3: "TensorProto" is not defined. 
tensorflow/core/protobuf/worker.proto:180:3: "StepStats" is not defined. 
tensorflow/core/protobuf/worker.proto:225:3: "BusAdjacency" is not defined. 
tensorflow/core/protobuf/worker.proto:227:3: "BusAdjacency" is not defined. 
tensorflow/core/protobuf/worker.proto:232:3: "TensorProto" is not defined. 
tensorflow/core/protobuf/worker.proto:272:3: "StepStats" is not defined. 

Nel mio file di lavoro, ho le seguenti:

local_repository(
    name = "tf", 
    path = __workspace_dir__ + "/serving/tensorflow", 
) 

local_repository(
    name = "tf_serving", 
    path = __workspace_dir__ + "/serving", 
) 

load('//serving/tensorflow/tensorflow:workspace.bzl', 'tf_workspace') 
tf_workspace("serving/tensorflow/", "@tf") 

La mia ipotesi è che perché tensorflow è un sotto-sotto-progetto non sta mettendo i suoi file generati nei progetti per nonni bazel-out. Tuttavia, ho provato molte cose e non sono riuscito a farlo funzionare.

risposta

3

Ho tensorflow che serve in una cartella e il mio progetto in un altro. Questo è il mio file di lavoro:

workspace(name = "my_project") 

local_repository(
    name = "org_tensorflow", 
    path = __workspace_dir__ + "/tf-serving/tensorflow/", 
) 

local_repository(
    name = "tf_serving", 
    path = __workspace_dir__ + "/tf-serving/", 
) 

load('//tf-serving/tensorflow/tensorflow:workspace.bzl', 'tf_workspace') 
tf_workspace("tf-serving/tensorflow/", "@org_tensorflow") 

# ===== gRPC dependencies ===== 

bind(
    name = "libssl", 
    actual = "@boringssl_git//:ssl", 
) 

bind(
    name = "zlib", 
    actual = "@zlib_archive//:zlib", 
) 

Ho anche copiato zlib.BUILD da tensorflow servire nello stesso posto in cui ho il file di lavoro.

Il file BUILD nel mio progetto ha questa regola (simile alla tua):

py_binary(
    name = "export_model", 
    srcs = [ 
     "export_model.py", 
    ], 
    deps = [ 
     "@org_tensorflow//tensorflow:tensorflow_py", 
     "@tf_serving//tensorflow_serving/session_bundle:exporter", 
    ], 
) 

La differenza tra il mio codice e il vostro è che ho incluso le dipendenze in Area di lavoro radice. Questo codice è compilato e funziona bene per me in una macchina Ho alcuni problemi per compilarlo in altri (ubuntu 14.04) a causa di una dipendenza. Spero che funzioni per te.

0

ho dovuto aggiungere anche

--genrule_strategy=standalone --spawn_strategy=standalone 

al comando di generazione al fine di ottenere le dipendenze fisse, si compila bene quando viene eseguito da lavoro tf-serving, ma appena ho linkato tf-serving come un sottomodulo e lo ho eseguito dal mio spazio di lavoro ho avuto errori di file header mancanti (nanopb/pb.h) durante la compilazione di grpc.