Invalid scope names when reimporting a Keras model
theHamsta opened this issue · 1 comments
theHamsta commented
When I try to re-import a Keras model. I get an error about invalid scope names in Tensorflow. The mentioned scope had a :
in it's name.
model = tf.keras.Sequential([
hub.KerasLayer(
"https://tfhub.dev/google/imagenet/resnet_v2_50/classification/5", dtype=tf.float32)
])
model.build([None, 224, 224, 3])
tf_net = convert_variables_to_constants_v2(
tf.function(model, jit_compile=args.jit_compile == 'true').get_concrete_function(
tf.TensorSpec(model.inputs[0].shape, dtype)))
tf_net.save('some path')
# then convert to onnx with tensorflow-onnx2 CLI
I could solve the bug by replacing all :
by _
for keras_names
in this line
onnx2keras/onnx2keras/converter.py
Line 182 in 45c81f2
[k.replace(':', '_') for k in keras_names]
if isinstance(keras_names, list) else keras_names.replace(':', '_')
I'm now wondering whether this is a proper fix or just a work around. Maybe there could be a validation/coercion step where all invalid Tensorflow names could be replaced by fill character.
AlexandreBourrieau commented
Same problem thanks for your fix !