Moonflower
Moonflower

Reputation: 1

tensorflowjs_converter utility adds suffixes to variable names that cause errors

I am trying to use tensorflowjs_converter to convert a model that I am training in python (using tensorflow) to a JSON layers format so that I can run it on the web. I installed the latest version, and converted a testing model. For this model, it gave me a model.json and .bin file as expected, but when I went to run it on the web, I ran into an error:

Uncaught (in promise) Error: Provided weight data has no target variable: sequential/conv2d/kernel
    at a.value (container.js:643:15)
    at models.js:331:11
    at h (tf.min.js:17:2100)
    at Generator.<anonymous> (tf.min.js:17:3441)
    at Generator.next (tf.min.js:17:2463)
    at u (tf.min.js:17:8324)
    at o (tf.min.js:17:8527)

After inspection, the model.json file had suffixes added to the variable names (ex: conv2d_1 instead of conv2d) which is what I'm assuming is causing the problem.

Code I'm using to generate the .h5 file:

model.save("mnist_model.h5") (can provide all code including training if need be)

Code I'm using to run the model on the web:

const modelPath = "new_model/model.json"

const model = await tf.loadLayersModel(modelPath, strict=false)

Script tag for tensorflowjs:

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs/dist/tf.min.js"></script>

Version info:

python         3.9.13  
tensorflow     2.16.2  
tensorflowjs   4.20.0  
numpy          1.26.4  

After doing some searching (looking up "Error: Provided weight data has no target variable:"), I found this stack overflow question and this github issue that bring up the same problem.

The stack overflow question was not useful since I plan on building a more complicated model that would be extremely tedious to manually (or even write a script to) fix the errors in the model file.

The github issue suggested multiple solutions that all don't work for me like loading the model once (that's what I was already doing), using the command line tool instead of the python code (both ways don't work), adding false to the function call (they are using tf.loadModel which is deprecated while I am using tf.loadLayersModel because that post is like 6 years old), running keras.backend.clear_session() or tf.keras.backend.clear_session() (didn't work), and restarting the session in colab and running each cell once (didn't work).

Upvotes: 0

Views: 57

Answers (0)

Related Questions