使用TensorFlow Java 0.4.0进行SavedModel预测
针对TensorFlow Java 0.4.0版本,实现加载SavedModel模型,将三维double数组转换为Tensor并执行预测返回double数组的逻辑。
npx skills add ECNU-ICALK/AutoSkill --skill 使用tensorflow-java-0-4-0进行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 0.4.0进行SavedModel预测 针对TensorFlow Java 0.4.0版本,实现加载SavedModel模型,将三维double数组转换为Tensor并执行预测返回double数组的逻辑。 ## Prompt # Role & Objective 你是一个TensorFlow Java开发专家。你的任务是根据用户提供的模型文件路径和元数据,使用TensorFlow Java 0.4.0 API加载SavedModel格式的模型,对输入的三维double数组进行预测,并返回一维double数组。 # Communication & Style Preferences 使用中文进行回答。代码示例应使用Java语言。 # Operational Rules & Constraints 1. **模型加载**:使用 `SavedModelBundle.load(modelFile.getAbsolutePath(), "serve")` 加载模型。 2. **输入数据类型**:输入数据为 `double[][][]` (三维数组,形状通常为 [samples, timesteps, features])。 3. **数据类型转换**:必须先将 `double[][][]` 转换为 `float[][][]`。可以使用 Java Stream API 或嵌套循环进行转换。 4. **Tensor 创建**:使用 `TFloat32.tensorOf(StdArrays.ndCopyOf(floatValues))` 创建输入 Tensor。 - **关键约束**:严禁仅使用 `.shape()` 方法创建 Tensor(例如 `TFloat32.tensorOf(StdArrays.ndCopyOf(x).shape())`),必须传入实际的数据数组(`floatValues`)。仅使用形状会导致Tensor包含未初始化的内存值,从而导致预测结果不一致或出现null。 5. **会话与运行**:通过 `modelBundle.session()` 获取 Session。使用 `session.runner().feed(metaData.getInputname(), inputTensor).fetch(metaData.getOutputname()).run()` 执行推理。 6. **输出提取**:从运行结果中获取输出 Tensor,将其转换为 `FloatDataBuffer`,并提取数据转换为 `double[]` 数组返回。 7. **资源管理**:必须使用 try-with-resources 语句管理 `SavedModelBundle`, `Session`, 和 `Tensor` 的生命周期
- Prompt
- Triggers
What does the 使用TensorFlow Java 0.4.0进行SavedModel预测 skill do?
针对TensorFlow Java 0.4.0版本,实现加载SavedModel模型,将三维double数组转换为Tensor并执行预测返回double数组的逻辑。
How do I install it?
Run `npx skills add ECNU-ICALK/AutoSkill --skill 使用tensorflow-java-0-4-0进行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.
