主要内容

このページの翻訳は最新ではありませ。

交通標識の検出と認識

この例では,深層学習を使用する交通標識の検出および認識用途のCUDA®墨西哥人コードを生成する方法を説明します。交通標識の検出および認識は,ドライバーに道路標識についての情報を提供して支援する運転者支援システムのための重要な用途です。

このこの通标识の検出検出および认识の例では,検出,非非大抑制(nms),および认识の3つのステップを行ます。この例では。你只看一次(yolo)ネットワークネットワークバリアントであるオブジェクト検出に,nms,nms,アルゴリズムあるを抑制,重なり,の検出をし,重なり,ある検出抑制ます。最后に,认识ネットワーク検出さ。します。

サードパーティの必要条件

必须

この例では,CUDA MEXを生成します。

  • CUDA®対応NVIDIA®GPUおよびおよび互换性のあるある

オプション

スタティックライブラリ,ダイナミックライブラリ,または実行可能ファイルなどの墨西哥人以外のビルドについて,この例では以下の要件も適用されます。

GPU環境の検証

関数coder.checkGpuInstall(GPU编码器)を使用して,この例を実行するのに必要なコンパイラおよびライブラリが正しく設定されていることを検証します。

envCfg = coder.gpuEnvConfig (“主机”);envcfg.deeplibtarget =.“cudnn”;envCfg。DeepCodegen = 1;envCfg。安静= 1;coder.checkGpuInstall (envCfg);

検出ネットワークと認識ネットワーク

検出ネットワークは,Darknetフレームワークで学習が行われ,推論のためにMATLAB®にインポートされています。交通標識のサイズはイメージのサイズと比べて比較的小さく,学習データ内のクラスあたりの学習サンプル数が少ないため,すべての交通標識を検出ネットワークに学習させるための単一のクラスと見なします。

検出ネットワークは,入力イメージを7行7列のグリッドに分割します。各グリッドセルは,交通標識の中心がそのグリッドセル内にある場合に交通標識を検出します。各セルは2つの境界ボックスとそれらの境界ボックスの信頼スコアを予測します。信頼スコアは,そのボックスがオブジェクトを含んでいるかどうかを示します。各セルは,グリッドセル内で交通標識が見つかる確率を予測します。最終的なスコアは前述のスコアの積です。0.2この最終スコアにのしきい値を適用して検出を選択します。

認識ネットワークは,MATLABを使用して同じイメージについて学習済みです。

trainRecognitionnet.m补助补助は,认识ネットワークの学习についてています。

事前学習済みのSeriesNetworkの取得

検出ネットワークと認識ネットワークをダウンロードします。

gettsdr();

検出ネットワークには,畳み込み層,漏ReLU層,全結合層など,58個の層が含まれています。

