Python utilities for reading, writing, and validating TensorFlow Serving models.config
Project description
TensorFlow Serving Config Utilities
Python utilities for reading, writing, and validating TensorFlow Serving models.config files. This project provides a convenient way to programmatically manage your TensorFlow Serving model configurations using Python.
描述
该项目旨在提供一套 Python 工具,用于处理 TensorFlow Serving 的 models.config 文件。通过使用 Protobuf 定义,您可以轻松地创建、修改和验证模型服务器配置,从而实现自动化部署和管理 TensorFlow Serving 实例。
特性
- 生成
models.config: 轻松创建符合 TensorFlow Serving 规范的models.config文件。 - 读取和解析: 从现有
models.config文件中读取并解析配置,方便程序化访问。 - 验证: 利用 Protobuf 的结构化特性,确保配置文件的格式正确性。
- 模块化和可重用: 代码遵循面向对象设计原则,易于集成和扩展。
安装
先决条件
- Python 3.8 或更高版本
使用 pip 安装
pip install tensorflow_serving_config
从源代码安装
- 克隆仓库:
git clone https://github.com/colorblank/tensorflow_serving_config.git cd tensorflow_serving_config
- 安装依赖:
pip install -r requirements.txt
- 安装项目:
python setup.py install
依赖
本项目依赖以下库:
protobuf>=6.31.1grpcio>=1.73.1grpcio-tools==1.73.1(用于生成 Protobuf 代码)wheel
使用示例
以下是一个简单的示例,展示如何使用此库生成并读取一个 models.config 文件:
from google.protobuf import text_format
from tensorflow_serving.config import model_server_config_pb2
import os
# --- 生成一个示例 models.config 文件 ---
sample_config = model_server_config_pb2.ModelServerConfig()
# 添加第一个模型配置
model1 = sample_config.model_config_list.config.add()
model1.name = "example_model_a"
model1.base_path = "/var/lib/tensorflow_serving/models/example_model_a"
model1.model_platform = "tensorflow"
model1.model_version_policy.specific.versions.append(1)
model1.model_version_policy.specific.versions.append(2)
# 添加第二个模型配置
model2 = sample_config.model_config_list.config.add()
model2.name = "example_model_b"
model2.base_path = "/var/lib/tensorflow_serving/models/example_model_b"
model2.model_platform = "tensorflow"
config_file_path = "models.config"
with open(config_file_path, "w") as f:
f.write(text_format.MessageToString(sample_config))
print(f"示例配置文件 '{config_file_path}' 生成成功!")
# --- 读取并解析 models.config 文件 ---
model_server_config = model_server_config_pb2.ModelServerConfig()
try:
with open(config_file_path, "r") as f:
config_content = f.read()
text_format.Parse(config_content, model_server_config)
print("\n配置文件 'models.config' 读取并解析成功!")
print("\n--- 读取到的模型配置 ---")
for model_config in model_server_config.model_config_list.config:
print(f"模型名称: {model_config.name}")
print(f"模型路径: {model_config.base_path}")
print(f"模型平台: {model_config.model_platform}")
if model_config.model_version_policy.HasField("specific"):
versions = list(model_config.model_version_policy.specific.versions)
print(f"版本策略: {versions}")
else:
print("版本策略: 默认 (Latest)")
print("-" * 20)
except FileNotFoundError:
print(f"错误: 找不到配置文件 '{config_file_path}'")
except text_format.ParseError as e:
print(f"错误: 解析配置文件失败,请检查文件格式是否正确。错误详情: {e}")
# 清理生成的示例文件
if os.path.exists(config_file_path):
os.remove(config_file_path)
print(f"\n清理: 示例配置文件 '{config_file_path}' 已删除。")
许可证
本项目采用 Apache-2.0 许可证。详情请参阅 LICENSE 文件。
联系方式
- 作者: Colorblank
- 邮箱: colorblank@example.com
- GitHub: https://github.com/colorblank/tensorflow_serving_config
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tensorflow_serving_config-0.0.2.tar.gz.
File metadata
- Download URL: tensorflow_serving_config-0.0.2.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
745761ec16c944fb1c4ddb0f0563a303ed9f64c55a15b0255615fd513917fde7
|
|
| MD5 |
f39a62f165122fe049a26e2a608b89be
|
|
| BLAKE2b-256 |
01804ab8499f265cf96001235fa29bedc18d1266486b029f5d09892fa4265665
|
Provenance
The following attestation bundles were made for tensorflow_serving_config-0.0.2.tar.gz:
Publisher:
python-package.yml on colorblank/tensorflow_serving_config
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tensorflow_serving_config-0.0.2.tar.gz -
Subject digest:
745761ec16c944fb1c4ddb0f0563a303ed9f64c55a15b0255615fd513917fde7 - Sigstore transparency entry: 307702571
- Sigstore integration time:
-
Permalink:
colorblank/tensorflow_serving_config@14239817ad01a2d73f930cdab7b37807f25179ed -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/colorblank
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@14239817ad01a2d73f930cdab7b37807f25179ed -
Trigger Event:
release
-
Statement type:
File details
Details for the file tensorflow_serving_config-0.0.2-py3-none-any.whl.
File metadata
- Download URL: tensorflow_serving_config-0.0.2-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17d734e607c930e6f1c875895d38f360269b4e3e06613592d5481303fac8b0a0
|
|
| MD5 |
0ab800e42c34c166db4e712f73773641
|
|
| BLAKE2b-256 |
167ef8c627bbf33257e5d843c3554d92d799e2880bd29f9ae812236b6c22e81e
|
Provenance
The following attestation bundles were made for tensorflow_serving_config-0.0.2-py3-none-any.whl:
Publisher:
python-package.yml on colorblank/tensorflow_serving_config
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tensorflow_serving_config-0.0.2-py3-none-any.whl -
Subject digest:
17d734e607c930e6f1c875895d38f360269b4e3e06613592d5481303fac8b0a0 - Sigstore transparency entry: 307702581
- Sigstore integration time:
-
Permalink:
colorblank/tensorflow_serving_config@14239817ad01a2d73f930cdab7b37807f25179ed -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/colorblank
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@14239817ad01a2d73f930cdab7b37807f25179ed -
Trigger Event:
release
-
Statement type: