neural style transfer on images · generation, custom fabric, typography and coloring book designs....

4
Ampere Compung Confidenal 1 White Paper One of the most excing and rapidly-developing areas of arficial intelligence and deep learning is the recognion, generaon and modificaon of digital images. Convoluonal Neural Networks (CNNs), which are adaptable to a great variety of tasks, can create arsc images through neural style transfer processes (NST). This system uses neural representaons to separate and recombine the content and style of arbitrary images, providing the neural algorithm for the creaon of arsc images. These algorithms generate a new image rendered in the style of one image but contain the content of a separate image. This is done by encoding the two source images using a CNN model and then ulizing a white noise image to minimize the loss between the generated image and the source content and style images. Neural style transfer is an example of image stylizaon, a non-photorealisc rendering technique that has changed dramacally over the past two decades. Prior to NST, the transfer of image style was performed using machine learning techniques based on image analogy. Given a pair of images, a transformaon could be learned and then applied to create a new artwork from a new photo, by analogy. The drawback of this method is that such a training pair rarely exists in pracce. NST requires no such pairing; only a single example of neural artwork is needed for the algorithm to transfer its style. Neural style transfer is an opmal and efficient tool for visual design applicaons like photo-stylizaon, video stylizaon, graphic design generaon, custom fabric, typography and coloring book designs. A similar style transfer process can be used for sound design. The style of one audio sample is extracted with CNNs and transferred to a target audio sample, combining the structural and tonal elements of the target data with the beat of the styling audio. The evoluon of deep CNNs to extract high-level semanc informaon from audio signals has enabled the synthesis of textures for the audio signal. To maximize the ulity of these promising algorithms, developers must deploy them on a sophiscated technology plaorm that delivers uncompromising end-user experience, lower operang costs and excellent energy efficiency. This white paper will demonstrate a neural style transfer that was trained and tested on the Ampere eMAG™ plaorm. Ampere’s Armv8 64-bit servers are purpose-built for large-scale public and private cloud environments. Ampere’s cloud soluons deliver such advantages through large number of cores, high-speed connecvity, memory throughput, and cost-effecveness so that developers can deploy their soluons. The highly integrated, purpose-built Ampere soluon delivers the highest performance, lowest total cost of ownership (TCO) for private and public clouds. Neural Style Transfer on Images Model Selecon: We use a deep CNN model to extract the features of images and provide proper encoding. Effecve models such as VGG-19 have a large number of convoluonal layers to provide rich feature representaons on a wide variety of images. Pre-trained models are used as they provide proper encoding. VGG-19, for example, has been trained on over a million images. Neural Style Transfer on Images

Upload: others

Post on 31-Jul-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Neural Style Transfer on Images · generation, custom fabric, typography and coloring book designs. A similar style transfer process can be used for sound design. The style of one

Ampere Computing Confidential 1

White Paper

One of the most exciting and rapidly-developing areas of artificial intelligence and deep learning is the recognition, generation and modification of digital images. Convolutional Neural Networks (CNNs), which are adaptable to a great variety of tasks, can create artistic images through neural style transfer processes (NST).

This system uses neural representations to separate and recombine the content and style of arbitrary images, providing the neural algorithm for the creation of artistic images. These algorithms generate a new image rendered in the style of one image but contain the content of a separate image. This is done by encoding the two source images using a CNN model and then utilizing a white noise image to minimize the loss between the generated image and the source content and style images.

Neural style transfer is an example of image stylization, a non-photorealistic rendering technique that has changed dramatically over the past two decades. Prior to NST, the transfer of image style was performed using machine learning techniques based on image analogy. Given a pair of images, a transformation could be learned and then applied to create a new artwork from a new photo, by analogy. The drawback of this method is that such a training pair rarely exists in practice. NST requires no such pairing; only a single example of neural artwork is needed for the algorithm to transfer its style.

Neural style transfer is an optimal and efficient tool for visual design applications like photo-stylization, video stylization, graphic design generation, custom fabric, typography and coloring book designs.

A similar style transfer process can be used for sound design. The style of one audio sample is extracted with CNNs and transferred to a target audio sample, combining the structural and tonal elements of the target data with the beat of the styling audio. The evolution of deep CNNs to extract high-level semantic information from audio signals has enabled the synthesis of textures for the audio signal.

To maximize the utility of these promising algorithms, developers must deploy them on a sophisticated technology platform that delivers uncompromising end-user experience, lower operating costs and excellent energy efficiency.

This white paper will demonstrate a neural style transfer that was trained and tested on the Ampere eMAG™ platform. Ampere’s Armv8 64-bit servers are purpose-built for large-scale public and private cloud environments. Ampere’s cloud solutions deliver such advantages through large number of cores, high-speed connectivity, memory throughput, and cost-effectiveness so that developers can deploy their solutions. The highly integrated, purpose-built Ampere solution delivers the highest performance, lowest total cost of ownership (TCO) for private and public clouds.

