首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未知激活: swish

未知激活: swish
EN

Stack Overflow用户
提问于 2021-05-25 08:53:25
回答 1查看 149关注 0票数 4

我喜欢在中加载ML模型。

我使用此命令将Keras模型model.h5转换为model.json和二进制权重文件。

代码语言:javascript
复制
tensorflowjs_converter --input_format=keras /tmp/model.h5 /tmp/tfjs_model

App代码

代码语言:javascript
复制
import * as tf from "@tensorflow/tfjs"
import { bundleResourceIO } from "@tensorflow/tfjs-react-native"

const modelJson = require("model.json")
const modelWeights = require("weights.bin")

await tf.ready().then(async () => {
  try {
    const modelBundle = bundleResourceIO(modelJson, modelWeights)
    console.log("modelBundle", modelBundle)
    // Output
    /**
     * {"modelJson": {"convertedBy": "TensorFlow.js Converter v3.6.0", "format": "layers-model",
     * "generatedBy": "keras v2.4.0", "modelTopology": {"backend": "tensorflow",
     * "keras_version": "2.4.0", "model_config": [Object]}, "weightsManifest": [[Object]]},
     * "modelWeightsId": 4}
     */
    await tf
      .loadLayersModel(bundleResourceIO(modelJson, modelWeights))
      .then((layersModel) => console.log("layersModel", layersModel))
    // Output
    /**
     * [Error: Unknown activation: swish. This may be due to one of the following reasons: 
     * 1. The activation is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.
     * 2. The custom activation is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().]
    */
    await tf
      .loadGraphModel(bundleResourceIO(modelJson, modelWeights))
      .then((graphModel) => console.log("graphModel", graphModel))
    // Output
    /**
     * [TypeError: undefined is not an object (evaluating 'graph.versions.producer')]
     */
  } catch (error) {
    console.log("error", error)
  }
})

我尝试将model.json中的model.json中的Functional更改为Model,结果仍然相同。

包版本:

代码语言:javascript
复制
"@tensorflow/tfjs": "3.4.0",
"@tensorflow/tfjs-react-native": "^0.5.0",
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-25 15:19:03

错误很简单,您使用的是未定义的激活swish。你可以看看这些答案,herethere

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67684738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档