deepLearn addLayer

Standard: Building a CNN for Product Image Classification

Scénario de test & Cas d'usage

Business Context

A retail company wants to build a Convolutional Neural Network (CNN) to automatically classify images of its products into categories like 'shirts', 'shoes', and 'accessories'. This test scenario simulates the foundational step of constructing the model architecture layer by layer.
About the Set : deepLearn

Creation and training of deep neural networks.

Discover all actions of deepLearn
Data Preparation

This scenario does not require pre-existing data in a table, as the 'addLayer' action operates on a model definition table. We will create an empty model table named 'product_cnn_model' to start.

Copied!
1/* The action builds the model architecture in a CAS table. No
2data step is needed for this specific test. */

Étapes de réalisation

1
Initialize the model by adding the first layer, an INPUT layer, to a new model table named 'product_cnn_model'. This layer is configured for 128x128 pixel color images.
Copied!
1PROC CAS;
2DEEPLEARN.addLayer /
3 modelTable={name='product_cnn_model', replace=true}
4 layer={type='input', nchannels=3, width=128, height=128, scale=1.0/255.0}
5 name='data';
6RUN;
2
Add the first Convolutional layer, named 'conv1', which takes the 'data' layer as input. It uses 16 filters and a ReLU activation function.
Copied!
1PROC CAS;
2DEEPLEARN.addLayer /
3 modelTable={name='product_cnn_model'}
4 name='conv1'
5 layer={type='convolution', nFilters=16, width=3, height=3, stride=1, act='relu'}
6 srcLayers={'data'};
7RUN;
3
Add a Max Pooling layer, named 'pool1', to down-sample the feature maps from the 'conv1' layer.
Copied!
1PROC CAS;
2DEEPLEARN.addLayer /
3 modelTable={name='product_cnn_model'}
4 name='pool1'
5 layer={type='pooling', width=2, height=2, stride=2, pool='max'}
6 srcLayers={'conv1'};
7RUN;
4
Add a Fully Connected layer, named 'fc1', with 128 neurons.
Copied!
1PROC CAS;
2DEEPLEARN.addLayer /
3 modelTable={name='product_cnn_model'}
4 name='fc1'
5 layer={type='fullconnect', n=128, act='relu'}
6 srcLayers={'pool1'};
7RUN;
5
Add the final OUTPUT layer for classification, with 3 neurons (for 3 product categories) and a Softmax activation.
Copied!
1PROC CAS;
2DEEPLEARN.addLayer /
3 modelTable={name='product_cnn_model'}
4 name='output'
5 layer={type='output', n=3, act='softmax'}
6 srcLayers={'fc1'};
7RUN;

Expected Result


A complete, sequential CNN model architecture is successfully created in the 'product_cnn_model' CAS table. The final model summary should show five layers: 'data' (Input), 'conv1' (Convolution), 'pool1' (Pooling), 'fc1' (FullConnect), and 'output' (Output), connected in that order.