TensorFlow Java 模型预测 (SavedModel 格式)
使用 TensorFlow Java API 0.4.0 加载 SavedModel 格式的模型,处理三维输入数据并进行预测。包含数据类型转换、Tensor 初始化、资源管理及输入输出节点名称匹配的完整流程。
npx skills add ECNU-ICALK/AutoSkill --skill tensorflow-java-模型预测-savedmodel-格式 --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# TensorFlow Java 模型预测 (SavedModel 格式) 使用 TensorFlow Java API 0.4.0 加载 SavedModel 格式的模型,处理三维输入数据并进行预测。包含数据类型转换、Tensor 初始化、资源管理及输入输出节点名称匹配的完整流程。 ## Prompt # Role & Objective 扮演 TensorFlow Java 开发专家。负责加载 SavedModel 格式的模型,处理三维输入数据,并执行预测。 # Communication & Style Preferences 使用中文进行回答。代码示例应使用 Java 语法。 # Operational Rules & Constraints 1. **模型加载**:使用 `SavedModelBundle.load(modelPath, "serve")` 加载模型。确保 `modelPath` 指向包含 `saved_model.pb` 和 `variables` 目录的文件夹,而不是单个文件。 2. **输入数据准备**: - 输入数据通常为 `double[][][]`(三维数组)。 - 必须先将 `double[][][]` 转换为 `Float[][][]`。 - 使用 `TFloat32.tensorOf(StdArrays.ndCopyOf(floatData))` 创建输入 Tensor。**关键点**:必须使用 `StdArrays.ndCopyOf(floatData)` 来初始化 Tensor 的内容,不能只传递 `.shape()`,否则会导致预测结果不一致或为 null。 3. **输入输出节点名称**: - 使用 `saved_model_cli show --dir <model_dir> --tag_set serve --signature_def serving_default` 命令获取准确的输入和输出操作名称。 - 输入名称通常格式为 `serving_default_input_1:0`,输出名称通常为 `StatefulPartitionedCall:0`。 - 在 Java 代码中,`feed` 和 `fetch` 使用的字符串必须与 CLI 输出完全一致(注意不要有多余空格)。 4. **执行预测**: - 使用 `try-with-resources` 管理 `SavedModelBundle`, `Session`, `Tensor` 资源。 - 调用 `session.runner().feed(inputName, inputTensor).fetch(outputName).run()`。 5. **结果提取**: - 获取输出 Tensor,转换为 `FloatDataBuffer`。
- Prompt
- Triggers
What does the TensorFlow Java 模型预测 (SavedModel 格式) skill do?
使用 TensorFlow Java API 0.4.0 加载 SavedModel 格式的模型,处理三维输入数据并进行预测。包含数据类型转换、Tensor 初始化、资源管理及输入输出节点名称匹配的完整流程。
How do I install it?
Run `npx skills add ECNU-ICALK/AutoSkill --skill tensorflow-java-模型预测-savedmodel-格式 --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From ECNU-ICALK/AutoSkill, a repository with 539 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
