# Getting Started¶

Before you can use the DLPy package, you will need a running CAS server and the SWAT package. The SWAT package can make connections using the binary or HTTP protocol. Between these two options, the binary protocol will give you better performance.

Other than the CAS host and port, you just need a user name and password to connect. User names and passwords can be implemented in various ways, so you may need to see your system administrator on how to acquire an account.

To connect to a CAS server, you simply import SWAT and use the swat.CAS class to create a connection.

In [1]: import swat

In [2]: sess = swat.CAS(host, port, userid, password)


Next, import the DLPy package, and then build a simple convolutional neural network (CNN) model.

In [3]: from dlpy import Model, Sequential


Import DLPy layer functions

In [4]: from dlpy.layers import *


Use DLPy to create a sequential model and name it ‘Simple_CNN’

In [5]: model1 = Sequential(sess, model_table='Simple_CNN')


Now define an input layer to add to model1

# The input shape contains RGB images (3 channels)
# The model images are 224 px in height and 224 px in width


Now, add a 2D convolution layer and a pooling layer.

# Add 2-Dimensional Convolution Layer to model1
# that has 8 filters and a kernel size of 7.

# Add Pooling Layer of size 2


# Add another 2D convolution Layer that has 8 filters
# and a kernel size of 7

# Add a pooling layer of size 2 to
# complete the second pair of layers.


# Add Fully-Connected Layer with 16 units


# Add an output layer that has 2 nodes and uses
# the Softmax activation function
NOTE: Model compiled successfully.


Display a print summary of the table.

In [13]: model1.print_summary()
Layer Id    Layer    Type  Kernel Size  Stride Activation    Output Size        Number of Parameters FLOPS(forward pass)
0        0   Input1   input                            None  (224, 224, 3)                      (0, 0)                   0
1        1  Convo.1   convo       (7, 7)  (1, 1)       Relu  (224, 224, 8)                   (1176, 8)            59006976
2        2    Pool1    pool       (2, 2)  (2, 2)        Max  (112, 112, 8)                      (0, 0)                   0
3        3  Convo.2   convo       (7, 7)  (1, 1)       Relu  (112, 112, 8)                   (3136, 8)            39337984
4        4    Pool2    pool       (2, 2)  (2, 2)        Max    (56, 56, 8)                      (0, 0)                   0
5        5    F.C.1      fc  (25088, 16)               Relu             16                 (401408, 0)              401408
6        6  Output1  output                         Softmax              2                     (32, 2)                   0
7                                                                           Total number of parameters         Total FLOPS
8  Summary                                                                                     405,770          98,746,368
Out[13]:
Layer Id    Layer    Type  Kernel Size  Stride Activation    Output Size        Number of Parameters FLOPS(forward pass)
0        0   Input1   input                            None  (224, 224, 3)                      (0, 0)                   0
1        1  Convo.1   convo       (7, 7)  (1, 1)       Relu  (224, 224, 8)                   (1176, 8)            59006976
2        2    Pool1    pool       (2, 2)  (2, 2)        Max  (112, 112, 8)                      (0, 0)                   0
3        3  Convo.2   convo       (7, 7)  (1, 1)       Relu  (112, 112, 8)                   (3136, 8)            39337984
4        4    Pool2    pool       (2, 2)  (2, 2)        Max    (56, 56, 8)                      (0, 0)                   0
5        5    F.C.1      fc  (25088, 16)               Relu             16                 (401408, 0)              401408
6        6  Output1  output                         Softmax              2                     (32, 2)                   0
7                                                                           Total number of parameters         Total FLOPS
8  Summary                                                                                     405,770          98,746,368


Use the open source utility Graphviz to display a plot of the model network. Graphviz is available here: https://www.graphviz.org/download/. If you do not have Graphviz, skip this instruction.

In [14]: model1.plot_network()
Out[14]: <graphviz.dot.Digraph at 0x275959f8908>