2
$\begingroup$

I have a sample of images of chairs and tables and I want to use a neural network using convolutional layer and gpu-acceleration for training. This is what I have so far - how do I train the network?

chairs = Import["C:\\Users\\Murphy\\Samples\\chairs\\*"];
tables = Import["C:\\Users\\Murphy\\Samples\\tables\\*"];

$train = 300;
trainingData = <|"Chairs" -> chairs[[;; $train]], "Tables" -> tables[[;;$train]]|>;
testingData = <|"Chairs" -> chairs[[$train + 1 ;;]], "Tables" -> tables[[$train + 1 ;;]]|>;

module = NetChain[{ ConvolutionLayer[100, {3, 3}], BatchNormalizationLayer[], ElementwiseLayer[Ramp], PoolingLayer[{3, 3}, "PaddingSize" -> 1] }]

net = NetChain[{ module, module, module, module, FlattenLayer[], 500, Ramp, 10, SoftmaxLayer[]}, "Input" -> NetEncoder[{"Image", {32, 32}}], "Output" -> NetDecoder[{"Class", classes}]]

{time, trained} = AbsoluteTiming @ NetTrain[net, trainingData, TargetDevice -> "GPU"];
$\endgroup$
5
  • 1
    $\begingroup$ What have you tried? Have you checked documentation for Classify? That would be a reasonable place to start. $\endgroup$ Commented Nov 6, 2016 at 19:03
  • $\begingroup$ I tried the following: $\endgroup$ Commented Nov 6, 2016 at 19:56
  • $\begingroup$ module = NetChain[{ ConvolutionLayer[100, {3, 3}], BatchNormalizationLayer[], ElementwiseLayer[Ramp], PoolingLayer[{3, 3}, "PaddingSize" -> 1] }] net = NetChain[{ module, module, module, module, FlattenLayer[], 500, Ramp, 10, SoftmaxLayer[]}, "Input" -> NetEncoder[{"Image", {32, 32}}], "Output" -> NetDecoder[{"Class", classes}]] {time, trained} = AbsoluteTiming @ NetTrain[net, trainingData, TargetDevice -> "GPU"]; $\endgroup$ Commented Nov 6, 2016 at 19:56
  • $\begingroup$ from this site: wolfram.com/language/11/neural-networks/… $\endgroup$ Commented Nov 6, 2016 at 19:56
  • $\begingroup$ Training a net for an image classification task from scratch is probably not a good idea when there are pre-trained models that you can use as feature extractors. Have a look at NetModel and google transfer learning $\endgroup$
    – Sascha
    Commented May 29, 2017 at 7:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.