Skip to content
Snippets Groups Projects

fix artifacts vs cache

1 file
+ 3
1
Compare changes
  • Side-by-side
  • Inline
+ 23
4
import cv2
import cv2
from datetime import datetime, timedelta
from datetime import datetime, timedelta
import numpy as np
import keras
from utils.preprocessing import fix_singular_shape, norm_by_imagenet
from utils.preprocessing import fix_singular_shape, norm_by_imagenet
 
from dotenv import load_dotenv
 
import numpy as np
 
import requests
import json
import json
import time
import time
 
import os
from cameras import restaurants
from cameras import restaurants
from db import models
from db import models
from db.database import SessionLocal
from db.database import SessionLocal
from routers.websocket import manager
from routers.websocket import manager
 
load_dotenv()
 
host = os.getenv('MODEL_HOST')
 
port = os.getenv('MODEL_PORT')
 
model = os.getenv('MODEL_NAME')
 
 
 
def make_prediction(instances):
 
url = f"http://{host}:{port}/v1/models/{model}:predict"
 
data = json.dumps({"signature_name": "serving_default", "instances": instances.tolist()})
 
headers = {"content-type": "application/json"}
 
json_response = requests.post(url, data=data, headers=headers)
 
try:
 
predictions = json.loads(json_response.text)['predictions']
 
except BaseException:
 
print("prediction failed")
 
return predictions
 
async def handle_cameras():
async def handle_cameras():
model = keras.models.load_model('assets', compile=False)
db = SessionLocal()
db = SessionLocal()
for restaurant in restaurants:
for restaurant in restaurants:
for camera in restaurant["cameras"]:
for camera in restaurant["cameras"]:
@@ -58,7 +77,7 @@ async def handle_cameras():
@@ -58,7 +77,7 @@ async def handle_cameras():
[treated_img]))),
[treated_img]))),
axis=0)
axis=0)
# getting the density map from the model and the number of people
# getting the density map from the model and the number of people
pred_map = np.squeeze(model.predict(input_image, verbose=0))
pred_map = np.squeeze(make_prediction(input_image))
count_prediction += np.sum(pred_map)
count_prediction += np.sum(pred_map)
for checkout in camera["checkouts"]:
for checkout in camera["checkouts"]:
# we check whether or not the density in the checkout area is high enough to determine if it is open or not
# we check whether or not the density in the checkout area is high enough to determine if it is open or not
Loading