{"id":15159395,"url":"https://github.com/xwi88/gp","last_synced_at":"2026-01-20T05:31:51.529Z","repository":{"id":45612669,"uuid":"341405669","full_name":"xwi88/gp","owner":"xwi88","description":"go predict with tensorflow, pytorch and others ","archived":false,"fork":false,"pushed_at":"2021-12-08T13:43:10.000Z","size":30,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-13T18:50:52.730Z","etag":null,"topics":["go","prediction","tensorflow","tensorflow-examples"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xwi88.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-23T02:41:11.000Z","updated_at":"2024-10-04T03:20:44.000Z","dependencies_parsed_at":"2022-08-28T10:00:35.906Z","dependency_job_id":null,"html_url":"https://github.com/xwi88/gp","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xwi88%2Fgp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xwi88%2Fgp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xwi88%2Fgp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xwi88%2Fgp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xwi88","download_url":"https://codeload.github.com/xwi88/gp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247687849,"owners_count":20979547,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","prediction","tensorflow","tensorflow-examples"],"created_at":"2024-09-26T21:20:53.066Z","updated_at":"2026-01-20T05:31:46.504Z","avatar_url":"https://github.com/xwi88.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gp\n\ngo predict with tensorflow, pytorch and others\n\n## Env\n\n\u003e work well in\n\n- go 1.16+\n- os: x86_64, `Ubuntu 14.04+` | `MacOS`\n- Tensorflow C API: **2.3.0**\n- github.com/tensorflow/tensorflow v2.1.3 or v2.1.4\n\n## Tensorflow\n\n### Ref\n\n- [tensorflow](https://github.com/tensorflow/tensorflow)\n- [tensorflow-serving](https://github.com/tensorflow/serving)\n\n### Go API\n\n\u003ehttps://www.tensorflow.org/install/lang_go\n\n### C Lib\n\n- [download](https://www.tensorflow.org/install/lang_c#download)\n- [libtensorflow-cpu-darwin-x86_64-2.3.0](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-darwin-x86_64-2.3.0.tar.gz)\n- [libtensorflow-cpu-linux-x86_64-2.3.0](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.3.0.tar.gz)\n\n```bash\n#export LIB_TENSORFLOW_FILE=libtensorflow-cpu-darwin-x86_64-2.3.0.tar.gz\nexport LIB_TENSORFLOW_FILE=libtensorflow-cpu-linux-x86_64-2.3.0.tar.gz\n```\n\n#### **Standard Install**\n\n```bash\ntar -C /usr/local -xzf ${LIB_TENSORFLOW_FILE}\n# linux\nldconfig\n\n# macos 11.2.2+ work well\nexport LD_LIBRARY_PATH=\"${LD_LIBRARY_PATH}:/usr/local/lib\"\n```\n\n#### *Non Sys Dir Install*\n\n```bash\nexport LIB_TENSORFLOW_INSTALL_DIR=~/mydir\ntar -C ${LIB_TENSORFLOW_INSTALL_DIR} -xzf ${LIB_TENSORFLOW_FILE}\n\n# config linker\nexport LIBRARY_PATH=$LIBRARY_PATH:${LIB_TENSORFLOW_INSTALL_DIR}/lib # For both Linux and macOS X\nexport LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${LIB_TENSORFLOW_INSTALL_DIR}/lib # For Linux only\nexport DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:${LIB_TENSORFLOW_INSTALL_DIR}/lib # For macOS X only\n```\n\n#### C Lib Check\n\n```cgo\n#include \u003cstdio.h\u003e\n#include \u003ctensorflow/c/c_api.h\u003e\n\nint main() {\n  printf(\"Hello from TensorFlow C library version %s\\n\", TF_Version());\n  return 0;\n}\n```\n\n- `gcc hello_tf.c -ltensorflow -o hello_tf`\n- `./hello_tf`\n\n### Go Usage\n\n`go get github.com/xwi88/gp`\n\n### Example\n\n```bash\n# register model\nRegisterTFModelWithParamName(modelName, exportDir, tags, []string{\"param_name_input\"}, \"param_name_output\")\n\n# predict.go\n# get model\nGetModel(modelName)\n# predict with the special model\noutput, err := Predict(modelName, input ...interface{})\n```\n\n### Params Look Up\n\n- `pip install tensorflow`\n- `saved_model_cli show --all --dir output/keras`\n\n### Docker Images\n\n\u003e**tf version now will be ok in: macos \u0026 ubuntu16.04**\n\n|image repos|target|notes|\n|:--|:--|:--|\n|v8fg/ubuntu:22.04-go1.17.4-tf-cpu|build||\n|v8fg/ubuntu:22.04-tf-cpu|run||\n|v8fg/ubuntu:16.04-go1.16-tf-cpu|build||\n|v8fg/ubuntu:16.04-tf-cpu|run||\n\n- more docker images ref: [v8fg/docker-compose-resources](https://github.com/v8fg/docker-compose-resources)\n- official images: [TensorFlow Docker](https://www.tensorflow.org/install/docker)\n\n## Quick run in local\n\n```bash\nwget https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-darwin-x86_64-2.3.0.tar.gz\nexport LIB_TENSORFLOW_FILE=libtensorflow-cpu-darwin-x86_64-2.3.0.tar.gz\ntar -C /usr/local -xzf ${LIB_TENSORFLOW_FILE}\n\n# ll /usr/local/lib/libtensorflow*\n\n-r-xr-xr-x  1 root  wheel   331M Jan  1  2000 /usr/local/lib/libtensorflow.2.3.0.dylib\nlrwxr-xr-x  1 root  wheel    25B Jan  1  2000 /usr/local/lib/libtensorflow.2.dylib -\u003e libtensorflow.2.3.0.dylib\nlrwxr-xr-x  1 root  wheel    21B Jan  1  2000 /usr/local/lib/libtensorflow.dylib -\u003e libtensorflow.2.dylib\n-r-xr-xr-x  1 root  wheel    28M Jan  1  2000 /usr/local/lib/libtensorflow_framework.2.3.0.dylib\nlrwxr-xr-x  1 root  wheel    35B Jan  1  2000 /usr/local/lib/libtensorflow_framework.2.dylib -\u003e libtensorflow_framework.2.3.0.dylib\nlrwxr-xr-x  1 root  wheel    31B Jan  1  2000 /usr/local/lib/libtensorflow_framework.dylib -\u003e libtensorflow_framework.2.dylib\n\n# ll /usr/local/include/tensorflow/*\n\n-r-xr-xr-x  1 root  wheel    77K Jan  1  2000 c_api.h\n-r-xr-xr-x  1 root  wheel    13K Jan  1  2000 c_api_experimental.h\ndrwxr-xr-x  5 root  wheel   160B Jun 11 00:24 eager\n-r-xr-xr-x  1 root  wheel   2.4K Jan  1  2000 tensor_interface.h\n-r-xr-xr-x  1 root  wheel   1.2K Jan  1  2000 tf_attrtype.h\n-r-xr-xr-x  1 root  wheel   2.7K Jan  1  2000 tf_datatype.h\n-r-xr-xr-x  1 root  wheel   1.2K Jan  1  2000 tf_file_statistics.h\n-r-xr-xr-x  1 root  wheel   3.0K Jan  1  2000 tf_status.h\n-r-xr-xr-x  1 root  wheel   7.4K Jan  1  2000 tf_tensor.h\n```\n\n## Tips\n\n- [version incompatible ref](https://github.com/tensorflow/tensorflow/issues/41808)\n    - https://github.com/photoprism/photoprism/pull/775\n- [hack fixed, only ref](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/go/README.md)\n- [saved_model_half_plus_two](https://github.com/tensorflow/serving/blob/master/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two.py)\n    - input, output, tags\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxwi88%2Fgp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxwi88%2Fgp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxwi88%2Fgp/lists"}