Guest User

Untitled

a guest
Nov 19th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. classifier.add(Dense(units = 128, activation = 'relu'))
  2. classifier.add(Dense(units = 4, activation = 'softmax'))
  3.  
  4. # Compiling the CNN
  5. classifier.compile(optimizer = 'adam', loss =
  6. 'categorical_crossentropy', metrics = ['accuracy'])
  7.  
  8. # Part 2 - Fitting the CNN to the images
  9. from keras.preprocessing.image import ImageDataGenerator
  10. train_datagen = ImageDataGenerator(rescale = 1./255,
  11. shear_range = 0.2,
  12. zoom_range = 0.2,
  13. horizontal_flip = True)
  14. test_datagen = ImageDataGenerator(rescale = 1./255)
  15. training_set = train_datagen.flow_from_directory('dataset/dota_training_set',
  16. target_size = (64, 64),
  17. batch_size = 32,
  18. class_mode = 'categorical')
  19. test_set = test_datagen.flow_from_directory('dataset/dota_test_set',
  20. target_size = (64, 64),
  21. batch_size = 32,
  22. class_mode = 'categorical')
  23. classifier.fit_generator(training_set,
  24. steps_per_epoch = 1000,
  25. epochs = 3,
  26. validation_data = test_set,
  27. validation_steps = 500)
  28.  
  29. # Part 3 - Making new predictions
  30. import numpy as np
  31. from keras.preprocessing import image
  32. test_image = image.load_img('dataset/single_prediction/test_2.jpg', target_size = (64, 64))
  33. test_image = image.img_to_array(test_image)
  34. test_image = np.expand_dims(test_image, axis = 0)
  35. result = classifier.predict(test_image)
  36. training_set.class_indices
  37. if result[0][0] == 1.0:
  38. prediction = 'sven'
  39. print("This is a Sven.")
  40. if result[0][0] == 2.0:
  41. prediction = 'mirana'
  42. print("This is a mirana.")
  43. if result[0][0] == 3.0:
  44. prediction = 'Wraith_King'
  45. print("This is a Wraith King.")
  46. if result[0][0] == 4.0:
  47. prediction = 'Phantom_Lancer'
  48. print("This is a Phantom Lancer.")
  49. else:
  50. prediction = 'non_dota hero'
  51. print("This is a non dota hero.")
Add Comment
Please, Sign In to add comment