0

I am having problem to construct my train model. It return 'int' object is not callable.

here is my code:

from __future__ import print_function
import keras

from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
from keras.utils import np_utils
from keras import backend as K
import pandas as pd
import numpy as np


# input image dimensions
img_rows, img_cols = 7, 7

# fix random seed for reproducibility
seed = 7
np.random.seed(seed)

x_train = pd.read_csv('palm_3x3_test.csv')
x_train.drop(['class'],axis=1,inplace=True)
x_train = x_train.as_matrix().reshape(-1, 7, 7)

y_train = pd.read_csv('palm_3x3_test.csv')
y_train = y_train[['class']]


x_test = pd.read_csv('palm_3x3_data.csv')
x_test.drop(['class'],axis=1,inplace=True)
x_test = x_test.as_matrix().reshape(-1, 7, 7)

y_test = pd.read_csv('palm_3x3_data.csv')
y_test = y_test[['class']]

# reshape to be [samples][pixels][width][height]
x_train_final = x_train.reshape(x_train.shape[0], 7, 7,1).astype('float32')
x_test_final = x_test.reshape(x_test.shape[0], 7, 7,1).astype('float32')

# normalize inputs from 0-255 to 0-1
x_train_final = x_train_final / 255
x_test_final = x_test_final / 255

# one hot encode outputs
y_train = np_utils.to_categorical(y_train)
y_test = np_utils.to_categorical(y_test)
num_classes = y_test.shape[1]

input_shape = (img_rows,img_cols , 1)

def baseline_model():
#     create model

    model = Sequential()
    model.add(Conv2D(30 (5,5), border_mode='valid', input_shape=(1,(7,7)), activation='relu'))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Conv2D(15 (3, 3), activation='relu'))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Dropout(0.2))
    model.add(Flatten())
    model.add(Dense(128, activation='relu'))
    model.add(Dense(50, activation='relu'))
    model.add(Dense(num_classes, activation='softmax'))

    # Compile model
    model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
    return model

# build the model
model = baseline_model()
# Fit the model
model.fit(x_train_final,y_train_final, validation_data=(x_test,y_test), nb_epoch=10, batch_size=200,verbose=2)
# Final evaluation of the model
scores = model.evaluate(x_test,y_test, verbose=0)
print("CNN Error: %.2f%%" % (100-scores[1]*100))

Here is the error :

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-42-7f55d9765a8e> in <module>()
     76 
     77 # build the model
---> 78 model = baseline_model()
     79 # Fit the model
     80 model.fit(x_train_final,y_train_final, validation_data=(x_test,y_test), nb_epoch=10, batch_size=200,verbose=2)

<ipython-input-42-7f55d9765a8e> in baseline_model()
     61 
     62     model = Sequential()
---> 63     model.add(Conv2D(30 (5,5), border_mode='valid', input_shape=(1,(7,7)), activation='relu'))
     64     model.add(MaxPooling2D(pool_size=(2, 2)))
     65     model.add(Conv2D(15 (3, 3), activation='relu'))

TypeError: 'int' object is not callable

I've try to search related errors and most of the answer is saying about the variable naming clashing function name. Will the reason of this error is because my naming of variable ?

1 Answer 1

1

You are missing a comma after 30 in

   model.add(Conv2D(30 (5,5), border_mode='valid', input_shape=(1,(7,7)), activation='relu'))

Thats why it is trying to call 30 with parameters 5,5.

2
  • Thanks for the help ! I am having new error, do u mind helping me as well ? TypeError: int() argument must be a string or a number, not 'tuple'
    – soapho
    Commented Apr 17, 2017 at 8:21
  • That is just basic debugging. The input_shape on the same line will not accept (7,7) tuple. Also If you look further, there is a same typo with missing comma after 15 in model.add(Conv2D(15 (3, 3), activation='relu'))
    – matusko
    Commented Apr 17, 2017 at 9:11

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.