def test_non5d_data_raises(): with pytest.raises(IteratorValidationError): _ = Flip(Undivided(default=np.random.randn(2, 3, 1, 2)), prob_dict={'default': 1}) with pytest.raises(IteratorValidationError): _ = Pad(Undivided(default=np.random.randn(2, 3, 1, 2)), size_dict={'default': 1}) with pytest.raises(IteratorValidationError): _ = RandomCrop(Undivided(default=np.random.randn(2, 3, 1, 2)), shape_dict={'default': (1, 1)})
def test_pad(): a = np.random.randn(2, 3, 5, 5, 4) b = np.random.randn(2, 3, 4, 4, 1) c = np.random.randn(2, 3, 1) iterator = Undivided(default=a, secondary=b, targets=c) pad = Pad(iterator, size_dict={'default': 1})(default_handler) x = next(pad) assert set(x.keys()) == set(iterator.data.keys()) assert x['default'].shape == (2, 3, 7, 7, 4) assert x['secondary'].shape == (2, 3, 4, 4, 1) assert x['targets'].shape == (2, 3, 1) assert np.allclose(x['default'][:, :, 1:-1, 1:-1, :], a) assert np.allclose(x['secondary'], b) assert np.allclose(x['targets'], c)
def test_pad_dict_mismatch_raises(): with pytest.raises(IteratorValidationError): _ = Pad(inner, size_dict={'images': 1}) with pytest.raises(IteratorValidationError): _ = Pad(inner, size_dict={'default': 1}, value_dict={'images': 0})