负载(“yolo_tsr.mat”);yolo。意思层
ANS = 58×1层阵列,带有图层:1'输入'图像输入448×448×3图像2'CONC1'卷积64 7×7×3卷绕升序[2 2]和填充[3 3 3 3] 3'Relu1'泄漏释放泄漏释放relu与刻度0.1 4'池1'最大池2×2最大汇集步进[2 2]和填充[0 0 0 0] 5'CONV2'卷积192 3×3×64卷绕卷发[11]和填充[1 1 1 1] 6'Relu2'泄漏释放泄漏释放尺寸0.1 7'Pool2'最大池2×2最大汇集步进[2 2]和填充[0 0 0 0] 8'CRANC3'卷积128 1×1×192卷曲的卷发[1 1]和填充[0 0 0 0] 9'Relu3'泄漏的Relu泄漏Relu,带刻度0.1 10''Conv4'卷积256 3×3×128卷曲的卷曲[1 1]并填充[1 1 1 1] 11'Relu4'泄漏的Relu泄漏Relu与Scale0.1 12''Conv5'卷积256 1×1×256卷绕卷曲[1 1]和填充[0 0 0 0] 13'Relu5'泄漏释放泄漏释放尺寸为0.1 14''CONV6'卷积512 3×3×256卷曲的卷曲[1 1]和填充[1 1 1 1] 15'CREU6'泄漏的Relu泄漏释放尺寸0.1 16'池6'最大池2×2最大池与步幅[2 2]和填充[0 0 0 0] 17'CONV7'卷积256 1×1×512卷曲与步幅有卷曲[1]和填充[0 0 0 0] 18'Relu7'泄漏释放泄漏释放尺度0.1 19'CANC8'卷积512 3×3×256卷绕卷曲[1 1]和填充[1 1 1 1] 20'relu8'泄漏Relu Leaky Relu与Scale0.1 21'Conv9'卷积256 1×1×512卷绕卷发[1 1]和填充[0 0 0 0] 22'Relu9'泄漏释放Relu与Scale0.1 23'Conv10'卷积512 3×3×256卷绕卷发[1 1]和填充[1 1 1 1] 24'Relu10'泄漏的Relu泄漏释放尺寸为0.1 25'Conv11'卷积256 1×1×512卷绕卷发[1 1]和填充[0 0 0 0] 26'Relu11'泄漏的Relu泄漏Relu与刻度0.1 27''Conv12'卷积512 3×3×256卷绕升温[1 1]和填充[1 1 1 1] 28'Relu12'泄漏释放Relu与Scale 0.1 29''Conv13'卷积256 1×1×512卷曲与步幅[1 1] and padding [0 0 0 0] 30 'relu13' Leaky ReLU Leaky ReLU with scale 0.1 31 'conv14' Convolution 512 3×3×256 convolutions with stride [1 1] and padding [1 1 1 1] 32 'relu14' Leaky ReLU Leaky ReLU with scale 0.1 33 'conv15' Convolution 512 1×1×512 convolutions with stride [1 1] and padding [0 0 0 0] 34 'relu15' Leaky ReLU Leaky ReLU with scale 0.1 35 'conv16' Convolution 1024 3×3×512 convolutions with stride [1 1] and padding [1 1 1 1] 36 'relu16' Leaky ReLU Leaky ReLU with scale 0.1 37 'pool16' Max Pooling 2×2 max pooling with stride [2 2] and padding [0 0 0 0] 38 'conv17' Convolution 512 1×1×1024 convolutions with stride [1 1] and padding [0 0 0 0] 39 'relu17' Leaky ReLU Leaky ReLU with scale 0.1 40 'conv18' Convolution 1024 3×3×512 convolutions with stride [1 1] and padding [1 1 1 1] 41 'relu18' Leaky ReLU Leaky ReLU with scale 0.1 42 'conv19' Convolution 512 1×1×1024 convolutions with stride [1 1] and padding [0 0 0 0] 43 'relu19' Leaky ReLU Leaky ReLU with scale 0.1 44 'conv20' Convolution 1024 3×3×512 convolutions with stride [1 1] and padding [1 1 1 1] 45 'relu20' Leaky ReLU Leaky ReLU with scale 0.1 46 'conv21' Convolution 1024 3×3×1024 convolutions with stride [1 1] and padding [1 1 1 1] 47 'relu21' Leaky ReLU Leaky ReLU with scale 0.1 48 'conv22' Convolution 1024 3×3×1024 convolutions with stride [2 2] and padding [1 1 1 1] 49 'relu22' Leaky ReLU Leaky ReLU with scale 0.1 50 'conv23' Convolution 1024 3×3×1024 convolutions with stride [1 1] and padding [1 1 1 1] 51 'relu23' Leaky ReLU Leaky ReLU with scale 0.1 52 'conv24' Convolution 1024 3×3×1024 convolutions with stride [1 1] and padding [1 1 1 1] 53 'relu24' Leaky ReLU Leaky ReLU with scale 0.1 54 'fc25' Fully Connected 4096 fully connected layer 55 'relu25' Leaky ReLU Leaky ReLU with scale 0.1 56 'fc26' Fully Connected 539 fully connected layer 57 'softmax' Softmax softmax 58 'classoutput' Classification Output crossentropyex with '1' and 538 other classes

