-
-
Save amurzina/b9b825352be2cbc8baedcf6fb1365b89 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
import time | |
import sys | |
import os | |
import numpy as np | |
from keras.models import load_model | |
from keras.preprocessing import image | |
data_path = "../data/" | |
picture_path = data_path + "{}.jpg" | |
CLASSES = [1, 0] | |
def run(model_path): | |
pictures_names = os.listdir(data_path) | |
pic_num = len(pictures_names) | |
model = load_model(model_path) | |
res = [] | |
for pic in range(pic_num): | |
img = image.load_img(picture_path.format(pic), target_size=(224,224)) | |
x = image.img_to_array(img) | |
x = np.expand_dims(x, axis=0) | |
preds = model.predict(x) | |
y_classes = preds.argmax(axis=-1) | |
res.append(CLASSES[y_classes[0]]) | |
res = ''.join(map(str, res)) | |
n = int("0b" + res, 2) | |
text = n.to_bytes((n.bit_length() + 7) // 8, 'big').decode() | |
print(text) | |
if __name__ == '__main__': | |
if len(sys.argv) < 2: | |
print("path to the model expected") | |
exit(1) | |
run(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment