def test_dataset() -> None: labels = cache("labels", load_labels)("/store/dataset/labels.csv") annotations = cache("train_annotations", get_annotations)("/store/dataset/train.csv", labels) d = Dataset(annotations) assert len(d) == 142119
def test_dataset() -> None: raw_audios = load_audios(RAW_TGT_DIR) dataset = Dataset(raw_audios, (128, 128)) for i in range(4): x, y = dataset[0] plot_spectrograms([np.log(i) for i in [x, y]], f"/store/plot/test-{i}.png")
def test_dataset(window_size: int, expected: int) -> None: cache = Cache("/store/tmp") df = cache("load-train", load)("/store/data/train.csv") d = Dataset( df[:20], window_size=window_size, stride=5, ) assert len(d) == expected x, y = d[0] assert x.shape == (1, window_size) assert y.shape == (window_size, )
def test_dataset_total_size() -> None: cache = Cache("/store/tmp") df = cache("load-train", load)("/store/data/train.csv")[:20] d = Dataset( df, window_size=5, stride=5, ) total_size = 0 for i in range(len(d)): t, _ = d[i] total_size += t.shape[1] assert total_size == 20
def test_transform(id: str, mode: Mode) -> None: annotations = [Annotation(id, [])] dataset = Dataset(annotations, mode=mode, resolution=320) save_image( make_grid( [dataset[0][0] for i in range(24)], nrow=8, padding=2, normalize=False, range=None, scale_each=False, pad_value=0, ), f"/store/tmp/test_aug_{id}-{mode}.png", )
def test_generation(): dataset = Dataset() loader = torch.utils.data.DataLoader(dataset, batch_size=1, num_workers=2, collate_fn=lambda batch: batch) b0 = None b1 = None for i, batch in enumerate(loader): if i == 0: b0 = batch else: b1 = batch break assert b0 != b1 for i, batch in enumerate(loader): example = batch[0] ast.parse(example.supervisions["ground_truth"]) if i == 10000: break
from app.dataset import Dataset from app.output import Output from app.segmenter import Segmenter from app.utils import Utils from app.debug import Debug import numpy as np import cv2 dataset = Dataset() dataset.load() segmenter = Segmenter() Output.clear() for item in dataset.items: print(item.file) #if item.file != "008.jpg": # continue # # run the segmentation algorithm # quad = segmenter.segment(item.img, item.distribution_rect) # # draw the result # # reference image