def test_demo_images_guides_smoke(name, regions):
    image = demo.demo_images()[name]

    assert isinstance(image.guides, data.DownloadableImageCollection)

    names, _ = zip(*iter(image.guides))
    assert set(names).issuperset(set(regions))
Beispiel #2
0
    def test_demo_images_smoke(self):

        with get_tmp_dir() as root:
            images = demo.demo_images()
            images.download(root=root)
            images = [image for _, image in images]

            guides = [
                [guide for _, guide in image.guides]
                for image in images
                if image.guides is not None
            ]

            for image_or_guide in itertools.chain(images, *guides):
                with self.subTest(image_or_guide=image_or_guide):
                    file = path.join(root, image_or_guide.file)

                    self.assertTrue(
                        path.exists(file), msg=f"File {file} does not exist."
                    )

                    actual = calculate_md5(file)
                    desired = image_or_guide.md5
                    self.assertEqual(
                        actual,
                        desired,
                        msg=(
                            f"The actual and desired MD5 hash of the image mismatch: "
                            f"{actual} != {desired}"
                        ),
                    )
def test_demo_images_smoke():
    images = demo.demo_images()
    assert isinstance(images, data.DownloadableImageCollection)

    names, _ = zip(*iter(images))
    assert set(names) == {
        "bird1",
        "paint",
        "bird2",
        "mosaic",
        "castle",
        "church",
        "cliff",
    }
from pystiche.loss import PerceptualLoss
from pystiche.misc import get_device, get_input_image
from pystiche.ops import (
    FeatureReconstructionOperator,
    MRFOperator,
    MultiLayerEncodingOperator,
)
from pystiche.optim import default_image_pyramid_optim_loop
from pystiche.pyramid import ImagePyramid

print(f"I'm working with pystiche=={pystiche.__version__}")

device = get_device()
print(f"I'm working with {device}")

images = demo_images()
images.download()

########################################################################################
# At first we define a :class:`~pystiche.loss.perceptual.PerceptualLoss` that is used
# as optimization ``criterion``.

multi_layer_encoder = vgg19_multi_layer_encoder()

content_layer = "relu4_2"
content_encoder = multi_layer_encoder.extract_single_layer_encoder(
    content_layer)
content_weight = 1e0
content_loss = FeatureReconstructionOperator(content_encoder,
                                             score_weight=content_weight)
Beispiel #5
0
from os import path

import pytest

from pystiche.demo import demo_images

from .utils import (
    assert_downloads_correctly,
    assert_is_downloadable,
    rate_limited_urlopen,
    retry,
)
from tests.mocks import make_mock_target

IMAGES_AND_IDS = [(image, f"demo, {name}")
                  for name, image in itertools.chain(demo_images(), )]

IMAGE_PARAMETRIZE_KWARGS = dict(zip(("argvalues", "ids"),
                                    zip(*IMAGES_AND_IDS)))


def assert_image_is_downloadable(image, **kwargs):
    assert_is_downloadable(image.url, **kwargs)


@pytest.mark.slow
@pytest.mark.parametrize("image", **IMAGE_PARAMETRIZE_KWARGS)
def test_image_download_smoke(subtests, image):
    retry(lambda: assert_image_is_downloadable(image), times=2, wait=5.0)