0

The function used to build the model:

def CancerModel(input_shape):   

    X_input = Input(input_shape)

    X = ZeroPadding2D((2, 2))(X_input)

    X = Conv2D(8, (5, 5), strides = (1, 1), name = 'conv')(X)
    X = BatchNormalization(axis = 3, name = 'bn1')(X)
    X = Activation('relu')(X)

    X = MaxPooling2D((2, 2), name='max_pool')(X)

    X = Conv2D(16, (5, 5), strides = (1, 1), name = 'conv2')(X)
    X = BatchNormalization(axis = 3, name = 'bn2')(X)
    X = Activation('relu')(X)

    X = MaxPooling2D((2, 2), name='max_pool2')(X)

    X = Flatten()(X)
    X = Dense(120, activation='relu', name='fc1')(X)
    X = Dense(84, activation='relu', name='fc2')(X)
    X = Dense(7, activation='softmax', name='output')(X)

    model = Model(inputs = X_input, outputs = output, name='CancerModel')

    return model

The model was attempted to be created using:

cancerModel = CancerModel(X_train.shape[1:])

However, I am getting an error saying that the attribute can't be set. I have also attached a screenshot of the error I'm getting. Any help would be appreciated.

Screenshot of bug

1
  • 2
    Can you share the code of your model? And please no screenshots, write the code here. Commented Jan 12, 2021 at 7:59

1 Answer 1

1

I found no error in your code. It may be problem in your training data shape or Keras version issue (My Keras version 2.4.3).

def CancerModel(input_shape):   

    X_input = Input(input_shape)

    X = ZeroPadding2D((2, 2))(X_input)

    X = Conv2D(8, (5, 5), strides = (1, 1), name = 'conv')(X)
    X = BatchNormalization(axis = 3, name = 'bn1')(X)
    X = Activation('relu')(X)

    X = MaxPooling2D((2, 2), name='max_pool')(X)

    X = Conv2D(16, (5, 5), strides = (1, 1), name = 'conv2')(X)
    X = BatchNormalization(axis = 3, name = 'bn2')(X)
    X = Activation('relu')(X)

    X = MaxPooling2D((2, 2), name='max_pool2')(X)

    X = Flatten()(X)
    X = Dense(120, activation='relu', name='fc1')(X)
    X = Dense(84, activation='relu', name='fc2')(X)
    X = Dense(7, activation='softmax', name='output')(X)

    model = Model(inputs = X_input, outputs = X, name='CancerModel')

    return model


CancerModel((224,224,3)).summary() #It works fine

Also works fine using

CancerModel(np.ones((5,120,120,3)).shape[1:]).summary()
Sign up to request clarification or add additional context in comments.

1 Comment

It worked fine after reinstalling Tensorflow and Keras. thanks.

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.