def test_conform_coordinates_to_spatial_resolution(): conform_coordinates_to_spatial_resolution( spatial_resolution=30, image_size=ImageSize(width=256, height=256), center=LatLon(lat=40, lon=-70), ) fail_if( conform_coordinates_to_spatial_resolution( spatial_resolution=30, image_size=ImageSize(width=256, height=256), ) is not None) fail_if( conform_coordinates_to_spatial_resolution( spatial_resolution=30, image_size=ImageSize(width=256, height=256), bbox=BBox(top_left=LatLon(lat=0, lon=0), bottom_right=LatLon(lat=1, lon=1))) is None)
def test_cifar10(): train_loader, test_loader = get_data(root=Path('/tmp'), dataset='CIFAR10', mini_batch_size=1) fail_if(not isinstance(train_loader, DataLoader)) fail_if(not isinstance(test_loader, DataLoader)) fail_if(not Path('/tmp/cifar-10-batches-py').is_dir())
def test_imagenet(): train_loader, test_loader = get_data(root=Path('/tmp'), dataset='ImageNet', mini_batch_size=1) fail_if(not isinstance(train_loader, DataLoader)) fail_if(not isinstance(test_loader, DataLoader))
def test_square_resize(): images_dir = Path.cwd() / 'tests/images' fail_if(not images_dir.exists()) image = cv2.imread(str(images_dir / '1_2_RGB_img_0.png')) fail_if(image is None) size = 50 img = square_resize(image, size) h, w, c = img.shape fail_if(h != size or w != size or c != image.shape[2]) # scenario sending already squared image size = 10 img = square_resize(img, size=size) h, w, c = img.shape fail_if(h != size or w != size or c != image.shape[2]) # test width > height image = cv2.resize(image, (50, 100)) size = 50 img = square_resize(image, size) h, w, c = img.shape fail_if(h != size or w != size or c != image.shape[2]) # test height > width image = cv2.resize(image, (100, 50)) size = 50 img = square_resize(image, size) h, w, c = img.shape fail_if(h != size or w != size or c != image.shape[2])
def test_concatenate_horizontal(): images_dir = Path.cwd() / 'tests/images' fail_if(not images_dir.exists()) image_left = cv2.imread(str(images_dir / '1_2_RGB_img_0.png')) image_right = cv2.imread(str(images_dir / '1_2_LST_img_0.png')) fail_if(image_left is None) fail_if(image_right is None) h1, w1, c1 = image_left.shape h2, w2, c2 = image_right.shape fail_if(h1 != h2 or w1 != w2 or c1 != c2) img = concatenate_horizontal([image_left, image_right]) h, w, c = img.shape fail_if(h != h1 or h != h2) fail_if(w != w1 + w2) fail_if(c != c1 or c != c2)
def test_image_size(): img = ImageSize(width=10, height=10) fail_if(img.width != 10 or img.height != 10)
def test_lat_lon(): ll = LatLon(lat=10, lon=10) fail_if(ll.lat != 10 or ll.lon != 10)
def test_bbox(): bbox = BBox(top_left=LatLon(lat=0, lon=0), bottom_right=LatLon(lat=10, lon=10)) fail_if(bbox.top_left.lat != 0 or bbox.top_left.lon != 0) fail_if(bbox.bottom_right.lat != 10 or bbox.bottom_right.lon != 10)