Search code examples
keraskeras-layer

Error while applying TimeDistributed to InceptionResnetV2 in Keras


x=Input(shape=(10,299,299,3))
y=TimeDistributed(InceptionResnetV2(include_top=False,weights='./weights.h5'))(x)

This is the error that I am getting

Failed to convert object of type <type 'tuple'> to Tensor. Contents: (-1, 10, None, None, 1536). Consider casting elements to a supported type.

Solution

  • I have no idea why we're getting this error, but it's possible to use this workaround:

    x=Input(shape=(10,299,299,3))
    
    #join the steps dimension with the samples dimension, the model won't see a difference    
    y=Lambda(lambda x: K.reshape(x,(-1,299,299,3)))(x)
    
    #use a regular inception model
    y = InceptionResNetV2(include_top=False,weights=None)(y)
    
    #bring back the hidden steps dimension
    y = Lambda(lambda x: K.reshape(x,(-1,10,8,8,1536)))(y)