/
sat1988
/
MachineVision
Обзор
Документация
Войти
/
sat1988
/
MachineVision
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
task07/test.py
44 строки
1 KB
Oleg Chorakaev
Добавлен 7 пример
26 июл 2025, 16:13
26 июл 2025, 16:13
0a00484
Код
Авторство
О чём код?
import os os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" import numpy as np import cv2 from tqdm import tqdm import tensorflow as tf def create_dir(path): if not os.path.exists(path): os.makedirs(path) """ Global parameters """ H = 640 W = 640 """ Seeding """ np.random.seed(42) tf.random.set_seed(42) """ Directory for storing files """ create_dir("results") model = tf.keras.models.load_model(os.path.join("files", "model.keras")) files = os.listdir("images/") for file in files: print(file) #file = "adfbecd6-dc58-40cf-b8fa-de1305046cdd.jpg" image = cv2.imread("images/"+ file, cv2.IMREAD_COLOR) x = cv2.resize(image, (W, H)) x = (x - 127.5) / 127.5 x = np.expand_dims(x, axis=0) predictions = model.predict(x) print('размерность прогнозов:', predictions.shape) pred_bbox = predictions[-1] print (pred_bbox) # 0.5,0.47890625,0.96796875,0.434375 """ Rescale the bbox points. """ pred_x = int(pred_bbox[0] * image.shape[1]) pred_y = int(pred_bbox[1] * image.shape[0]) pred_w = int(pred_bbox[2] * image.shape[1]) pred_h = int(pred_bbox[3] * image.shape[0]) image = cv2.rectangle(image, (pred_x-int(pred_w/2), pred_y-int(pred_h/2)), (pred_x+int(pred_w/2), pred_y+int(pred_h/2)), (0, 255, 0), 3) ## RED cv2.imwrite(f"results/"+file, image)