コード例 #1
0
def _load_model():
    global MODEL
    global EMOJI
    client = storage.Client()
    bucket = client.get_bucket(MODEL_BUCKET)
    blob = bucket.get_blob(MODEL_FILENAME)
    weights = blob.download_to_filename("model_weights.pth")

    MODEL = LSCCNN(checkpoint_path="model_weights.pth")
    # MODEL.cuda()
    MODEL.eval()

    EMOJI = cv2.imread("blm_fist.png", -1)
    logging.info("Model loaded")
コード例 #2
0
ファイル: app.py プロジェクト: matthiaszimmermann/blm
def _load_model():
    global MODEL
    global EMOJI

    logging.basicConfig(level=logging.INFO)
    logging.info("Loading model '" + MODEL_FILENAME + "' ...")

    MODEL = LSCCNN()
    MODEL.load_weights(MODEL_FILENAME)
    MODEL.eval()

    EMOJI = cv2.imread(EMOJI_FILENAME, -1)

    logging.info("Model loaded")
コード例 #3
0
import numpy as np

checkpoint_path = './weights/part_b_scale_4_epoch_24_weights.pth'
save_dir = "./output/"
data_path = "F:/PETS2006/newframes/"

#output_dir = './output/'
#model_name = os.path.basename(model_path).split('.')[0]
#file_results = os.path.join(output_dir,'results_' + model_name + '_.txt')
if not os.path.exists(save_dir):
    os.mkdir(save_dir)
save_dir = os.path.join(save_dir, 'results')
if not os.path.exists(save_dir):
    os.mkdir(save_dir)

network = LSCCNN(checkpoint_path=checkpoint_path)
#network.cuda()
network.eval()


def save_results(data_path, fname, save_dir):
    img = cv2.imread(os.path.join(data_path, fname))
    print('Loaded ', fname)
    #image = cv2.imread('F:/PETS2006/manypeople/IMG_158.jpeg')
    #image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

    pred_dot_map, pred_box_map, img_out = network.predict_single_image(
        img, nms_thresh=0.75)
    cnt = np.sum(pred_dot_map)

    text = "There are " + str(cnt) + " people in the pic"
コード例 #4
0
import cv2
import os
import torch
from model import LSCCNN
from matplotlib import pyplot as plt
import numpy as np

checkpoint_path = './weights/part_b_scale_4_epoch_24_weights.pth'
checkpoint_path = './weights/qnrf_scale_4_epoch_46_weights.pth'
checkpoint_path = './weights/part_a_scale_4_epoch_13_weights.pth'
# checkpoint_path = './weights/part_a/scale_4_epoch_13.pth'

network = LSCCNN(checkpoint_path=checkpoint_path)
if torch.cuda.is_available():
    network.cuda()
network.eval()

weights_tag = 'part_a'
nms_thresh = 0.1
image_dir = 'outputs/head-detection-frames'
output_dir = "outputs/" + os.path.basename(
    image_dir) + '-{}-{}-outputs'.format(weights_tag, nms_thresh)
print(output_dir)
if os.path.exists(image_dir) and not os.path.exists(output_dir):
    os.makedirs(output_dir)

for image_file in os.listdir(image_dir):
    if image_file.endswith('jpg'):
        print(image_file)

        image_filepath = os.path.join(image_dir, image_file)