Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- classifier.add(Dense(units = 128, activation = 'relu'))
- classifier.add(Dense(units = 4, activation = 'softmax'))
- # Compiling the CNN
- classifier.compile(optimizer = 'adam', loss =
- 'categorical_crossentropy', metrics = ['accuracy'])
- # Part 2 - Fitting the CNN to the images
- from keras.preprocessing.image import ImageDataGenerator
- train_datagen = ImageDataGenerator(rescale = 1./255,
- shear_range = 0.2,
- zoom_range = 0.2,
- horizontal_flip = True)
- test_datagen = ImageDataGenerator(rescale = 1./255)
- training_set = train_datagen.flow_from_directory('dataset/dota_training_set',
- target_size = (64, 64),
- batch_size = 32,
- class_mode = 'categorical')
- test_set = test_datagen.flow_from_directory('dataset/dota_test_set',
- target_size = (64, 64),
- batch_size = 32,
- class_mode = 'categorical')
- classifier.fit_generator(training_set,
- steps_per_epoch = 1000,
- epochs = 3,
- validation_data = test_set,
- validation_steps = 500)
- # Part 3 - Making new predictions
- import numpy as np
- from keras.preprocessing import image
- test_image = image.load_img('dataset/single_prediction/test_2.jpg', target_size = (64, 64))
- test_image = image.img_to_array(test_image)
- test_image = np.expand_dims(test_image, axis = 0)
- result = classifier.predict(test_image)
- training_set.class_indices
- if result[0][0] == 1.0:
- prediction = 'sven'
- print("This is a Sven.")
- if result[0][0] == 2.0:
- prediction = 'mirana'
- print("This is a mirana.")
- if result[0][0] == 3.0:
- prediction = 'Wraith_King'
- print("This is a Wraith King.")
- if result[0][0] == 4.0:
- prediction = 'Phantom_Lancer'
- print("This is a Phantom Lancer.")
- else:
- prediction = 'non_dota hero'
- print("This is a non dota hero.")
Add Comment
Please, Sign In to add comment