cifar10 matlab
时间: 2023-09-13 21:07:51 浏览: 49
CIFAR-10 is a popular image classification dataset that contains 60,000 color images of 32x32 pixels in 10 classes, with 6,000 images per class. The dataset is often used as a benchmark for computer vision tasks such as object recognition, image segmentation, and image classification.
In MATLAB, the CIFAR-10 dataset can be loaded using the `cifar10Data` function provided by the Computer Vision System Toolbox. This function returns a struct containing the training and testing data, labels, and other information.
Here is an example code snippet for loading the CIFAR-10 dataset in MATLAB:
```
% Load CIFAR-10 dataset
cifar10 = cifar10Data;
% Display sample images
figure
for i = 1:20
subplot(4,5,i)
imshow(cifar10.trainData(:,:,:,i))
end
% Train a simple CNN on the dataset
layers = [
imageInputLayer([32 32 3])
convolution2dLayer(3,32,'Padding','same')
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
fullyConnectedLayer(10)
softmaxLayer
classificationLayer];
options = trainingOptions('sgdm', ...
'MaxEpochs',20, ...
'Verbose',false, ...
'Plots','training-progress');
net = trainNetwork(cifar10.trainData,cifar10.trainLabels,layers,options);
% Test the network on the test set
predictedLabels = classify(net,cifar10.testData);
accuracy = mean(predictedLabels == cifar10.testLabels);
disp("Test accuracy: " + accuracy)
```
In this example, the CIFAR-10 dataset is loaded using the `cifar10Data` function, and the first 20 images from the training set are displayed. Then, a simple CNN is trained on the dataset using the `trainNetwork` function with stochastic gradient descent optimizer. Finally, the trained network is tested on the test set, and the classification accuracy is computed.