認識ネットワークには,畳み込み層,全結合層,分類出力層など,14個の層が含まれています。

负载(“RecognitionNet.mat”);事先。层
ans = 14×1 Layer array with layers:1“imageinput”图像输入48×48×3图片zerocenter正常化和randfliplr的扩增2 conv_1卷积100 7×7×3步[1]和填充的卷积[0 0 0 0]3‘relu_1 ReLU ReLU 4“maxpool_1”马克斯池2×2马克斯池步(2 - 2)和填充[0 0 0 0]5 conv_2卷积150 4×4×100旋转步[1]和填充[0 0 0 0]6‘relu_2 ReLU ReLU 7“maxpool_2”马克斯池2×2马克斯池步[2 2]和填充[0 0 0 0]8 conv_3卷积250 4×4×150旋转步[1]和填充[0 0 0 0]9“maxpool_3”马克斯池2×2马克斯池步[2 2]和填充[0 0 0 0]10“fc_1”完全连接300完全已连接层11 'dropout' dropout 90% dropout 12 'fc_2' Fully connected 35 Fully connected layer 13 'softmax' softmax' softmax 14 'classoutput' classoutput crossentropyex with '0'和34个其他类

エントリポイント関数tsdr_predict

エントリポイント関数tsdr_predict.mは,イメージ入力を受け取り,検出ネットワークを使用してイメージ内の交通標識を検出します。この関数は,selectStrongestBboxを使用して重なりのある検出を抑制し(NMS),認識ネットワークを使用して交通標識を認識します。この関数は,ネットワークオブジェクトをyolo_tsr.matから永続変数detectionnetRecognitionNet.matから永続変数recognitionnetに読み込みます。この関数のそれ以降の呼び出しでは,この永続オブジェクトが再利用されます。

