How to export a custom model from TensorflowJS to Tensorflow Python

0

I am trying to export a custom model made with TensorflowJS to Tensorflow Python. The main problem is that TF.JS saves two artifacts: "model-js.json" and "model-js.weights.bin"

I tried importing the JSON:

    with open('model-js/model-js.json') as json_file:
        json_config = str(json.loads(json_file.read())["modelTopology"])
    
    json_config=json_config.replace("'","\"")

    new_model = tf.keras.models.model_from_json(json_config)

But I am getting the next error:

~\anaconda3\lib\json\decoder.py in raw_decode(self, s, idx)
    353             obj, end = self.scan_once(s, idx)
    354         except StopIteration as err:
--> 355             raise JSONDecodeError("Expecting value", s, err.value) from None
    356         return obj, end

So, the line 103 in the Json File is the "N" in the "Null" of:

    "config": {
        "batch_input_shape": [
            null,
            128,
            128,
            1
         ],
         "dtype": "float32",
         "sparse": false,
         "name": "conv2d_input"
    }

That is later changed "Null" for "None" when you import the JSON to python.

Why the TensorflowJS model artifacts doesnt fit in Python Tensorflow?

Other thing is that I dont know how to import the weights in the .bin file. There are some other ways to do that? Or there are other kinds of files that can be exported from TF.JS?

Thanks in advance

javascript keras python tensorflow
2021-11-23 10:51:24
1

0

Formats are totally different, that is never going to work like that

And there is no offical way to convert TFJS Graph Model to TF Saved Model as conversion is one-way in the opposite direction

You might have some luck using a 3rd party conversion tool, check out https://github.com/patlevin/tfjs-to-tf

2021-12-13 17:40:32

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................