Guest User

Untitled

a guest
Jan 17th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. #Importing
  2. from keras.models import Sequential
  3. from keras.layers import Convolution2D
  4. from keras.layers import MaxPooling2D
  5. from keras.layers import Flatten
  6. from keras.layers import Dense
  7.  
  8. #classifier
  9. classifier = Sequential()
  10.  
  11.  
  12. #convolution layer-1
  13. classifier.add(Convolution2D(32, 9, padding='same', input_shape = (128, 128, 3), activation = 'relu' ))
  14. #maxpooling layer-1
  15. classifier.add(MaxPooling2D(pool_size=(2, 2), strides=None))
  16.  
  17. #convolution layer-2
  18. classifier.add(Convolution2D(64, 5, padding='same', activation = 'relu' ))
  19. #maxpooling layer-2
  20. classifier.add(MaxPooling2D(pool_size=(2, 2), strides=None))
  21.  
  22. #convolution layer-3
  23. classifier.add(Convolution2D(64, 3, padding='same', activation = 'relu' ))
  24. #maxpooling layer-3
  25. classifier.add(MaxPooling2D(pool_size=(2, 2), strides=None))
  26.  
  27. classifier.add(Flatten())
  28.  
  29. #full connection
  30. classifier.add(Dense(1028, activation = 'relu'))
  31.  
  32. classifier.add(Dense(4, activation = 'relu'))
  33.  
  34. #compiling
  35. classifier.compile(optimizer='adam',
  36. loss='categorical_crossentropy',
  37. metrics=['accuracy'])
  38.  
  39. #preprocessing
  40. from keras.preprocessing.image import ImageDataGenerator
  41. train_datagen = ImageDataGenerator(
  42. rescale=1./255,
  43. shear_range=0.2,
  44. zoom_range=0.2,
  45. horizontal_flip=True)
  46.  
  47. #loading images
  48. training_set = train_datagen.flow_from_directory(
  49. r'D:ImageDatasetTraining',
  50. target_size=(128, 128),
  51. batch_size=32,
  52. class_mode='categorical')
  53.  
  54. #training begins here
  55. classifier.fit_generator(
  56. training_set,
  57. steps_per_epoch=7594,
  58. epochs=5)
  59. classifier.save('cnn_four_classes.h5')
  60.  
  61. All epochs should be run without error since no image in my training data is .png! I have all .jpg.
Add Comment
Please, Sign In to add comment