tensorflowjs_converter可以与使用功能性API制作的Keras模型一起使用吗?

时间:2019-03-22 16:28:16

标签: python tensorflow keras tensorflow.js

我正在尝试将在Python中用tf.keras制作的模型转换为tensorflow.js格式,以便在Node.js中使用。这是我的软件包版本:

tensorflowjs: 1.0.1
Keras: 2.2.4
tf-nightly-2.0-preview: 2.0.0.dev20190321 (from pip install tensorflowjs)

这是我的顺序模型,也使用功能性API进行了重新构建:

# Sequential API
model = tf.keras.Sequential()
model.add(layers.Dense(128, activation='relu', input_shape=(22050,))
model.add(layers.Dense(9, activation='softmax'))

# Functional API
inputs = tf.keras.Input(shape=(22050,))
x = layers.Dense(128, activation='relu')(inputs)
logits = layers.Dense(9, activation='softmax')(x)

当我使用tfjs_layers_model将顺序模型转换为tensorflowjs_converter时,使用tensorflowjs可以很好地加载。当我对功能模型执行相同的操作时,会出现格式错误的模型配置错误:

Error: Improperly formatted model config for layer {"_callHook":null,"_addedWeightNames":[],"_stateful":false,"id":1,"activityRegularizer":null,"inputSpec":[{"minNDim":2}],"supportsMasking":true,"_trainableWeights":[],"_nonTrainableWeights":[],"_losses":[],"_updates":[],"_built":false,"inboundNodes":[],"outboundNodes":[],"name":"dense_38","trainable_":true,"updatable":true,"initialWeights":null,"_refCount":null,"fastWeightInitDuringBuild":true,"activation":{},"useBias":true,"kernel":null,"bias":null,"DEFAULT_KERNEL_INITIALIZER":"glorotNormal","DEFAULT_BIAS_INITIALIZER":"zeros","units":128,"kernelInitializer":{"scale":1,"mode":"fanAvg","distribution":"uniform","seed":null},"biasInitializer":{},"kernelConstraint":null,"biasConstraint":null,"kernelRegularizer":null,"biasRegularizer":null}: "input_26"

我也尝试导出为tfjs_graph_model,但是tensorflowjs_converter不允许这样做。我希望模型最终具有多个输出,这就是为什么我想使用功能性API而不是顺序性API的原因。

0 个答案:

没有答案