|
18 | 18 | fullyConnectedLayer(5)
|
19 | 19 | softmaxLayer
|
20 | 20 | classificationLayer];
|
21 |
| - |
22 | 21 | options = trainingOptions('sgdm', ...
|
23 | 22 | 'InitialLearnRate', 0.001, ...
|
24 | 23 | 'LearnRateSchedule', 'piecewise', ...
|
|
30 | 29 | 'Verbose', true, 'Plots','training-progress');
|
31 | 30 |
|
32 | 31 | % Train the network
|
33 |
| - |
34 | 32 | cifar10Net = trainNetwork(imdsTrain, layers, options );
|
35 |
| - |
36 | 33 | % TO AVOID TRAINING, YOU CAN LOAD TRAINED MODEL
|
37 | 34 | %load('final_train.mat');
|
38 | 35 |
|
|
45 | 42 | ax2.ActivePositionProperty = 'position';
|
46 | 43 | keepRolling = true;
|
47 | 44 | set(gcf,'CloseRequestFcn','keepRolling = false; closereq');
|
48 |
| - |
49 | 45 | while keepRolling
|
50 | 46 | % Display and classify the image
|
51 | 47 | im = snapshot(camera);
|
52 | 48 | image(ax1,im)
|
53 | 49 | im = imresize(im, [128 128]);
|
54 | 50 | [label,score] = classify(cifar10Net,im);
|
55 | 51 | title(ax1,{char(label),num2str(max(score),2)});
|
56 |
| - |
57 | 52 | % Select the top five predictions
|
58 | 53 | classNames = cifar10Net.Layers(end).ClassNames
|
59 | 54 | [~,idx] = sort(score,'descend');
|
60 | 55 | idx = idx(5:-1:1);
|
61 | 56 | scoreTop = score(idx);
|
62 | 57 | classNamesTop = classNames(idx);
|
63 |
| - |
64 | 58 | % Plot the histogram
|
65 | 59 | barh(ax2,scoreTop)
|
66 | 60 | title(ax2,'Top 5')
|
|
0 commit comments