4
$\begingroup$

I am using following code:

input_shape = (75, 75, 3)
x = Input(input_shape)
model = BatchNormalization(axis = 3)(x)

Above code works all right. However, following code does not work:

from keras.models import Sequential
input_shape = (64,64,3)
model = Sequential()
model = model.add(InputLayer(input_shape=input_shape))
model = model.add(BatchNormalization(axis = 3))

But at last line, I get error:

AttributeError: 'NoneType' object has no attribute 'add'

If I change to:

model = model.add(Input(input_shape))

I get following error:

TypeError: The added layer must be an instance of class Layer. 
Found: Tensor("input_1:0", shape=(?, 64, 64, 3), dtype=float32)

Where is the problem and how can it be solved?

(PS: If you find this question to be interesting/important, please upvote it.)

$\endgroup$
1
  • $\begingroup$ I feel you. I am watching a tutorial by Janis Seeman, that probably is deprecated. In dhtis tutorial he uses the same commands. I have to work on my master thesis and this whole ....... does not work. Iam kind of frustrated as f... They do not knwo Sequential() anymore, and most of those commands are "deprecated". That is what the error message contains. $\endgroup$ Commented Oct 8, 2019 at 4:29

1 Answer 1

6
$\begingroup$
from keras.models import Sequential
from keras.layers import InputLayer

model = Sequential()
model.add(InputLayer(input_shape))
model.add(BatchNormalization(axis = 3))

This should work. The first error was because the model was getting reassigned. The second error was because 'Input' is a function of 'layers' class but not a class, 'InputLayer' is a class.

$\endgroup$
2
  • $\begingroup$ No! This does not work. I have already put a statement at beginning: from keras.models import Sequential, Model. Replacing that with from keras import models and using models.Sequential() also gives same error. I am editing my question above to add this statement. $\endgroup$
    – rnso
    Commented Sep 29, 2018 at 1:48
  • $\begingroup$ Yes, it has to be just model.add(... and not model = model.add(... $\endgroup$
    – rnso
    Commented Sep 29, 2018 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.