<jupyter_start><jupyter_text>Understanding Predict<jupyter_code>from dextr.data_pipeline import dextr_transforms
from dextr.model import _DextrInferenceDataset
from skimage.util import img_as_ubyte, img_as_float32
target_size_yx = dextr_model.target_size_yx
padding = dextr_model.padding
blob_sigma = dextr_model.blob_sigma
net = dextr_model.net
from torchvision.transforms import Compose
inference_transforms = Compose([
            dextr_transforms.DextrCropWithHeatmapTransform(
                target_size_yx=target_size_yx,
                padding=padding,
                blob_sigma=blob_sigma,
            ),
            dextr_transforms.DextrToTensor(),
            dextr_transforms.DextrNormalize(),
        ])
images = [pixels]
object_extreme_points = dextr_points[None, :, :]
ds = _DextrInferenceDataset(images, object_extreme_points, transform=inference_transforms)
loader = torch.utils.data.DataLoader(ds, batch_size=1, num_workers=1)
for im in loader:
    image = im['input']
    print(image.shape)
    show_images([image[0,0:3], image[0,3]])
sample_i = 0
predictions = []
with torch.no_grad():
    for batch in loader:
        input = batch['input']
        crop_yx = batch['crop_yx'].detach().cpu().numpy()

        pred_logits = net(input)['out']

        pred_prob = torch.sigmoid(pred_logits).detach().cpu().numpy()

        for i in range(len(crop_yx)):
            image_size = ds.image_sizes[sample_i]
            pred_pil = dextr_transforms.paste_mask_into_image(
                image_size, pred_prob[i, 0, :, :], crop_yx[i])

            pred_pil_arr = img_as_float32(np.array(pred_pil))

            predictions.append(pred_pil_arr)

            sample_i += 1
show_image(pred_prob[0,0]>0.5)
regions = labelling_tool.PolygonLabel.mask_image_to_regions_cv(mask, sort_decreasing_area=True)
regions_js = labelling_tool.PolygonLabel.regions_to_json(regions)
regions_js<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10161542470036478, 'fraction_numerical': 0.009379885356956748, 'mean_word_length': 3.81203007518797, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '401209', 'license': 'MIT', 'n_tokens_mistral': 691, 'n_tokens_neox': 656, 'n_words': 96, 'path': 'nbs/01_dextr.ipynb', 'repo_name': 'tcapelle/django-labeller', 'size': '1919'}