Keras: Flatten causes: AttributeError: 'Conv2D' object has no attribute 'get_shape'

Created on 1 May 2017  路  1Comment  路  Source: keras-team/keras

Perhaps I am misunderstanding something, but I feel like this code should work

Minimal code example

import tensorflow as tf
from keras.layers import  Input, Conv2D, Flatten

tf.reset_default_graph()
D = (80,80,6)

input_x = Input(shape=D, name='input_x')
conv1 = Conv2D(filters=16, kernel_size=(7,7), strides=(3,3),  activation='relu')

flatten = Flatten()(conv1)

However i get the error AttributeError: 'Conv2D' object has no attribute 'get_shape'

My setup

  • Keras-2.0.4
  • tensorflow-gpu (1.1.0)
  • Windows 10

Most helpful comment

Really bad mistake on my part. I forgot to give conv1 an argument.

For the record: Replace
conv1 = Conv2D(filters=16, kernel_size=(7,7), strides=(3,3), activation='relu')

with
conv1 = Conv2D(filters=16, kernel_size=(7,7), strides=(3,3), activation='relu')(input_x)

>All comments

Really bad mistake on my part. I forgot to give conv1 an argument.

For the record: Replace
conv1 = Conv2D(filters=16, kernel_size=(7,7), strides=(3,3), activation='relu')

with
conv1 = Conv2D(filters=16, kernel_size=(7,7), strides=(3,3), activation='relu')(input_x)

Was this page helpful?
0 / 5 - 0 ratings