Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import keras
- import numpy as np
- import sys
- import cv2
- from keras.utils import np_utils
- from keras.datasets import mnist
- from keras.models import load_model, Model
- from keras.layers import Conv2D, MaxPooling2D
- from keras.preprocessing.image import img_to_array, load_img
- from keras.preprocessing import image
- import matplotlib.pyplot as plt
- name = 'img.jpg'
- model = load_model('catsvsdogs_saved/cvd')
- model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
- img = load_img(name, target_size=(150,150))
- img_plot = load_img(name)
- x = img_to_array(img)
- x /= 255
- x = np.expand_dims(x, axis=0)
- img_class = model.predict_classes(x)
- img_d = model.predict(x)
- print(img_class)
- print(img_d)
- cs = ''
- if img_class[0][0] == 0:
- cs = 'кот'
- img_d[0][0] = 1 - img_d[0][0]
- else:
- cs = 'пёс'
- plt.imshow(img_plot)
- plt.title('Я думаю, что это ' + cs + ' (' + str(int(img_d[0][0]*100)) + '%)')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement