Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import keras
- from keras import backend as K
- import os
- from keras.layers.advanced_activations import LeakyReLU
- from __future__ import print_function
- from keras.datasets import mnist
- import matplotlib.pylab as plt
- from importlib import reload
- def set_keras_backend(backend):
- if K.backend() != backend:
- os.environ['KERAS_BACKEND'] = backend
- reload(K)
- assert K.backend() == backend
- set_keras_backend("tensorflow")
- DATA = joblib.load(open('Data.sav', 'rb'))
- LABEL = joblib.load(open('Lable.sav', 'rb'))
- print(DATA.shape)
- print(LABEL.shape)
- print(tf.__version__)
- X_train, X_test, y_train, y_test = train_test_split(DATA, LABEL, test_size=0.30, random_state=45)
- print(X_train.shape)
- print(X_test.shape)
- print(y_train.shape)
- print(y_test.shape)
- print(X_train[0])
- X_train = np.reshape(X_train,(X_train.shape[0],200,180,1))
- X_test = np.reshape(X_test,(X_test.shape[0],200,180,1))
- # convert the data from binary to float
- X_train = X_train.astype('float32')
- X_test = X_test.astype('float32')
- X_train /= 255
- X_test /= 255
- model = Sequential()
- model.add(Conv2D(32, kernel_size=(5,5), strides=(1, 1),
- activation='relu',
- input_shape=([200,180,1])))
- model.add(LeakyReLU(alpha=0.1))
- model.add(MaxPooling2D(pool_size=(2,2)))
- model.add(Conv2D(64,(5,5), activation='relu'))
- model.add(LeakyReLU(alpha=0.1))
- model.add(MaxPooling2D(pool_size=(2,2)))
- model.add(Conv2D(128,(5,5), activation='relu'))
- model.add(LeakyReLU(alpha=0.1))
- model.add(MaxPooling2D(pool_size=(2,2)))
- model.add(Dropout(0.30))
- model.add(Flatten())
- model.add(Dense(1000, activation='relu'))
- model.add(Dropout(0.5))
- model.add(Dense(72, activation='softmax'))
- # When we compile the model, we declare the loss function and the optimizer
- model.compile(loss=keras.losses.categorical_crossentropy,
- optimizer=keras.optimizers.Adam(),
- metrics=['accuracy'])
- # Train the model
- hist = model.fit(X_train, Y_train,batch_size=32,epochs=12, verbose=1, validation_data=(X_test, Y_test))
- score = model.evaluate(X_test, Y_test, verbose=0)
- print("%s: %.2f%%" % ('Accuracy', score[1]*100))
Add Comment
Please, Sign In to add comment