New image types and transforms.

class IncrementalSplitter[source]

IncrementalSplitter(pct=1.0, valid_pct=0.2, seed=None)

Dynamically changes pct of data used without mixing train and val data

items = np.arange(1000)
splitter = IncrementalSplitter()
t1,v1 = splitter(items)
t2,v2 = splitter(items)
test_eq(set(t1), set(t2))
test_eq(set(v1), set(v2))

Calculate coco variance

# coco = untar_data(URLs.COCO_SAMPLE)
# dset = Datasets(get_image_files(coco), tfms=[PILImage.create])
# dl = dset.dataloaders(after_item=[ToTensor(), Resize(512)], after_batch=[IntToFloatTensor()])
# c_mean = partial(torch.mean, axis=[0,2,3])
# c_std = partial(torch.std, axis=[0,2,3])
# means,stds = zip(*[(c_mean(x[0]),c_std(x[0])) for x in progress_bar(dl.train)])
# mean = torch.stack(means).mean(axis=0)
# std  = torch.stack(stds).pow(2).mean(axis=0).sqrt()

class TensorImageX[source]

TensorImageX(x, **kwargs) :: TensorImage

class PILImageX[source]

PILImageX() :: PILImage

This class represents an image object. To create :py:class:~PIL.Image.Image objects, use the appropriate factory functions. There's hardly ever any reason to call the Image constructor directly.

  • :py:func:~PIL.Image.open
  • :py:func:~PIL.Image.new
  • :py:func:~PIL.Image.frombytes

class NormalizeX[source]

NormalizeX(mean=None, std=None, axes=(0, 2, 3)) :: Normalize

Normalize/denorm batch of TensorImage

img = PILImage.create(TEST_IMAGE).resize((64,64)); img
t = image2tensor(img)
tim, timx = map(IntToFloatTensor(), (TensorImage(t), TensorImageX(t)))
mean,std = [.5]*3,[.5]*3
mean,std = broadcast_vec(1, 4, mean, std, cuda=False)
batch_tfms = [NormalizeX(mean,std)]
tdl = TfmdDL([(timx,tim)], after_batch=batch_tfms, bs=1)
x,y = tdl.one_batch()
test_close(y.mean(), tim.mean())
test_close(x.mean(), (timx.mean()-.5)/.5)

class NormalizeAll[source]

NormalizeAll(mean=None, std=None, axes=(0, 2, 3)) :: Normalize

Normalize/denorm batch of TensorImage

batch_tfms = NormalizeAll(mean,std)
tdl = TfmdDL([(cast(tim, Tensor),tim)], after_batch=batch_tfms, bs=1)
x,y = tdl.one_batch()
test_close(x,y)
test_close(x.mean(), (tim.mean()-.5)/.5)