from utils.torch_utils import select_device
from models.common import DetectMultiBackend
from utils.general import ( check_img_size,non_max_suppression, scale_coords,LOGGER)
import torch
def model_load(device,weights,dnn,imgsz,half):
    # Load model
    device = select_device(device)
    model = DetectMultiBackend(weights, device=device, dnn=dnn)
    stride, names, pt, jit, onnx = model.stride, model.names, model.pt, model.jit, model.onnx
    imgsz = check_img_size(imgsz, s=stride)  # check image size

            # Half 
    half &= pt and device.type != 'cpu'  # half precision only supported by PyTorch on CUDA
    if pt:
        model.model.half() if half else model.model.float()
    if pt and device.type != 'cpu':
                    model(torch.zeros(1, 3, *imgsz).to(device).type_as(next(model.model.parameters())))
    return model,device
from utils.torch_utils import select_device
from models.common import DetectMultiBackend
from utils.general import ( check_img_size,non_max_suppression, scale_coords,LOGGER)
import torch
def model_load(device,weights,dnn,imgsz,half):
    # Load model
    device = select_device(device)
    model = DetectMultiBackend(weights, device=device, dnn=dnn)
    stride, names, pt, jit, onnx = model.stride, model.names, model.pt, model.jit, model.onnx
    imgsz = check_img_size(imgsz, s=stride)  # check image size

            # Half 
    half &= pt and device.type != 'cpu'  # half precision only supported by PyTorch on CUDA
    if pt:
        model.model.half() if half else model.model.float()
    if pt and device.type != 'cpu':
                    model(torch.zeros(1, 3, *imgsz).to(device).type_as(next(model.model.parameters())))
    return model,device
# Load model # check image size # Half # half precision only supported by PyTorch on CUDA