MathWorks - Mobile View
  • MathWorks 계정에 로그인합니다.MathWorks 계정에 로그인합니다.
  • Access your MathWorks Account
    • 내 계정
    • 나의 커뮤니티 프로필
    • 라이선스를 계정에 연결
    • 로그아웃
  • 제품
  • 솔루션
  • 아카데미아
  • 지원
  • 커뮤니티
  • 이벤트
  • MATLAB 다운로드
MathWorks
  • 제품
  • 솔루션
  • 아카데미아
  • 지원
  • 커뮤니티
  • 이벤트
  • MATLAB 다운로드
  • MathWorks 계정에 로그인합니다.MathWorks 계정에 로그인합니다.
  • Access your MathWorks Account
    • 내 계정
    • 나의 커뮤니티 프로필
    • 라이선스를 계정에 연결
    • 로그아웃

비디오 및 웨비나

  • MathWorks
  • 비디오
  • 비디오 홈
  • 검색
  • 비디오 홈
  • 검색
  • 영업 상담
  • 평가판 신청
  Register to watch video
  • Description
  • Full Transcript
  • Code and Resources

Deep Learning with MATLAB: Transfer Learning in 10 Lines of MATLAB Code

From the series: Deep Learning with MATLAB

Joe Hicklin, MathWorks

Use MATLAB® for transfer learning, and see how it is a practical way to apply deep learning to your problems.

This demo uses transfer learning to retrain AlexNet, a pretrained deep convolutional neural network (CNN or ConvNet), to recognize snack foods such as hot dogs, cupcakes, and apple pie.

Recorded: 8 Feb 2017

Hi. My name is Joe Hicklin. I'm a senior developer at the MathWorks. I'm going to show you how to do transfer learning. Transfer learning can be a very practical way to apply deep learning to your problems.

With transfer learning, you take a preexisting neural net, modify it slightly, and then retrain it on your images. This can produce excellent results and is far, far easier than designing a network from scratch and training it yourself.

In my work, I need to be able to distinguish hamburgers from hot dogs and cupcakes and apple pie and ice cream. As far as I know, there's no network that'll do that for me. So I'm going to start with a preexisting network, Alex net. Alex net's been trained to classify 1,000 different kinds of images, and it's been trained on over a million images already.

So here I am. I'm going to start out loading Alex net, and I'm going to get the layers out of it so I can see the parts. If you look down here, you can see that Alex net has 25 layers. Most of the layers are doing useful image processing things that'll work for my system as well as for Alex net's. I'm going to leave those alone.

But the 23rd layer has 1,000 neurons in it, because Alex net classifies 1,000 different images. I'm only going to do five different kinds of images, so I'm going to replace that with a network that only has five images. Finally, I'm going to replace the output layer as well. The last layer of Alex net has learned Alex net's classifications, those 1,000 different classes. I don't want that. I'm going to replace it with an empty layer that's going to learn mine.

So now I've got my network set up. It's time to deal with the data. You don't need a million images like Alex net was trained on, but you do need 1,000 of them to get good results. I've made a folder with five subfolders in it, one for each of my classes. So there's one called Apple Pie, one called Cupcakes, and so on. And inside each of these folders are 1,000 images of the appropriate topic.

I've sized these images to be the size Alex net expects, 227 by 227, and you'll have to do that, too. If you arrange your data like this, you can use MATLAB's image data store object, because it understands that structure, and it will load all the images and label them appropriately for you. So that's what I'm doing here.

As soon as I've got my images, I need to separate them into two sets. Most of them I'll use for training, but I'll save a few of them out to test for accuracy later. So let's do that. Now I'm all set to train my network. I've got to set up a few network parameters here. I've chosen parameters that are going to work well.

You can change these if you like and see what happens. And then I'm ready to train the network. That started. That's going to take five or six minutes to do its job. I have a fairly powerful GPU in my computer, so it's pretty quick. Your mileage may vary. All right, the network's done training. The first thing we're going to do now is see how accurate it is.

We're going to ask the network to classify the test images, the images we left out of our training set. And then we're just going to see what fraction of those it gets right. We were 84% accurate. Pretty good for five minutes of work. Let's try it now with the webcam on some real food. I just happened to have some food on my desk. There's hamburgers, apple pie, hot dogs, ice cream.

So overall, it works pretty good, and it's fairly robust for a lot of these. Different angles and stuff. So there we go. That worked better than I expected, really. I simplified this demo as much as I could, but in the download, we'll include a second file that'll have a lot more comments, and it'll have some more code to handle some situations that might arise.

I've showed you how to do classification with transfer learning, but if you need real numbers out, you can also do regression with transfer learning. Well, I hope I've shown you enough to get you interested in transfer learning, so grab some snacks and give it a go.

Download Code and Files

Download code

Related Products

  • Deep Learning Toolbox
  • MATLAB

Learn More

Introduction to Deep Learning (3 Videos)
Deep Learning with MATLAB (Ebook)
Practical Deep Learning Examples with MATLAB (Ebook)
Get Ready for AI with MATLAB (Article)

FREE EBOOK

Introducing Deep Learning with MATLAB

Download ebook

DOWNLOAD CODE

Get the example code used in this video

Feedback

Featured Product

Deep Learning Toolbox

  • Request Trial
  • Get Pricing

Up Next:

Use MATLAB for configuring, training, and evaluating a convolutional neural network for image classification.
5:12
Training a Neural Network from Scratch with MATLAB
View full series (5 Videos)

Related Videos:

7:35
Deep Learning for Computer Vision with MATLAB (Highlights)
2:27
How to Plot Multiple Lines on the Same Figure
45:02
Teaching Fluid Mechanics and Heat Transfer with Interactive...
5:04
Teaching Heat Transfer Using MATLAB Apps
4:15
Transfer Functions in MATLAB

View more related videos

MathWorks - Domain Selector

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

Select web site

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文Chinese
    • English
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

  • 영업 상담
  • 평가판 신청

제품 소개

  • MATLAB
  • Simulink
  • 학생용 소프트웨어
  • 하드웨어 지원
  • File Exchange

다운로드 및 구매

  • 다운로드
  • 평가판 신청
  • 영업 상담
  • 가격 및 라이선스
  • MathWorks 스토어

사용 방법

  • 문서
  • 튜토리얼
  • 예제
  • 비디오 및 웨비나
  • 교육

지원

  • 설치 도움말
  • 사용자 커뮤니티
  • 컨설팅
  • 라이선스 센터
  • 지원 문의

회사 정보

  • 채용
  • 뉴스 룸
  • 사회적 미션
  • 영업 상담
  • 회사 정보

MathWorks

Accelerating the pace of engineering and science

MathWorks는 엔지니어와 과학자들을 위한 테크니컬 컴퓨팅 소프트웨어 분야의 선도적인 개발업체입니다.

활용 분야 …

  • Select a Web Site United States
  • 특허
  • 등록 상표
  • 정보 취급 방침
  • 불법 복제 방지
  • 매스웍스코리아 유한회사
  • 주소: 서울시 강남구 삼성동 테헤란로 521 파르나스타워 14층
  • 전화번호: 02-6006-5100
  • 대표자 : 이종민
  • 사업자 등록번호 : 120-86-60062

© 1994-2021 The MathWorks, Inc.

  • Naver
  • Facebook
  • Twitter
  • YouTube
  • LinkedIn
  • RSS

대화에 참여하기