Neural Style Transfer on Images

Model Selection: We use a deep CNN model to extract the features of images and provide proper encoding. Effective models such as VGG-19 have a large number of convolutional layers to provide rich feature representations on a wide variety of images. Pre-trained models are used as they provide proper encoding. VGG-19, for example, has been trained on over a million images.

Neural Style Transfer on Images

Page 2: Neural Style Transfer on Images · generation, custom fabric, typography and coloring book designs. A similar style transfer process can be used for sound design. The style of one

Ampere Computing Confidential 2

White Paper

Figure 1 shows the output image obtained when content image is combined with the style image. Figure 2 shows image representations and reconstructions in CNN.

Loss Function: Let [missing variable] be the content image, [missing variable] be the style image, and [missing variable] be the white noise image (i.e., the generated image) that will constitute the final image. Total loss is the sum of content loss and style loss.

Content Loss: The content loss is the mean squared error between the encoding of the white noise image and the content image.For a layer l and the input image , let the number of filters be Tr. The output (or encoded) image will have Tr feature maps, each of size Sr, where Sr is the height times width. So, the encoded image of layer can be stored in a matrix .

Where is the activation of ith filter at position j in layer l.

Style Loss: For capturing the style of an artist, a style representation is used. It computes the correlations between the different filter responses, where the expectation is taken over the spatial extent of the input image. These feature correlations are given by Gram Matrix , where is the inner product between the feature maps i and j represented by vectors in layer l and Nl is the number of feature maps.

The style loss is the mean squared error between the gram matrices of style image and the white noise image. Let be the style image and be the white noise image. Let Al and Xl be the style representations of style image and white noise image in layer l. So, total style loss of a layer l is El.

The total style is:

where Wl is the weighting factor of each layer.

Figure 1: The figure above combines the content of the “Neckarfront” photograph in A and the style

of the starry night to create the output image in C.

Figure 2: Image representations and reconstructions in a CNN

Page 3: Neural Style Transfer on Images · generation, custom fabric, typography and coloring book designs. A similar style transfer process can be used for sound design. The style of one

Ampere Computing Confidential 3

White Paper

Hyperparameter Tuning: To calculate the style and content loss, we use standard error back-propagation. To calculate Ltotal, Lcontent

is weighted by α and Lstyle is weighted by β. The ratio of αβ is generally kept 10–3 or 10–4, to prevent the style from dominating and therefore preventing the loss of content. We use the Adam optimizer algorithm, and find that running it for 500-2000 iterations seems to produce nice results.

Technology Overview:

Hardware: This neural style transfer was performed on Ampere’s eMAG platform with a TensorFlow 1.0 backend.

Architecture: Arm®v8 64-bit server

CPU op-mode: 64-bit

Model name: Arm®v8 64-bit server operating up to 3.3GHZ

Processor Subsystem • 32 Arm v8 64-bit CPU cores up to 3.3 GHz with Turbo • 32 KB L1 I-cache, 32 KB L1 D-cache per core • Shared 256 KB L2 cache per 2 cores

Memory • 32 MB globally shared L3 cache • 8x 72-bit DDR4-2667 channels • Advanced ECC and DDR4 RAS features • Up to 16 DIMMs, 1 TB/socket

System Resources • Full interrupt virtualization • I/O virtualization • Enterprise server-class RAS – End-to-end data poisoning – Error containment and isolation – Background L3 and DRAM scrubbing.

Connectivity • 42 lanes of PCIe Gen 3, with 8 controllers – x16 or two x8/x4 – x16 or two x8/x4 – x8 or two x4 – Two x1 • 4 x SATA Gen 3 ports • 2 x USB 2.0 ports

Technology & Functionality • TSMC 16nm FinFET+ • Arm v8.0-A, SBSA Level 3 – EL3, secure memory and secure boot support • Advanced power management

Power • TDP: 125 W

Software stack: The following dependencies must be installed: TensorFlow, Numpy, OpenCV, Python3 and pretrained VGG network data file.

Usage: Copy your content image to the default image content directory ./image_input. Copy one or more style images to the default style directory ./styles. Run the command:

bash stylize_image.sh <path_to_content_image> <path_to_style_image>Note: Supported image formats include: .png, .jpg, .ppm, .pgm

Figure 3: Neural Style Transfer Algorithm

Ampere Computing™ / 4555 Great America Parkway, Suite 601 / Santa Clara, CA 95054 / www.amperecomputing.com

Ampere Computing reserves the right to make changes to its products, its data sheets, or related documentation, without notice and warrants its products solely pursuant to its terms and conditionsof sale, only to substantially comply with the latest available data sheet. The Ampere Computing logo is a registered trademark of Ampere Computing. Arm is a registered trademark of Arm Holdings.All other trademarks are the property of their respective owners.

