Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. model = Sequential()
  2. dim = 28
  3. nclasses = 10
  4.  
  5. model.add(Conv2D(filters=32, kernel_size=(5,5), padding='same', activation='relu', input_shape=(dim,dim,1)))
  6. model.add(Conv2D(filters=32, kernel_size=(5,5), padding='same', activation='relu',))
  7.  
  8. model.add(MaxPool2D(pool_size=(2,2), strides=(2,2)))
  9. model.add(Dropout(0.2))
  10. model.add(Conv2D(filters=64, kernel_size=(5,5), padding='same', activation='relu'))
  11.  
  12. model.add(Conv2D(filters=64, kernel_size=(5,5), padding='same', activation='relu'))
  13. model.add(MaxPool2D(pool_size=(2,2), strides=(2,2)))
  14. model.add(Dropout(0.2))
  15. model.add(Flatten())
  16.  
  17. model.add(Dense(120, activation='relu'))
  18. model.add(Dense(84, activation='relu'))
  19. model.add(Dense(nclasses, activation='softmax'))
  20.  
  21. opt = SGD(lr=0.001)
  22. reduce_lr = ReduceLROnPlateau(monitor='val_acc', factor=0.9, patience=25, min_lr=0.000001, verbose=1)
  23. model.compile(optimizer=opt, loss="categorical_crossentropy", metrics=["accuracy"])
  24. history = model.fit(x=x_train,
  25. y=y_train,
  26. batch_size=10,
  27. epochs=1,
  28. verbose=1,
  29. callbacks=[reduce_lr],
  30. validation_data=(x_val,y_val),
  31. shuffle=True)
  32.  
  33. plt.plot(history.history['val_acc'])
  34. plt.plot(history.history['lr'])
  35. plt.title('Plot of overall accuracy to larning rate for SGD optimizer')
  36. plt.ylabel('accuracy')
  37. plt.xlabel('learning rate')
  38. plt.legend(['x_train', 'x_test'], loc='upper right')
  39. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement