在Go可执行文件中包括完整的目录结构,而不是单个文件

I am trying to create an executable program with a trained tensorflow model. However, I have realised that the compiled Go script will need the model directory path as an argument. To avoid this I would like to include the model in the Go executable and compile them together. I have been looking at go-bindata but that doesn't work in this case because the function tf.LoadSavedModel takes a directory path to load the model, not the actual model files.

Do you know how this could be done?

EDIT:

tf.LoadSavedModel function (https://godoc.org/github.com/tensorflow/tensorflow/tensorflow/go#LoadSavedModel) needs the path of a directory to load a model. It is not able to process individual files, so thats why go-bindata (which is the solution of that question) doesn't work in this case. tf.LoadSavedModel uses a function in C to load files in a directory, so the files cannot be provided directly to Go. I hope that I explained it correctly

Take a look at golang.org/x/tools/godoc/vfs or, say, github.com/spf13/afero.

Combined with go-bindata or any other package providing for embedding of file contents, it could be used to abstract away filesystem-like trees (directory hierarchies).


Note that this approach presumes that "tensorflow" thing is able to use such virtualization. If, instead, it insists on using a path on a real filesystem, you'll need to work around this somehow.

One approach is to embed an archive file into your executable, and then unpack it under a temporary directory during the program initialization phase. Read up on io/ioutil.TempDir.