TheBlue Phoenix
Created January 18, 2020 © GPL3+

JetFire

It is a classifier machine vision model that is developed on the NVIDIA Jetson using datasets of thermal Images to identify crop pests.

AdvancedFull instructions provided5 days147
JetFire

Things used in this project

Hardware components

NVIDIA Jetson Nano Developer Kit
NVIDIA Jetson Nano Developer Kit
×1
Adafruit AMG8833
×1

Software apps and online services

NVIDIA JetPack
MATLAB
MATLAB

Story

Read more

Custom parts and enclosures

drone image

This solution can be deployed on this drone

Schematics

Nano and AMG8833 connections

It shows the actual connections between the AMG8833 and Jetson Nana

Code

MATLAB_CNN_file

MATLAB
It is the main file of the system, that generates and trains the CNN
%% dataset loading and labeling(already resized)
imds = imageDatastore('eggcluster_alexnet_227',...
    'IncludeSubfolders',true,...
    'FileExtensions','.jpg',...
    'LabelSource','foldernames');
labelCount = countEachLabel(imds)
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7);
img = readimage(imds,2);
size_img = size(img)

%% neural net configuration
varSize = 227;
conv1 = convolution2dLayer(6,varSize,'Padding',2,'BiasLearnRateFactor',2);
conv1.Weights = gpuArray(single(randn([6 6 3 varSize])*0.0001));

%% neural net layers
layers = [
    imageInputLayer([varSize varSize 3]);
    
    conv1;
    maxPooling2dLayer(4,'Stride',2);
    reluLayer();
    
    convolution2dLayer(6,112,'Padding',2,'BiasLearnRateFactor',2);
    reluLayer();
    averagePooling2dLayer(3,'Stride',2);
    
    convolution2dLayer(6,55,'Padding',2,'BiasLearnRateFactor',2);
    reluLayer();
    averagePooling2dLayer(4,'Stride',2);
    
    fullyConnectedLayer(26);
    reluLayer();
    fullyConnectedLayer(3);
    softmaxLayer()
    classificationLayer()];

%% training options specifier
opts = trainingOptions('sgdm', ...
    'InitialLearnRate', 0.00004, ...
    'LearnRateSchedule', 'piecewise', ...
    'LearnRateDropFactor', 0.005, ...
    'LearnRateDropPeriod', 12, ...
    'L2Regularization', 0.0008, ...
    'MaxEpochs', 10, ...
    'MiniBatchSize', 10, ...
    'ValidationData', imdsValidation, ...
    'Shuffle', 'every-epoch', ...
    'Verbose', true, ...
    'ValidationFrequency',5, ...
    'Plots','training-progress');
[net, info] = trainNetwork(imds, layers, opts);
%% Save the net

saveCustomNetToFile();

%% Save test image

img_test = imread(test_img.jpg);

CustomNetGPU

MATLAB
code to use Jetson Nano GPU
function classIdx = myCustomNetGPU(im)

persistent net
if isempty(net)
    net = coder.loadDeepLearningNetwork('CustomNet.mat');
end

% Predict with CustomNet
output = predict(net, im);

% Determine the class index with the highest probability
[~,classIdx] = max(output);

end

Cuda generation Code

MATLAB
cfg = coder.gpuConfig('lib','ecoder',true);
cfg.GenerateReport = true;
cfg.ReportPotentialDifferences = false;
cfg.InitFltsAndDblsToZero = false;
cfg.VerificationMode='PIL';
cfg.CodeExecutionProfiling = true;
cfg.BuildConfiguration = 'Faster Builds';
cfg.Hardware = coder.hardware('NVIDIA Jetson');
cfg.HardwareImplementation.TargetHWDeviceType = 'ARM Compatible->ARM 64-bit (LP64)';

%% Define argument types for entry-point 'myCustomNetGPU'.
ARGS = cell(1,1);
ARGS{1} = cell(1,1);
ARGS{1}{1} = coder.typeof(uint8(0),[227 227 3]);

%% Invoke MATLAB Coder.
codegen('-config',cfg,'myCustomNetGPU','-args',{img_test},'-report');

Credits

TheBlue Phoenix

TheBlue Phoenix

7 projects • 32 followers
I have represented India Internationally. I have knowledge of various boards and embedded coding, FPGAs, TI, ADI, On Semi, RPi, SBCs etc.

Comments