Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. from keras.models import Sequential
  2. from keras.layers import Dense, Activation, Conv2D, MaxPooling2D, Flatten
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5. from cnn_utils import *
  6. from scipy import ndimage
  7. import math
  8. from mreDeepLTools import *
  9.  
  10. # Loading the data (signs)
  11. X_train_orig, Y_train_orig, X_test_orig, Y_test_orig, classes = load_dataset()
  12. (training_images, training_labels) = X_train_orig/255, MaxInArray(convert_to_one_hot(Y_train_orig, 6).T)
  13. (test_images, test_labels) = X_test_orig/255, MaxInArray(convert_to_one_hot(Y_test_orig, 6).T)
  14.  
  15.  
  16. # Example of a picture
  17. index = 100
  18. plt.imshow(X_train_orig[index])
  19. print ("y = " + str(np.squeeze(Y_train_orig[:, index])))
  20.  
  21. callbacks = myCallback()
  22. # Create a convolutional -NN model
  23. model = Sequential([
  24. Conv2D(64, (3,3), activation = 'relu', input_shape =(64, 64, 3)),
  25. MaxPooling2D(2, 2),
  26. Conv2D(32, (3,3), activation = 'relu'),
  27. MaxPooling2D(2, 2),
  28. Flatten(),
  29. Dense(128, activation = 'relu'),
  30. Dense(6, activation = 'softmax')
  31. ])
  32. model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
  33. model.summary()
  34.  
  35. # Training the C-NN network
  36. model.fit(training_images, training_labels, epochs=20, callbacks=[callbacks]) # with callbacks
  37. test_loss = model.evaluate(test_images, test_labels)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement