Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from keras.models import Sequential
- from keras.layers import Dense, Activation, Conv2D, MaxPooling2D, Flatten
- import numpy as np
- import matplotlib.pyplot as plt
- from cnn_utils import *
- from scipy import ndimage
- import math
- from mreDeepLTools import *
- # Loading the data (signs)
- X_train_orig, Y_train_orig, X_test_orig, Y_test_orig, classes = load_dataset()
- (training_images, training_labels) = X_train_orig/255, MaxInArray(convert_to_one_hot(Y_train_orig, 6).T)
- (test_images, test_labels) = X_test_orig/255, MaxInArray(convert_to_one_hot(Y_test_orig, 6).T)
- # Example of a picture
- index = 100
- plt.imshow(X_train_orig[index])
- print ("y = " + str(np.squeeze(Y_train_orig[:, index])))
- callbacks = myCallback()
- # Create a convolutional -NN model
- model = Sequential([
- Conv2D(64, (3,3), activation = 'relu', input_shape =(64, 64, 3)),
- MaxPooling2D(2, 2),
- Conv2D(32, (3,3), activation = 'relu'),
- MaxPooling2D(2, 2),
- Flatten(),
- Dense(128, activation = 'relu'),
- Dense(6, activation = 'softmax')
- ])
- model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
- model.summary()
- # Training the C-NN network
- model.fit(training_images, training_labels, epochs=20, callbacks=[callbacks]) # with callbacks
- test_loss = model.evaluate(test_images, test_labels)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement