top_level = pyramid[-1] content_image = top_level.resize_image(content_image) style_image = top_level.resize_image(style_image) ######################################################################################## # As a last preliminary step the previously loaded images are set as targets for the # perceptual loss (``criterion``) and we create the input image. criterion.set_content_image(content_image) criterion.set_style_image(style_image) starting_point = "content" input_image = get_input_image(starting_point, content_image=content_image) show_image(input_image, title="Input image") ######################################################################################## # Finally we run the NST with the # :func:`~pystiche.optim.optim.default_image_pyramid_optim_loop`. If ``get_optimizer`` # is not specified, as is the case here, the # :func:`~pystiche.optim.optim.default_image_optimizer`, i.e. # :class:`~torch.optim.lbfgs.LBFGS` is used. output_image = default_image_pyramid_optim_loop(input_image, criterion, pyramid, logger=demo_logger()) # sphinx_gallery_thumbnail_number = 4 show_image(output_image, title="Output image")
# The optimization runs on each ``level`` for ``level.num_steps``. # # # In every step perceptual loss is calculated # with the ``criterion`` and propagated backward to the ``input_image``. If # ``get_optimizer`` is not specified, as is the case here, the # :func:`~pystiche.optim.optim.default_image_optimizer`, i.e. # :class:`~torch.optim.lbfgs.LBFGS` is used. # # .. note:: # # By default ``pystiche`` logs the time during an optimization. In order to reduce # the clutter, we use the minimal ``demo_logger`` here. output_image = default_image_optim_loop( input_image, criterion, num_steps=500, logger=demo_logger() ) ######################################################################################## # After the NST is complete we show the result. # sphinx_gallery_thumbnail_number = 4 show_image(output_image, title="Output image") ######################################################################################## # Conclusion # ---------- # # If you started with the basic NST example without ``pystiche`` this example hopefully
def test_demo_logger_smoke(caplog): optim_logger = demo.demo_logger() with asserts.assert_logs(caplog, logger=optim_logger): optim_logger.message("test message")
def test_demo_logger_smoke(self): optim_logger = demo.demo_logger() with self.assertLogs(optim_logger.logger, "INFO"): optim_logger.message("Test message")