Created
January 22, 2019 13:52
-
-
Save adriaciurana/17a2e52db7d942d8181181904e762975 to your computer and use it in GitHub Desktop.
Medium Articulo: Parte 5
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
import argparse, keras, os | |
from keras.models import model_from_json | |
parser = argparse.ArgumentParser() | |
parser.add_argument("image", help="Image or folder of images to predict", | |
type=str) | |
args = parser.parse_args() | |
# Cargamos el modelo | |
json_file = open('model.json', 'r') | |
loaded_model_json = json_file.read() | |
json_file.close() | |
model = model_from_json(loaded_model_json) | |
model.load_weights("model.h5") | |
# Cargamos la imagen/imagenes | |
if os.path.isdir(args.image): | |
path_images = [] | |
for ext in ['jpg', 'jpeg', 'tiff', 'png', 'gif']: | |
path_images += glob.glob(os.path.join(args.image, "*." + ext)) | |
else: | |
path_images = [args.image] | |
images = [] | |
for path_im in path_images: | |
images.append(np.float32(cv2.resize(cv2.imread(path_im), (32, 32))[..., ::-1]/255.0)) | |
raw_results = model.predict(images) | |
results = {} | |
for i in range(results.shape[0]): | |
if(results[i] > 0.5): | |
results[path_images[i]] = 'dog' | |
else: | |
results[path_images[i]] = 'cat' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment