【发布时间】:2020-05-27 02:15:48
【问题描述】:
我已经将一个训练有素的 keras 模型转换为 tensorflow.js,我现在正尝试在 react-native 中实现它。模型转换得很好,但是当我尝试加载它时,它说
错误:未知激活:嗖嗖
我知道可以制作自定义层,但我不确定这是否适用于已经训练过的模型。
有什么解决办法吗?
代码: Swift.js
import * as tf from '@tensorflow/tfjs';
class Swish extends tf.layers.Layer {
constructor(config) {
super(config);
this.alpha = config.alpha;
}
call(input) {
return tf.tidy(() => {
const x = input[0]; //tf.getExactlyOneTensor(input);
return tf.sigmoid(x.mul(this.alpha)).mul(x);
});
}
computeOutputShape(inputShape){
return inputShape;
}
static get className() {
return 'swish';
}
}
export default Swish;
加载中:
import Swish from '/Users/alex/Documents/GitHub/TrueSkyApp/src/components/swish.js'
const modelJson = require('/Users/alex/Documents/GitHub/TrueSkyApp/assets/model/model.json');
const modelWeights = require('/Users/alex/Documents/GitHub/TrueSkyApp/assets/model/group1-shard1of1.bin');
class TFtest extends Component {
private model: any
state = {
isModelReady: false
}
async componentDidMount() {
await tf.ready()
this.model = await tf.loadLayersModel(bundleResourceIO(modelJson, modelWeights));
this.setState({
isModelReady: true
})
//Output in Expo console
console.log(this.state.isModelReady)
}
render() {
return (
<View style={styles.container}>
<Text>Model ready? {this.state.isModelReady ? <Text>Yes</Text> : ''}</Text>
</View>
)
}
}
【问题讨论】:
-
请提供代码
-
@Yoskutik 已添加
标签: keras tensorflow.js