from sklearn.model_selection import train_test_split
data,Label = shuffle(M, label, random_state = 2)
labelled_data = [data, Label]
X,Y = [labelled_data[0],labelled_data[1]]
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.4, random_state=4)
x_test, x_validation, y_test, y_validation=train_test_split(X_test, Y_test, test_size=0.5,
random_state=4)
X_train = X_train.reshape((X_train.shape[0],256,256,3))
x_validation = x_validation.reshape((x_validation.shape[0],256,256,3))
x_test =x_test.reshape((x_test.shape[0],256,256,3))
X_train = X_train.astype('float32')
x_validation = x_validation.astype('float32')
x_test = x_test.astype('float32')
X_train = X_train/255
x_validation = x_validation/255
x_test =x_test/255
from keras.utils import np_utils
Y_validation = np_utils.to_categorical(Y_train,8)
y_validation =np_utils.to_categorical(y_validation,8)
y_test =np_utils.to_categorical(y_test,8)
from keras.models import Sequential
from keras.layers import Activation, Dense
model = Sequential()
model.add(Dense(units=256,input_shape=(1000,),activation='relu'))
model.add(Dense(units=64,activation='tanh'))
model.add(Dense(units=8,activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='sgd',
metrics=['categorical_accuracy'])
model.fit(X_train,Y_train,epochs=5,batch_size=32)
model.predict(x_test,batch_size=32)
return model
from keras.layers.convolutional import Convolution2D
model = Sequential()
model.add(convolution2D(filters=(6,3,3),input_shape=(256,256,1),activation='relu'))
from keras.layers.convolutional import MaxPooling2D
model = Sequential()
model.add(MaxPooling2D(pool_size=(2,2),strides=2))
from keras.layers import Dropout
model = Sequential()
model.add(Convolution2D(filters=6, nb_row=3, nb_col=3,subsample=(2,2),
input_shape=(256, 256, 1,), activation='relu', border_mode='same'))
model.add(Dropout(0.1))
model.add(Flatten())
model.add(Dense(8, activation='softmax'))
model= fish_model()
print(model.summary())
history = model.fit(X_train,Y_train,validation_data=(x_validation, y_validation),epochs=5,batch_size=32)
Model: "sequential_42"
Layer (type) Output Shape Param #
dense_67 (Dense) (None, 256) 256256
dense_68 (Dense) (None, 64) 16448
dense_69 (Dense) (None, 8) 520
Total params: 273,224
Trainable params: 273,224
Non-trainable params: 0
None
NameError Traceback (most recent call last)
<ipython-input-131-ab439073340b> in <module>
1 model= fish_model()
2 print(model.summary())
----> 3 history = model.fit(X_train,Y_train,validation_data=(x_validation, y_validation),epochs=5,batch_size=32)
NameError: name 'X_train' is not defined
I have already defined X_train but it shows an error like ir is not defined. When i tried to test the accuracy also i got the same error like x_test is not defined.
X_train
is defined in different session? Are all the lines run in a single session?return model
after your firstmodel.predict
?