dongpu3347 2018-03-07 09:52
浏览 97
已采纳

在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

  • 写回答

1条回答 默认 最新

  • douyuben9434 2018-03-07 10:19
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