Created
August 3, 2018 08:31
-
-
Save sameerg07/81498025933da88fe3487a16f7e89c51 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras.models import load_model | |
from keras.preprocessing.image import ImageDataGenerator | |
from keras.models import Sequential | |
from keras.layers import Conv2D, MaxPooling2D | |
from keras.layers import Activation, Dropout, Flatten, Dense | |
from keras import backend as K | |
import cv2 | |
import numpy as np | |
img_width, img_height = 150, 150 | |
train_data_dir = 'flower_photos/train' | |
validation_data_dir = 'flower_photos/validation' | |
nb_train_samples = 2929 | |
nb_validation_samples = 741 | |
epochs = 50 | |
batch_size = 16 | |
if K.image_data_format() == 'channels_first': | |
input_shape = (3, img_width, img_height) | |
else: | |
input_shape = (img_width, img_height, 3) | |
def create_model(): | |
model = Sequential() | |
model.add(Conv2D(32, (3, 3), input_shape=input_shape)) | |
model.add(Activation('relu')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Conv2D(32, (3, 3))) | |
model.add(Activation('relu')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Conv2D(64, (3, 3))) | |
model.add(Activation('relu')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Flatten()) | |
model.add(Dense(64)) | |
model.add(Activation('relu')) | |
model.add(Dropout(0.5)) | |
model.add(Dense(5)) | |
model.add(Activation('sigmoid')) | |
return model | |
model = create_model() | |
model = model.load_weights('first_try.h5') | |
print(type(model)) | |
img = cv2.imread('test.jpg') | |
img = cv2.resize(img,(150,150)) | |
img = np.reshape(img,[1,150,150,3]) | |
classes = model.predict_classes(model,img) | |
print (classes) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment