Skip to content

Instantly share code, notes, and snippets.

@amurzina amurzina/aww_solver.py Secret

Created May 28, 2019
Embed
What would you like to do?
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
You can’t perform that action at this time.