1

On my Keras(1.2.2), I tried to run code with a function Input,

inputs = keras.Input(shape=(img_size[0], img_size[1], 1))

But the following error returned

AttributeError: module 'keras' has no attribute 'Input'

Can someone help me?

3
  • How do you import keras? Is it tf.keras installed with Tensorflow, or the separate keras package? (tf.keras.Input would work) Commented Jul 27, 2020 at 13:28
  • It is a separate keras package Commented Jul 27, 2020 at 13:31
  • Then see M Z's answer :) Commented Jul 27, 2020 at 13:33

2 Answers 2

3

Use keras.layers.Input. All layers are under the submodule keras.layers. Like:

inputs = keras.layers.Input(shape=(img_size[0], img_size[1], 1))

Another common thing to do is to say

from keras.layers import Input

This way later in your code it doesn't get too messy when you try to add a bunch of layers to your model:

inputs = Input(shape=(img_size[0], img_size[1], 1))
Sign up to request clarification or add additional context in comments.

Comments

-1

try it from tensorflow.keras.layers import InputLayer or from tensorflow.keras.layers import * should work

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.