Guest User

Untitled

a guest
Dec 15th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. # Define Top2 and Top3 Accuracy
  2. from keras.metrics import categorical_accuracy, top_k_categorical_accuracy
  3.  
  4. def top_3_accuracy(y_true, y_pred):
  5. return top_k_categorical_accuracy(y_true, y_pred, k=3)
  6.  
  7. def top_2_accuracy(y_true, y_pred):
  8. return top_k_categorical_accuracy(y_true, y_pred, k=2)
  9.  
  10. # Compile the model
  11. model.compile(Adam(lr=0.01), loss='categorical_crossentropy', metrics=[categorical_accuracy, top_2_accuracy, top_3_accuracy])
  12.  
  13. # Add weights to make the model more sensitive to melanoma
  14. class_weights={
  15. 0: 1.0, # akiec
  16. 1: 1.0, # bcc
  17. 2: 1.0, # bkl
  18. 3: 1.0, # df
  19. 4: 3.0, # mel
  20. 5: 1.0, # nv
  21. 6: 1.0, # vasc
  22. }
Add Comment
Please, Sign In to add comment