类型(“tsdr_predict.m”
函数[selectedBbox idx] = tsdr_predict (img) % # codegen %这个函数图像中检测交通标志使用检测网络%(修改版Yolo)意思和识别(分类)使用识别网络输入% %:% % im:输入测试图像% %输出:% % selectedBbox:检测边界框% idx:版权所有2017-2019 The MathWorks, Inc. coder.gpu.kernelfun;% resize图像img_rz = imresize(img,[448,448]);%转换为BGR格式img_rz = img_rz(:,:,3:-1:1);img_rz = im2single (img_rz);%% TSD持续检测网;if isempty(detectionnet) detectionnet = coder.loadDeepLearningNetwork('yolo_tsr.mat','Detection'); / /检测网络end predictions = detectionnet.activations(img_rz,56,'OutputAs','channels');%%将预测转换为边界框属性类= 1;num = 2; side = 7; thresh = 0.2; [h,w,~] = size(img); boxes = single(zeros(0,4)); probs = single(zeros(0,1)); for i = 0:(side*side)-1 for n = 0:num-1 p_index = side*side*classes + i*num + n + 1; scale = predictions(p_index); prob = zeros(1,classes+1); for j = 0:classes class_index = i*classes + 1; tempProb = scale*predictions(class_index+j); if tempProb > thresh row = floor(i / side); col = mod(i,side); box_index = side*side*(classes + num) + (i*num + n)*4 + 1; bxX = (predictions(box_index + 0) + col) / side; bxY = (predictions(box_index + 1) + row) / side; bxW = (predictions(box_index + 2)^2); bxH = (predictions(box_index + 3)^2); prob(j+1) = tempProb; probs = [probs;tempProb]; boxX = (bxX-bxW/2)*w+1; boxY = (bxY-bxH/2)*h+1; boxW = bxW*w; boxH = bxH*h; boxes = [boxes; boxX,boxY,boxW,boxH]; end end end end %% Run Non-Maximal Suppression on the detected bounding boxess coder.varsize('selectedBbox',[98, 4],[1 0]); [selectedBbox,~] = selectStrongestBbox(round(boxes),probs); %% Recognition persistent recognitionnet; if isempty(recognitionnet) recognitionnet = coder.loadDeepLearningNetwork('RecognitionNet.mat','Recognition'); end idx = zeros(size(selectedBbox,1),1); inpImg = coder.nullcopy(zeros(48,48,3,size(selectedBbox,1))); for i = 1:size(selectedBbox,1) ymin = selectedBbox(i,2); ymax = ymin+selectedBbox(i,4); xmin = selectedBbox(i,1); xmax = xmin+selectedBbox(i,3); % Resize Image inpImg(:,:,:,i) = imresize(img(ymin:ymax,xmin:xmax,:),[48,48]); end for i = 1:size(selectedBbox,1) output = recognitionnet.predict(inpImg(:,:,:,i)); [~,idx(i)]=max(output); end

関数tsdr_predictのCUDA墨西哥人の生成

墨西哥人ターゲットのGPU構成オブジェクトを作成し,ターゲット言語をc++に設定します。関数编码器。DeepLearningConfig(GPU编码器)を使用してCUDNN.深層学習構成オブジェクトを作成し,それをGPUコード構成オブジェクトのDeepLearningConfigプロパティに割り当てます。CUDA墨西哥人を生成するには,codegenコマンドを使用し,入力のサイズを[3]480704年に指定します。この値は関数tsdr_predictの入力イメージサイズに対応します。

cfg = coder.gpuConfig ('mex');cfg。TargetLang =“c++”;cfg。DeepLearningConfig =编码器。DeepLearningConfig (“cudnn”);codegen配置cfgtsdr_predictarg游戏{(480704 3 uint8)}报告
代码生成成功:要查看报告,打开('codegen/mex/tsdr_predict/html/report.mldatx')。

TensorRTを使用してコードを生成するには,“cudnn”の代わりに,coder.DeepLearningConfig(“tensorrt”)をオプションとしてコーダー構成オブジェクトに渡します。

生成された墨西哥人の実行

入力イメージを読み込みます。

我= imread (“stop.jpg”);imshow (im);

入力イメージに対してtsdr_predict_mex.を呼び出します。

Im = imresize(Im, [480,704]);[bboxes、类]= tsdr_predict_mex (im);

クラス番号をクラスディクショナリ内の交通標識名にマッピングします。

一会= {“addedLane”“慢”“下降”“speedLimit25”“speedLimit35”'speedlimit40'“speedLimit45”...“speedLimit50”“speedLimit55”'speedlimit65'“speedLimitUrdbl”“doNotPass”“十字路口”...“keepRight”'巷子'“合并”'禁止左转弯'“noRightTurn”“停止”“pedestrianCrossing”...“stopAhead”“rampSpeedAdvisory20”“rampSpeedAdvisory45”'truckspeedlimit55'...“rampSpeedAdvisory50”“turnLeft”'rampspeedadvisisoryurdbl'“turnRight”“rightLaneMustTurn”...'屈服''前方减速''学校'“schoolSpeedLimit25”“zoneAhead45”“signalAhead”};classRec = ClassNames(类);

検出した交通标识を表示します。

outputImage = insertShape (im,“矩形”,bboxes,“线宽”,3);为了i = 1:size(bboxes,1) outputImage = insertText(outputImage,[bboxes(i,1)+bboxes(i,3) -20],classRec{i},'字体大小', 20岁,“输入TextColor”“红色”);结尾imshow (outputImage);

ビデオにある交通標識の検出と認識

用意されている補助ファイルtsdr_testVideo.mは,テストビデオからフレームを取得して,交通標識の検出および認識を実行し,テストビデオの各フレームについて結果をプロットします。

% Input video v = VideoReader('stop.avi'); / /输入视频fps = 0;
while hasFrame(v) %拍摄帧图片= readFrame(v);照片= imresize(图片,(920、1632));% Call MEX功能用于交通标志检测与识别[bboxes,一堂课]= tsdr_predict_mex(图);纽特= toc;
% FPS = .9* FPS + .1*(1/newt);
%显示
displaydetections(图片,bboxes,clases,fps);结尾

メモリに読み込まれた静的ネットワークオブジェクトをクリアします。

清晰的墨西哥人

関連するトピック