title: AttributeError: 'function' object has no attribute 'predict'. Keras
body: <p>I am working on an RL problem and I created a class to initialize the model and other parameters. The code is as follows:</p>
  
  <pre><code>class Agent:
      def __init__(self, state_size, is_eval=False, model_name=""):
          self.state_size = state_size
          self.action_size = 20 # measurement, CNOT, bit-flip
          self.memory = deque(maxlen=1000)
          self.inventory = []
          self.model_name = model_name
          self.is_eval = is_eval
          self.done = False
  
          self.gamma = 0.95
          self.epsilon = 1.0
          self.epsilon_min = 0.01
          self.epsilon_decay = 0.995
  
  
      def model(self):
          model = Sequential()
          model.add(Dense(units=16, input_dim=self.state_size, activation="relu"))
          model.add(Dense(units=32, activation="relu"))
          model.add(Dense(units=8, activation="relu"))
          model.add(Dense(self.action_size, activation="softmax"))
          model.compile(loss="categorical_crossentropy", optimizer=Adam(lr=0.003))
          return model
  
      def act(self, state):
          options = self.model.predict(state)
          return np.argmax(options[0]), options
  </code></pre>
  
  <p>I want to run it for only one iteration, hence I create an object and I pass a vector of length <code>16</code> like this:</p>
  
  <pre><code>agent = Agent(density.flatten().shape)
  state = density.flatten()
  action, probs = agent.act(state)
  </code></pre>
  
  <p>However, I get the following error:</p>
  
  <pre><code>AttributeError                       Traceback (most recent call last) &lt;ipython-input-14-4f0ff0c40f49&gt; in &lt;module&gt;
  ----&gt; 1 action, probs = agent.act(state)
  
  &lt;ipython-input-10-562aaf040521&gt; in act(self, state)
       39 #             return random.randrange(self.action_size)
       40 #         model = self.model()
  ---&gt; 41         options = self.model.predict(state)
       42         return np.argmax(options[0]), options
       43 
  
  AttributeError: 'function' object has no attribute 'predict'
  </code></pre>
  
  <p>What's the issue? I checked some other people's codes as well, like <a href="https://github.com/Alexander-H-Liu/Policy-Gradient-and-Actor-Critic-Keras/blob/master/agent_dir/agent_pg.py" rel="nofollow noreferrer">this</a> and I think mine is also very similar.</p>
  
  <p>Let me know.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I changed the argument in <code>Dense</code> from <code>input_dim</code> to <code>input_shape</code> and <code>self.model.predict(state)</code> to <code>self.model().predict(state)</code>.</p>
  
  <p>Now when I run the NN for one input data of shape <code>(16,1)</code>, I get the following error:</p>
  
  <blockquote>
    <p>ValueError: Error when checking input: expected dense_1_input to have
    3 dimensions, but got array with shape (16, 1)</p>
  </blockquote>
  
  <p>And when I run it with shape <code>(1,16)</code>, I get the following error:</p>
  
  <blockquote>
    <p>ValueError: Error when checking input: expected dense_1_input to have
    3 dimensions, but got array with shape (1, 16)</p>
  </blockquote>
  
  <p>What should I do in this case?</p>