ai_engine/utils/infer_utils.py
def infer(
    model: Module,
    dataloader: DataLoader,
    destination: str,
):
    """Evaluates test dataset and saves predictions if needed

    Args:
        model (Module): Model to use for inference
        dataloader (DataLoader): Dataloader for inference
        destination (str): Path to save results

    Returns:
        dict: Generates and saves predictions in desired format
    """
    with torch.no_grad():
        model.eval()
        mask_config = dataloader.dataset.mask_config
        for batch in dataloader:
            inputs, names = batch["input"], batch["name"]

            # Forward propagation
            outputs = model(inputs)["out"]

            masks = torch.argmax(outputs, dim=1)

            for input_img, mask, name in zip(inputs, masks, names):

                output_path = get_path_for_output("alphablend", destination, name)
                output_path_mask = get_path_for_output("mask_np", destination, name)
                np.save(output_path_mask, mask.cpu())

                vis_input_img, vis_mask = prepare_tensors_for_vis(input_img, mask)
                generate_save_alphablend(
                    vis_input_img, vis_mask, mask_config, output_path
                )
Evaluates test dataset and saves predictions if needed

    Args:
        model (Module): Model to use for inference
        dataloader (DataLoader): Dataloader for inference
        destination (str): Path to save results

    Returns:
        dict: Generates and saves predictions in desired format
    
Evaluates test dataset and saves predictions if needed
Evaluates test dataset and saves predictions if needed
def infer(
    model: Module,
    dataloader: DataLoader,
    destination: str,
):
    with torch.no_grad():
        model.eval()
        mask_config = dataloader.dataset.mask_config
        for batch in dataloader:
            inputs, names = batch["input"], batch["name"]
            outputs = model(inputs)["out"]
            masks = torch.argmax(outputs, dim=1)
            for input_img, mask, name in zip(inputs, masks, names):
                output_path = get_path_for_output("alphablend", destination, name)
                output_path_mask = get_path_for_output("mask_np", destination, name)
                np.save(output_path_mask, mask.cpu())
                vis_input_img, vis_mask = prepare_tensors_for_vis(input_img, mask)
                generate_save_alphablend(
                    vis_input_img, vis_mask, mask_config, output_path
                )
def infer ( model : Module , dataloader : DataLoader , destination : str , ) : with torch . no_grad ( ) : model . eval ( ) mask_config = dataloader . dataset . mask_config for batch in dataloader : inputs , names = batch [ "input" ] , batch [ "name" ] outputs = model ( inputs ) [ "out" ] masks = torch . argmax ( outputs , dim = 1 ) for input_img , mask , name in zip ( inputs , masks , names ) : output_path = get_path_for_output ( "alphablend" , destination , name ) output_path_mask = get_path_for_output ( "mask_np" , destination , name ) np . save ( output_path_mask , mask . cpu ( ) ) vis_input_img , vis_mask = prepare_tensors_for_vis ( input_img , mask ) generate_save_alphablend ( vis_input_img , vis_mask , mask_config , output_path )
Evaluates test dataset and saves predictions if needed
Evaluates test dataset and saves predictions if needed
"""Evaluates test dataset and saves predictions if needed

    Args:
        model (Module): Model to use for inference
        dataloader (DataLoader): Dataloader for inference
        destination (str): Path to save results

    Returns:
        dict: Generates and saves predictions in desired format
    """ # Forward propagation
Generates and saves predictions in desired format
Generates and saves predictions in desired format
dict
model
Module
Model to use for inference
Model to use for inference
dataloader
DataLoader
Dataloader for inference
Dataloader for inference
destination
str
Path to save results
Path to save results