Preserve node naming/namespacing
matemijolovic opened this issue · 4 comments
Hello,
Thanks for developing this great tool! I have a question regarding layer/node naming in the converted Keras model.
For the context, I have a usecase where I postprocess the converted graph and I expect the nodes to conform to some custom naming schema (more specifically, to be "namespaced" or to contain some specific keywords). In the current Nobuco setup, module names in the Keras graph are autogenerated and thus not connected to Pytorch module names.
Do you think it would make sense to support some sort of naming/namespacing here?
For 1-1 mappings PT module name could be used for Keras layer name, and for 1-N cases I'd propose using the PT module name as a prefix to the autogenerated name.
If you like this idea, I can offer some help with the implementation. Thanks in advance!
Hi! I'm not sure how to implement that. tf.name_scope
seems to have no effect.
with tf.name_scope('block'):
dense = tf.keras.layers.Dense(10, input_shape=(2, ))
inputs = tf.keras.Input((1, 2))
outputs = dense(inputs)
model = tf.keras.Model(inputs, outputs)
for w in model.weights:
print(w.name)
dense/kernel:0
dense/bias:0
Any ideas?
It's super weird how this works in TF. Usually, name_scope
is not reflected in the actual in-memory node names, but only in the serialized graph (which is what I'm trying to achieve). But if you add tf.saved_model.save(model, 'test-model')
at the end of your snippet and inspect the saved model in Netron, turns out it doesn't work (more specifically, it works only if you instantiate Tensorflow primitives, and Keras layers ignore it).
Then I stumbled upon this: keras-team/tf-keras#269
TL;DR it works if you enable tf.keras.__internal__.apply_name_scope_on_model_declaration(True)
I'm still trying to find the proper place to apply the named scopes in Nobuco.
I managed to hack it out but it's far from ideal: microblink@8b5a142
I managed to hack it out but it's far from ideal: microblink@8b5a142
Hey, could you give me an example script? I tried the patch, and I see no effect on my machine.
My other concern is that disabling decorate_all()
is really not desirable, as it damages Nobuco's tracing capabilities.