©2018 Ampere Computing. All rights reserved.

AMP 2018-0007

with advanced ECC in addition to standard DDR4 RAS features. End-to-end data poisoning ensures corrupted data is tagged and any attempt to use it is flagged as an error. The large L3 cache is also ECC protected, and the processor supports background scrubbing of the L3 cache and DRAM to locate and correct single-bit errors before they accumulate into uncorrectable errors.

Technology and ComplianceThe eMAG 8180 processor is fabricated using TSMC’s proven 16nm FF+ high-performance process technology. The device is fully compliant with the Arm server SBSA and SBBR standards.

eMAG 8180 Block Diagram

L 1lArm v8

CPUL1D

L 1lArm v8

CPUL1D

L2 Cache

L 1lArm v8

CPUL1D

L 1lArm v8

CPUL1D

L2 Cache

L 1lArm v8

CPUL1D

L 1lArm v8

CPUL1D

L2 Cache

32 Arm v8 cores up to 3.3 GHz with Turbo 8 x DDR4-2667

L 1lArm v8

CPUL1D

L 1lArm v8

CPUL1D

L2 Cache

Coherent Network

I/O Network

Shared 32 MBL3 Cache

72bDDR4with ECC

72bDDR4with ECC

72bDDR4with ECC

72bDDR4with ECC

72bDDR4with ECC

72bDDR4with ECC

72bDDR4with ECC

72bDDR4with ECC

4x 2x

SATA 3.0 USB 2.0

2x Instruction Trace

x16 x16 x 8 x1 x1

PCle3.0

PCle3.0

PCle3.0

PCle3.0

PCle3.0

PCle3.0

PCle3.0

PCle3.0

42 Lanes of PCle 3.0

Secure Boot and Management Processors

Low-Speed Interfaces

PMPro SMPro

Features (cont.)

TECHNOLOGY & FUNCTIONALITY• TSMC 16nm FinFET+• Arm v8.0-A, SBSA Level 3

– EL3, secure memory and secure boot support

• Advanced power management

POWER• TDP: 125 W

Figure 4: eMAG Block Diagram

Page 4: Neural Style Transfer on Images · generation, custom fabric, typography and coloring book designs. A similar style transfer process can be used for sound design. The style of one

White Paper

Summary

This white paper illustrates how a Convolutional Neural Network can mix two images to create a new image using neural style transfer. The new image is created by applying the style of one image to the content of another image with the neural style transfer algorithm. This gives better insight into how the algorithm can be applied to different images.

The Ampere Arm 64-bit platform with optimized software produces excellent throughput with lower latency. The eMAG platform supports programmability to deliver performant power across emerging AI workloads with the flexibility to adopt the latest AI technologies.

eMAG delivers better scalability while reducing platform complexity and improving TCO. The powerful ISA architecture provides efficient memory block loads to quickly load data tiles for optimized convolution or optimized generalized matrix multiplications. All devices on the edge are moving towards implementing some form of AI, increasingly performed locally due to cost latency and privacy concerns. Arm-64 bit provides a good solution to accelerate deep learning workloads.

Ampere helps developers innovate new solutions through a broad portfolio of hardware and software offerings to enable the continuum of AI workloads from the edge to the cloud. The eMAG platform supports many pretrained models, computer vision and deep learning algorithms, enabling developers to accelerate computer vision and deep learning algorithms.

This model is inferenced using Arm®v8 64-bit operating at 3GHZ with 32 CPU cores. The software ecosystem and necessary libraries already exist to run the inference application and this demo does not require any additional software or modification to the model. The existing system includes math libraries, supports model optimization and commonly used frameworks, and improves performance on inference.

References

https://modelzoo.co/model/neuralarthttps://github.com/cysmith/neural-style-tfhttps://software.intel.com/en-us/articles/neural-style-transfer-on-audio-signalshttps://www.cvfoundation.org/openaccess/content_cvpr_2016/papers/Gatys_Image_Style_Transfer_CVPR_2016_paper.pdfhttps://www.researchgate.net/publication/320463069_Style_Transfer_for_Audio_using_Convolutional_Neural_Networks/downloadhttps://en.wikipedia.org/wiki/Neural_Style_Transfer

Ampere Computing reserves the right to make changes to its products, its datasheets, or related documentation, without notice and warrants its products solely pursuant to its terms and conditions of sale, only to substantially comply with the latest available datasheet.

Ampere Computing, the Ampere Computing logo, and eMAG are trademarks of Ampere Computing.Arm is a registered trademark of Arm Holdings. All other trademarks are the property of their respective holders.

Copyright © 2019 Ampere Computing. All Rights Reserved.

Ampere Computing4655 Great America Parkway, Santa Clara, CA 95054

Phone: (669) 700-3700https://www.amperecomputing.com