Unknown activation: swish

Viewed 135

I like to load a ML Model in a React-Native App.
I converted Keras model model.h5 to model.json and binary weight files using this command.

tensorflowjs_converter --input_format=keras /tmp/model.h5 /tmp/tfjs_model

App Code

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)
  }
})

I tried changing modelTopology.model_config.class_name in model.json from Functional to Model still the same result.

Packages Versions:

"@tensorflow/tfjs": "3.4.0",
"@tensorflow/tfjs-react-native": "^0.5.0",
1 Answers

The error is straightforward, you are using an activation swish that is not defined. You can have a look at these answers here and there

Related