Tfjs: Error: Unknown layer: Functional. This may be due to one of the following reasons

Created on 13 Aug 2020  路  9Comments  路  Source: tensorflow/tfjs

I am new to the TensorFlow and JS.
I was trying to convert the MobileNet V2 model from keras to tensorflow.js
When I try to load model into JS, I get the following error:

`errors.ts:48 Uncaught (in promise) Error: Unknown layer: Functional. This may be due to one of the following reasons:

  1. The layer is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.
  2. The custom layer is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().
    at new e (errors.ts:48)
    at Rp (generic_utils.ts:242)
    at cd (serialization.ts:31)
    at e.fromConfig (models.ts:942)
    at Rp (generic_utils.ts:277)
    at cd (serialization.ts:31)
    at models.ts:300
    at common.ts:14
    at Object.next (common.ts:14)
    at a (common.ts:14)`

I construct my model with a MobileNet V2 pre-trained model and add two layers on top of it. And I convert the model using tensorflowjs_converter with a saved h5 file of the model.
Here is my model summary. The mobilenetv2_1.00_160 with a type of functional and I believed is the cause of the error.

Model: "sequential"
Layer (type)// Output Shape// Param #

#

mobilenetv2_1.00_160 (Functi (None, 5, 5, 1280)// 2257984

#

global_average_pooling2d (Gl (None, 1280) 0

#

dense (Dense) (None, 3755) 4810155

#

Total params: 7,068,139
Trainable params: 7,034,027
Non-trainable params: 34,112

#
converter bug

Most helpful comment

I had an issue like this albeit im using MobileNet not v2. I don't have the specific link, but a stack overflow thread somewhere said to go into the public/model.json folder and ctrl+f "Functional" and replace the word with "Model". worked for me!

All 9 comments

I had an issue like this albeit im using MobileNet not v2. I don't have the specific link, but a stack overflow thread somewhere said to go into the public/model.json folder and ctrl+f "Functional" and replace the word with "Model". worked for me!

Replace the "Functional" with "Model" indeed solve this error. However, it also gives me the new error as following:

Uncaught (in promise) Error: computeMask has not been implemented for Merge yet

@KailiangGu @lospericos I was able to reproduce the same for my model conversion, @pyu10055 can you please assist with this bug ?

@KailiangGu have you tried to convert the HDF5 model to TFJS graph model?

The same issue with Keras MobileNet v1. Replacing the word with "Model" worked for me, thanks!

@pyu10055 i tried to convert with TFJS graph model and no issues , i used the command
!tensorflowjs_converter --input_format keras --output_format=tfjs_graph_model my_sample_model.h5 model/
@KailiangGu @starrabb1t can you please try using TFJS Graph model

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 dyas if no further activity occurs. Thank you.

Are you satisfied with the resolution of your issue?
Yes
No

I had an issue like this albeit im using MobileNet not v2. I don't have the specific link, but a stack overflow thread somewhere said to go into the public/model.json folder and ctrl+f "Functional" and replace the word with "Model". worked for me!

Where is this public/model.json folder located?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

weiji14 picture weiji14  路  3Comments

kylemcdonald picture kylemcdonald  路  3Comments

chrisdonahue picture chrisdonahue  路  3Comments

JasonShin picture JasonShin  路  4Comments

rumschuettel picture rumschuettel  路  3Comments