Skip to content

Instantly share code, notes, and snippets.

# Imports
import pathlib
import numpy as np
import torch
from skimage.io import imread
from skimage.transform import resize
from inference import predict
from transformations import normalize_01, re_normalize
import torch
from skimage.io import imread
from torch.utils import data
class SegmentationDataSet(data.Dataset):
def __init__(self,
inputs: list,
targets: list,
transform=None,
from torch import nn
import torch
@torch.jit.script
def autocrop(encoder_layer: torch.Tensor, decoder_layer: torch.Tensor):
"""
Center-crops the encoder_layer to the size of the decoder_layer,
so that merging (concatenation) between levels/blocks is possible.
This is only necessary for input sizes != 2**n for 'same' padding and always required for 'valid' padding.
import pathlib
from utils import get_filenames_of_path
root = pathlib.Path(".../Heads")
inputs = get_filenames_of_path(root / 'input')
inputs.sort()
for idx, path in enumerate(inputs):
import pathlib
from typing import List
import numpy as np
from pytorch_faster_rcnn_tutorial.annotator import Annotator
from pytorch_faster_rcnn_tutorial.datasets import ObjectDetectionDatasetSingle
from pytorch_faster_rcnn_tutorial.transformations import (
ComposeSingle,
FunctionWrapperSingle,
import pathlib
import torch
from utils import get_filenames_of_path
root = pathlib.Path("...\Heads")
targets = get_filenames_of_path(root / 'target')
targets.sort()
annotation = torch.load(targets[1])
import logging
import pathlib
import sys
import warnings
from typing import List
import numpy as np
from pytorch_faster_rcnn_tutorial.datasets import ObjectDetectionDataSet
from pytorch_faster_rcnn_tutorial.transformations import (
import logging
import pathlib
from multiprocessing import Pool
from typing import Dict, List
import torch
from skimage.color import rgba2rgb
from skimage.io import imread
from torch.utils.data import Dataset
from torchvision.ops import box_convert
# visualize dataset
color_mapping = {
1: 'red',
}
from visual import DatasetViewer
datasetviewer = DatasetViewer(dataset, color_mapping)
datasetviewer.napari()
from pytorch_faster_rcnn_tutorial.viewers.object_detection_viewer import ObjectDetectionViewer
from torchvision.models.detection.transform import GeneralizedRCNNTransform
color_mapping: Dict[int, str] = {
1: "red",
}
transform: GeneralizedRCNNTransform = GeneralizedRCNNTransform(
min_size=1024,
max_size=1024,