tf-explain icon indicating copy to clipboard operation
tf-explain copied to clipboard

Subclassing API

Open RaphaelMeudec opened this issue 5 years ago • 8 comments

The current version of tf-explain does not support subclassing API because of the way subgraphs are created.

See: https://stackoverflow.com/questions/52826134/keras-model-subclassing-examples

RaphaelMeudec avatar Jul 30 '19 13:07 RaphaelMeudec

Hi! Thanks of all thank you for this great library! Is this functionality high on your priority list?

dtransposed avatar Aug 05 '19 10:08 dtransposed

Hi! I'm on holiday for a few days, but plan to tackle this as soon as I get back. There's an open issue on Tensorflow to help fix this

RaphaelMeudec avatar Aug 05 '19 10:08 RaphaelMeudec

Excellent, thank you!

dtransposed avatar Aug 05 '19 10:08 dtransposed

@dtransposed looks like getting support for subclassing API is going to be harder than expected: https://github.com/tensorflow/tensorflow/issues/30955#issuecomment-520291616

RaphaelMeudec avatar Aug 12 '19 07:08 RaphaelMeudec

Yes, I have tried to hack your code to use it with my models built using subclassing API and failed. It's a pity there is no way to "translate" subclassing model into functional one so far...

dtransposed avatar Aug 12 '19 07:08 dtransposed

@RaphaelMeudec is there any update on this issue? A workaround is also fine ...

leeor-langer avatar Nov 27 '19 07:11 leeor-langer

@leeor-langer No fix as of today. Best option is to define subclass layer with strict minimum operations and use it in a sequential/functional model, instead of defining the whole model in a subclass layer.

For example:

class MySpecialPadding(tf.keras.Layer):
  def call(self, inputs, *args, **kwargs):
     x = tf.pad(inputs, my_padding)
     return x

model = tf.keras.Model([
  tf.keras.layers.Conv2D(..),
  MySpecialPadding(),
])

RaphaelMeudec avatar Dec 02 '19 11:12 RaphaelMeudec

is there an update on the problem ?

ramshi236 avatar Aug 12 '21 08:08 ramshi236