Does patternnet support single precision data?
5 views (last 30 days)
Show older comments
MathWorks Support Team
on 29 Dec 2021
Answered: MathWorks Support Team
on 20 Jan 2022
I created a classic neural network using "patternnet". My GPU is optimized for single precision data, so how can I train the neural network using single precision data?
Accepted Answer
MathWorks Support Team
on 29 Dec 2021
Unfortunately, single precision data is unsupported for "patternnet".
We advise you to use the new deep learning interface, which uses single precision by default. Please see below for code that creates a deep neural network with similar architecture to "patternnet" using the "iris" dataset in MATLAB:
[x,t] = iris_dataset;\nrng(0)\n[~, nData] = size(x);\n\n% Randomizing the data\nrandIDs = randperm(nData);\nXAllData = x(:,randIDs);\n\n% Data split for training and testing \nY = categorical(vec2ind(t)');\nXTrain = XAllData(:,1:100)';\nYTrain = Y(randIDs(1:100));\nXTest = XAllData(:,101:150)';\nYTest = Y(randIDs(101:150));\n\n% Defining the shallow neural network layers \nlayers = [featureInputLayer(4, "Name", "Input", "Normalization", "rescale-symmetric");...\n fullyConnectedLayer(10, "Name", "firstHidden");\n tanhLayer("Name","tanHyperbolicLayer");\n fullyConnectedLayer(3, "Name", "OutputFC")\n softmaxLayer\n classificationLayer("Name","Output")];\n\n% Setting up training options\noptions = trainingOptions('sgdm', ...\n 'InitialLearnRate',1e-2, ...\n 'MaxEpochs',500,...\n 'Verbose',false, ...\n "Shuffle","every-epoch", ...\n "Plots","training-progress", ...\n "ValidationData",{XTest,YTest});\n\n% Train the network\nnetDLT = trainNetwork(XTrain,YTrain,layers,options);
For more information about the available layers in the Deep Learning Toolbox, you may refer to the following documentation links:
For more information about the "trainingOptions" and "trainNetwork" functions used in the above code, you may refer to the following documentation links:
To learn more about the new deep learning interface, you may refer to the following example:
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!