def test_to_float_unknown_dtype(): img = np.ones((100, 100, 3), dtype=np.int16) with pytest.raises(RuntimeError) as exc_info: F.to_float(img) assert str(exc_info.value) == ( "Can't infer the maximum value for dtype int16. You need to specify the maximum value manually by passing " "the max_value argument")
def test_no_resize_pad(): mask = AF.to_float( cv2.imread('data/train/masks/0b73b427d1.png', cv2.IMREAD_GRAYSCALE)) processor = D.DatasetResizePad(101, 128, border_mode=cv2.BORDER_REFLECT101, interpolation=cv2.INTER_LINEAR) mask_pad = processor.forward(image=mask, mask=mask)['image'] mask_torch = torch.from_numpy(mask_pad).unsqueeze(0).unsqueeze(0).float() mask_back = processor.backward(mask_torch).numpy().squeeze() f, ax = plt.subplots(3, 1, figsize=(12, 20)) f.suptitle('test_resize_pad', fontsize=16) ax[0].imshow(mask) ax[1].imshow(mask_pad) ax[2].imshow(mask_back) f.tight_layout() f.subplots_adjust(top=0.88) f.show() assert np.allclose(mask, mask_back)
def test_to_float_unknown_dtype_with_max_value(max_value): img = np.ones((100, 100, 3), dtype=np.int16) expected = img.astype("float32") / max_value assert_array_almost_equal_nulp(F.to_float(img, max_value=max_value), expected)
def test_to_float_without_max_value_specified(dtype, divider): img = np.ones((100, 100, 3), dtype=dtype) expected = img.astype("float32") / divider assert_array_almost_equal_nulp(F.to_float(img), expected)
def test_to_float_with_max_value_specified(max_value): img = np.ones((100, 100, 3), dtype=np.uint16) expected = img.astype('float32') / max_value assert_array_almost_equal_nulp(F.to_float(img, max_value=max_value), expected)