Last active
January 26, 2019 16:20
-
-
Save NickShargan/f8b31928159393c36d80b52bc7dd4a8b to your computer and use it in GitHub Desktop.
This file contains 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.applications.inception_v3 import InceptionV3 | |
# from keras.applications.resnet50 import ResNet50 | |
from keras.applications.mobilenet import MobileNet | |
from keras.preprocessing import image | |
from keras.models import Model | |
from keras.layers import Dense, GlobalAveragePooling2D | |
from keras.preprocessing.image import ImageDataGenerator | |
from keras.callbacks import ModelCheckpoint | |
from keras import backend as K | |
from keras.models import load_model | |
import numpy as np | |
import cv2 | |
# import matplotlib.pyplot as plt | |
img_size = 150 | |
num_channels = 3 | |
# create the base pre-trained model | |
# base_model = ResNet50(weights='imagenet', include_top=False) | |
# base_model = MobileNet(alpha=0.5, include_top=False, input_shape=(img_size, img_size, 3)) | |
# # add a global spatial average pooling layer | |
# x = base_model.output | |
# x = GlobalAveragePooling2D()(x) | |
# # let's add a fully-connected layer | |
# x = Dense(1024, activation='relu')(x) | |
# # and a logistic layer -- let's say we have 200 classes | |
# predictions = Dense(2, activation='softmax')(x) | |
# # this is the model we will train | |
# model = Model(inputs=base_model.input, outputs=predictions) | |
# model.load_weights("./weights-improvement-03-0.86.hdf5") | |
model = load_model("./weights-improvement-03-0.86.hdf5") | |
model.summary() | |
img_path = "./data/test1/1.jpg" | |
img = cv2.imread(img_path) | |
img = cv2.cvtColor(img, color=cv2.COLOR_BGR2RGB) | |
img = cv2.resize(img, (img_size, img_size), interpolation=cv2.INTER_CUBIC) | |
img = img / 255.0 | |
img = np.reshape(img, (1, img_size, img_size, num_channels)) | |
y = model.predict(img) | |
print(y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment