<jupyter_start><jupyter_text>Create Segmented Test Data<jupyter_code>import importlib
import time
import hpacellseg.cellsegmentator as cellsegmentator
from src import utils
NUC_MODEL = "./segmentation/nuclei-model.pth"
CELL_MODEL = "./segmentation/cell-model.pth"

segmentator = cellsegmentator.CellSegmentator(
    NUC_MODEL,
    CELL_MODEL,
    scale_factor=0.25,
    padding=True,
    multi_channel_model=True,
)
cells_frame = src.utils.create_cell_segmentation_rles(
    csv_file=DATA+"sample_submission.csv",
    root_dir=DATA+"/test/",
    segmentator=segmentator,
    test=True,
    n_samples=2,
    n_workers=24    
)
cells_frame.to_csv(DATA+f"test_cells_KAGGLE.csv", index=False)
import torchvision

transforms = torchvision.transforms.Compose([
    src.transforms.MaskCrop(),
    src.transforms.PadToSquare(),
    src.transforms.Resize(224),
    src.transforms.ToTensor(),
    src.transforms.Normalize(),
])

ssdata = src.datasets.SingleCellDatasetKaggle(csv_file='data/test_cells_KAGGLE.csv', root_dir=DATA+"test/",
                                        transform=transforms, test=True)<jupyter_output><empty_output><jupyter_text>Create Predictions<jupyter_code>ssloader = torch.utils.data.DataLoader(ssdata, batch_size=64, num_workers=8, collate_fn=src.datasets.collate_fn)
model = torch.load(MODELS+"model.pt")
def build_prediction_string(pred, conf, mask):
    mask = mask[2:-1]
    prediction_string = f"{pred} {conf} {mask}" 
    return prediction_string
with tqdm(ssloader, unit="batch") as tloader:
    tloader.set_description(f"Submission Sample")
    # Iterate over data.
    for images, labels, annotations in tloader:
        images = images.float().to(device)
        labels = labels.float().to(device)
        outputs = model_ft(images)
        confs, preds = torch.max(1/(1+torch.exp(-outputs)),1)
        for conf, pred, annotation in zip(confs, preds, annotations):
            iid = annotation['ID']
            pstring = build_prediction_string(pred, conf, annotation['rle'])
            sdf.loc[iid, 'PredictionString'] = sdf.loc[iid, 'PredictionString'] + ' ' + pstring
sdf.to_csv("./submissions/submission.csv")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12413793103448276, 'fraction_numerical': 0.007816091954022988, 'mean_word_length': 4.268765133171913, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '86219', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 759, 'n_tokens_neox': 739, 'n_words': 114, 'path': 'notebooks/sample-submission.ipynb', 'repo_name': 'mpff/hpa-single-cell-classification', 'size': '2175'}