/
sxfour
/
python_all_projects
Обзор
Документация
Войти
/
sxfour
/
python_all_projects
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
python_neuro_keras/main.py
39 строк
939 B
Egor Levashov
Add files via upload
27 апр 2024, 09:21
Не верифицирован
27 апр 2024, 09:21
a4602d2
Код
Авторство
О чём код?
from keras.models import load_model import cv2 import numpy as np np.set_printoptions(suppress=True) model = load_model("keras_Model.h5", compile=False) class_names = open("labels.txt", "r").readlines() camera = cv2.VideoCapture(0) while True: ret, image = camera.read() image = cv2.resize(image, (224, 224), interpolation=cv2.INTER_AREA) cv2.imshow("Webcam Image", image) image = np.asarray(image, dtype=np.float32).reshape(1, 224, 224, 3) image = (image / 127.5) - 1 prediction = model.predict(image) index = np.argmax(prediction) class_name = class_names[index] confidence_score = prediction[0][index] print("Class:", class_name[2:], end="") print("Confidence Score:", str(np.round(confidence_score * 100))[:-2], "%") keyboard_input = cv2.waitKey(1) if keyboard_input == 27: break camera.release() cv2.destroyAllWindows()