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 微带串馈天线阵列每个阵元宽度计算
  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了