Keras: Keras Identity Layer warning

Created on 1 Nov 2016  路  2Comments  路  Source: keras-team/keras

I am trying to create a layer that takes x as is (so that I can merge it with other layers).

I have used the following two methods and they both give the same warning:

/Users/sachin/anaconda/lib/python3.5/site-packages/keras/engine/topology.py:1656: UserWarning: Model inputs must come from a Keras Input layer, they cannot be the output of a previous non-Input layer. Here, a tensor specified as input to "sequential_158_model" was not an Input tensor, it was generated by layer identity_15.
Note that input tensors are instantiated via `tensor = Input(shape)`.
The tensor that caused the issue was: identity_input_10
  str(x.name))

Method 1

x = Sequential()
x.add(Lambda(lambda x: x, input_shape=(x2.shape[1],)))

Method 2

from keras import backend as K
from keras.engine.topology import Layer

class Identity(Layer):
    def __init__(self,output_dim, **kwargs):
        self.output_dim = kwargs['input_shape'][0]
        super(Identity, self).__init__(**kwargs)

    def call(self, x, mask=None):
        return x

    def get_output_shape_for(self, input_shape):
        return (input_shape[0], self.output_dim)

x = Sequential()
x.add(Lambda(lambda x: x, input_shape=(x2.shape[1],)))

My questions are:

  1. Is it safe to proceed with this warning?
  2. Is there a way of getting rid of the warning?
  3. Is the Lambda option preferable simply for readability reasons?
stale

Most helpful comment

Is it safe to proceed with this warning?

Yes.

Is there a way of getting rid of the warning?

x.add(Lambda(lambda x: x + 0, input_shape=(x2.shape[1],)))

Is the Lambda option preferable simply for readability reasons?

Yes.

All 2 comments

Is it safe to proceed with this warning?

Yes.

Is there a way of getting rid of the warning?

x.add(Lambda(lambda x: x + 0, input_shape=(x2.shape[1],)))

Is the Lambda option preferable simply for readability reasons?

Yes.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs, but feel free to re-open it if needed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

snakeztc picture snakeztc  路  3Comments

amityaffliction picture amityaffliction  路  3Comments

harishkrishnav picture harishkrishnav  路  3Comments

fredtcaroli picture fredtcaroli  路  3Comments

KeironO picture KeironO  路  3Comments