## Deep LearningUnderstanding and using deep learning networks

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the page.

# MATLAB Demos at GTC: Style Transfer and Celebrity Lookalikes5

Posted by Johanna Pingel,

This post is all about NVIDIA and their upcoming GPU Technology Conference commonly referred to as GTC. Thousands of people attend every year at GTCs worldwide. GTC San Jose boasts around 9000 attendants. If you're one of those people, stop by and say hello! There's going to be many presentations, including a few from MathWorks on GPU Coder, MATLAB and NVIDIA Docker, and a hands-on MATLAB workshop: See the schedule here.

## What are we going to show?

### Deep Learning on the Cloud

Even if you're not going to GTC, we want you to know that we support NVIDIA GPU Cloud Resources, through their NGC platform. This means you can run MATLAB with NVIDIA GPUs in the cloud. A new (NVIDIA!) blog post explains the details with an example: https://devblogs.nvidia.com/ More links on cloud resources:

### Demos

At the show, we'll be luring people to our booth with a raffle for a free MATLAB Home license, and cool demos including:
• Deep Learning on DGX
• Deep Learning running TensorRT
• Age Detection using YOLO on a Jetson Xavier board
And your choice between two deep learning demos I just completed: "Style Transfer" and "Celebrity Doppelganger." The code for Celebrity Doppelganger can be downloaded below. Just add your own images, and you're good to go! Style Transfer This demo uses deep learning to create images in the style of another image (such as Van Gogh, or Monet). A network was trained to extract specific features from an image at many points in the network. The network will encode and decode features of a new image that will take the style from a reference image: This isn't the zippiest of demos, (I've been averaging 0.5s per image with my setup) so we can't run this example streaming. Instead, I have it running on a timer to take a picture every few seconds and allow people to customize their own pictures in which ever style they'd like. Celebrity Doppelganger This demo is extracting features from a network (I chose ResNet-101 and pulled features from the final fully connected layer) and running a K-Nearest Neighbor algorithm to determine the closest match of features belonging to a celebrity. The code to build the celebrity KD Tree Searcher looks like this:
function MDL = buildCelebModel(imds_celeb,net,layer)
% get celebrity activations

num_files = length(imds_celeb.Files);
activs_c = [];

for ii = 1:num_files
bbox = face_predict(ipicture);
if ~isempty(bbox)
bboxpt = bbox(1,:);
bufx = floor(.3*bboxpt(3));        bufy = floor(.3*bboxpt(4));
xs = max(bboxpt(1)-bufx, 1);        ys = max(bboxpt(2)-bufy, 1);
xe = min(bboxpt(1)+bboxpt(3)-1+bufx, size(ipicture,2));
ye = min(bboxpt(2)+bboxpt(4)-1+bufy, size(ipicture,1));

face = ipicture(ys:ye, xs:xe, :);
face = imresize(face, [224,224]);
end

xx = activations(net,single(face),layer);
activs_c = vertcat(activs_c,squeeze(xx(1,1,:))'); %'
end
MDL = KDTreeSearcher(activs_c);
end
The idea is to pull activations from each face, and then build a model (MDL) that you can use to find the closest match. When I run this through my webcam, extract a face from the camera, I can run this code:
activs_u = squeeze(xx(1,1,:))';%'
[Idx,D] = knnsearch(app.mdl,activs_u,'K',num);

And I will get the Index (Idx) corresponding to the image number of my closest match. Inside the app, it will look something like this: Whether or not you believe I look like Uma I guess is up for debate, but let's just say I was happy with my match!! Update: when I ran it again the following day, apparently I look like Padma? This algorithm is suspicious! Also keep in mind at a conference such as this, it's not really about showing the most ground breaking or highest accuracy algorithm. It's about letting people interact with deep learning and hopefully starting a conversation. That said, I still have a few days to play with these demos before I leave for San Jose. Any suggestions on how to make these demos better before the conference? I put the code for the doppelganger example in the download code button below. Let me know what you think of the demos, and please stop by the booth if you're going to be at GTC San Jose!

Get the MATLAB code

Thanh replied on : 1 of 5
Very good
Kris replied on : 2 of 5
Very cool. Would you also please post the code for the Style Transfer example? Thanks!
Johanna Pingel replied on : 3 of 5
The trained network is too big to share on the blog, but I may be able to share via file exchange? I can look into this
Bradley Monk replied on : 4 of 5
The following code can be used to download a bunch of celebrity images from the web
% get celebrity thumbnails from the web

for k = 1000:1100

celebJPG = [num2str(k) '.jpg'];
celebURL = ['https://celebritybucks.com/images/celebs/full/' celebJPG];

try websave(celebJPG , celebURL);
fprintf('Celeb %.f saved \n',k)
catch