File Exchange

image thumbnail

Deep Learning for Defect Detection on Raspberry Pi

version 2.0.0 (9.07 MB) by Kei Otsuka
How to create, train simple network, integrate it into pre/post image processing and generate C code to run it on Raspberry Pi


Updated 19 Jul 2019

View Version History

View License

This example shows how to create and train a simple convolutional neural network for defect detection, and how to integrate it into pre/post image processing and generate C code for pre-processing, neural network and post processing to run it on Raspberry Pi.
The algorithm is to detect defective hexagon nuts that has scratch on a surface.

This example demonstrates how to:
#1. Load and explore image data.
#2. Define the network architecture
#3. Train the network
#4. Confirm if trained network works well for new data
#5. Walk through whole algorithm that consist of pre-processing, CNN and
#6. Generate C++ code for whole algorithm to test it on host machine
#7. Generate C++ code for ARM target(Raspberry Pi)
#8. Build and run the exe on the Raspberry Pi

To build and run generated code for deep learning networks that you deploy to Raspberry Pi, you must install third-party software. Please see "Prerequisites for Deep Learning with MATLAB Coder" by running following command.
>>web(fullfile(docroot, 'coder/ug/prerequisites-for-deep-learning-with-matlab-coder.html'))

Note : Code generation for ARM target is only supported on Linux and Windows.

[Japanese]本プログラムでは、簡単な畳み込みニューラルネットワークの作成と、前処理・後処理との統合、コード生成してRaspberry Pi上で動作させるまでの一連の流れをご紹介します。
今回は六角ナットを使用していますが、表面にキズがあるナットは不良品としており、良品と不良品を分類できるネットワークを作成します。また、ナットが写っている場所をROIとして抽出する部分は前処理として、検出された位置に注釈を挿入する部分は後処理として定義しており、それぞれコード生成して統合し、Raspberry Pi上で動作させます。

MATLAB Coderで生成されたコードをRaspberryPi上でビルド&実行させるためには、必要なソフトウェアのインストールおよび環境変数の設定が必要です。以下のコマンドをMATLAB上で実行し、事前に詳細を確認ください。
>>web(fullfile(docroot, 'coder/ug/prerequisites-for-deep-learning-with-matlab-coder.html'))


画像処理・画像分類・ディープラーニング・DeepLearning・デモ・IPCVデモ・ニューラルネットワーク・Raspberry Pi・ラズパイ

Cite As

Kei Otsuka (2020). Deep Learning for Defect Detection on Raspberry Pi (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (6)

Atsushi Ohashi


MATLAB Coder: How do I build the Intel MKL-DNN library for Deep Learning C++ code generation and deployment?

Kei Otsuka

Hi Vivian,
Did you see any error message when you attempted to run this example? It might be helpful to narrow down where the issue is.

vivian wang

Thanks.But I can't run this method.Is there any other code should be loaded? such as, CNN?

Dan Doherty

Pradeep KS

MATLAB Release Compatibility
Created with R2019a
Compatible with R2019a and later releases
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!