Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading Model from Keras #1718

Closed
wgcv opened this issue Jul 3, 2019 · 3 comments
Closed

Loading Model from Keras #1718

wgcv opened this issue Jul 3, 2019 · 3 comments
Assignees
Labels
type:bug Something isn't working

Comments

@wgcv
Copy link

wgcv commented Jul 3, 2019

TensorFlow.js version

1.1.2

Browser version

Chrome 75.0.3770.100 (Official Build) (64-bit)

Tensorflow

Tensorflow 2.0 Beta

Describe the problem or feature request

I export my trained model (Work great with Tensorflow 2.0 and Keras)

Model: "sequential_1"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_4 (Conv2D)            (None, 28, 28, 32)        160       
_________________________________________________________________
leaky_re_lu (LeakyReLU)      (None, 28, 28, 32)        0         
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 14, 14, 32)        0         
_________________________________________________________________
dropout_3 (Dropout)          (None, 14, 14, 32)        0         
_________________________________________________________________
conv2d_5 (Conv2D)            (None, 13, 13, 64)        8256      
_________________________________________________________________
leaky_re_lu_1 (LeakyReLU)    (None, 13, 13, 64)        0         
_________________________________________________________________
dropout_4 (Dropout)          (None, 13, 13, 64)        0         
_________________________________________________________________
max_pooling2d_3 (MaxPooling2 (None, 6, 6, 64)          0         
_________________________________________________________________
dropout_5 (Dropout)          (None, 6, 6, 64)          0         
_________________________________________________________________
conv2d_6 (Conv2D)            (None, 5, 5, 196)         50372     
_________________________________________________________________
leaky_re_lu_2 (LeakyReLU)    (None, 5, 5, 196)         0         
_________________________________________________________________
dropout_6 (Dropout)          (None, 5, 5, 196)         0         
_________________________________________________________________
max_pooling2d_4 (MaxPooling2 (None, 2, 2, 196)         0         
_________________________________________________________________
dropout_7 (Dropout)          (None, 2, 2, 196)         0         
_________________________________________________________________
global_max_pooling2d (Global (None, 196)               0         
_________________________________________________________________
flatten_1 (Flatten)          (None, 196)               0         
_________________________________________________________________
dense_2 (Dense)              (None, 1024)              201728    
_________________________________________________________________
leaky_re_lu_3 (LeakyReLU)    (None, 1024)              0         
_________________________________________________________________
dropout_8 (Dropout)          (None, 1024)              0         
_________________________________________________________________
dense_3 (Dense)              (None, 62)                63550     
=================================================================
Total params: 324,066
Trainable params: 324,066
Non-trainable params: 0
________________________

with

import tensorflowjs as tfjs
tfjs.converters.save_keras_model(model, "./js")

but when i load with

  <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.1.2/dist/tf.min.js"></script>
<script type="text/javascript">
        const model = await tf.loadLayersModel('model/model.json');
</script>

I get this error

Uncaught (in promise) Error: Input 0 is incompatible with layer flatten_1: expected min_ndim=3, found ndim=2. Error: Input 0 is incompatible with layer flatten_1: expected min_ndim=3, found ndim=2.
    at new e (errors.ts:48)
    at e.assertInputCompatibility (topology.ts:789)
    at topology.ts:984
    at Yp (common.ts:43)
    at e.apply (topology.ts:977)
    at e.add (models.ts:499)
    at e.fromConfig (models.ts:1020)
    at Cp (generic_utils.ts:277)
    at ud (serialization.ts:31)
    at models.ts:299
e @ errors.ts:48
e.assertInputCompatibility @ topology.ts:789
(anonymous) @ topology.ts:984
Yp @ common.ts:43
e.apply @ topology.ts:977
e.add @ models.ts:499
e.fromConfig @ models.ts:1020
Cp @ generic_utils.ts:277
ud @ serialization.ts:31
(anonymous) @ models.ts:299
(anonymous) @ common.ts:14
(anonymous) @ common.ts:14
o @ common.ts:14
errors.ts:48 Uncaught (in promise) Error: Input 0 is incompatible with layer flatten_1: expected min_ndim=3, found ndim=2.
    at new e (errors.ts:48)
    at e.assertInputCompatibility (topology.ts:789)
    at topology.ts:984
    at Yp (common.ts:43)
    at e.apply (topology.ts:977)
    at e.add (models.ts:499)
    at e.fromConfig (models.ts:1020)
    at Cp (generic_utils.ts:277)
    at ud (serialization.ts:31)
    at models.ts:299
e @ errors.ts:48
e.assertInputCompatibility @ topology.ts:789
(anonymous) @ topology.ts:984
Yp @ common.ts:43
e.apply @ topology.ts:977
e.add @ models.ts:499
e.fromConfig @ models.ts:1020
Cp @ generic_utils.ts:277
ud @ serialization.ts:31
(anonymous) @ models.ts:299
(anonymous) @ common.ts:14
(anonymous) @ common.ts:14
o @ common.ts:14

Code to reproduce the bug / link to feature request

@wgcv
Copy link
Author

wgcv commented Jul 3, 2019

I solved the problem removing this lines:

                    {
                        "class_name": "Flatten",
                        "config": {
                            "name": "flatten_1",
                            "trainable": true,
                            "dtype": "float32",
                            "data_format": "channels_last"
                        }

But i don't think that this is the best solution, this is a error of the export tool or in TF.Js?

@tafsiri tafsiri added the type:bug Something isn't working label Jul 3, 2019
@tafsiri
Copy link
Contributor

tafsiri commented Jul 3, 2019

cc @caisq @pyu10055 could you take a look.

@rthadur
Copy link
Contributor

rthadur commented Feb 5, 2020

Automatically closing due to lack of recent activity. Please update the issue when new information becomes available, and we will reopen the issue. Thanks!

@rthadur rthadur closed this as completed Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants