Code Monkey home page Code Monkey logo

python-dlpy's Introduction

DLPy - SAS Viya Deep Learning API for Python

SAS Deep Learning Icon

An efficient way to apply deep learning methods to image, text, and audio data.

SAS Viya Version Python Version Python Version

Overview

DLPy is a high-level Python library for the SAS Deep learning features available in SAS Viya. DLPy is designed to provide an efficient way to apply deep learning methods to image, text, and audio data. DLPy APIs are created following the Keras APIs with a touch of PyTorch flavor.

Recently Added Features

  • DLPy now supports the DLModelzoo action through the use of MZModel.
  • Real-time plots for hyper-parameter tuning are available with DLModelzoo.
  • New examples are available for APIs with DLModelzoo.
  • Segmentation models can produce PNG/base64 output.
  • Additional pre-defined network architectures are available. Examples include ENet and Efficient-Net.

Prerequisites

  • You must use Python version 3.3 or greater.
  • You must install SAS Scripting Wrapper for Analytics Transfer (SWAT) for Python. You can install the package from PyPI by using the command pip install swat or from the SAS conda repository by using conda install -c sas-institute swat.
  • You must have access to a SAS Viya 4.0 environment that has Machine Learning licensed.
  • To use time series APIs, you must have access to either SAS Econometrics or SAS Visual Forecasting.
  • You must have a user login to your SAS Viya back-end. See your system administrator for details if you do not have a SAS Viya account.
  • It is recommended that you install the open source graph visualization software called Graphviz to enable graphic visualizations of the DLPy deep learning models.
  • Install DLPy using pip install sas-dlpy or conda install -c sas-institute sas-dlpy.

SAS Viya and DLPY Versions

DLPy versions are aligned with SAS Viya versions. Below is the versions matrix.

DLPy SAS Viya
1.3.x 4.0
1.2.x 3.5
1.1.x 3.4
1.0.x 3.4

The table above can be read as follows: DLPy versions between 1.0 (inclusive) to 1.1 (exclusive) are designed to work with the SAS Viya 3.4.

External Libraries

The following versions of external libraries are supported:

  • ONNX: versions >= 1.5.0
  • Keras: versions >= 2.1.3

Getting Started

To connect to a SAS Viya server, import SWAT and use the swat.CAS class to create a connection:

Note: The default CAS port is 5570.

>>> import swat
>>> sess = swat.CAS('mycloud.example.com', 5570)

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

Import DLPy model functions:

>>> from dlpy import Model, Sequential
>>> from dlpy.layers import *

Use DLPy to create a sequential model and name it Simple_CNN:

>>> model1 = Sequential(sess, model_table = 'Simple_CNN')

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

>>> model1.add(InputLayer(3,224,224))

NOTE: Input layer added.

Add a 2-D convolution layer and a pooling layer:

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

>>> model1.add(Conv2d(8,7))

NOTE: Convolutional layer added.

# Add Pooling Layer of size 2

>>> model1.add(Pooling(2))

NOTE: Pooling layer added.

Add an additional pair of 2-D convolution and pooling layers:

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

>>> model1.add(Conv2d(8,7))

NOTE: Convolutional layer added.

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

>>> model1.add(Pooling(2))

NOTE: Pooling layer added.

Add a fully connected layer:

# Add Fully-Connected Layer with 16 units

>>> model1.add(Dense(16))

NOTE: Fully-connected layer added.

Finally, add the output layer:

# Add an output layer that has 2 nodes and uses
# the Softmax activation function 

>>> model1.add(OutputLayer(act='softmax',n=2))

NOTE: Output layer added.
NOTE: Model compiled successfully 

Additional Resources

Contributing

Have something cool to share? We gladly accept pull requests on GitHub! See the Contributor Agreement for details.

Licensing

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You can obtain a copy of the License at LICENSE.txt

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

python-dlpy's People

Contributors

adstev avatar aistatistics avatar arharvey918 avatar aviolante avatar bensloane avatar carolinepotts avatar chiprobie avatar chungdz avatar cjdinger avatar collinux avatar dlpysas avatar dxq77dxq avatar ethem-kinginthenorth avatar eusdougc avatar jld23 avatar jlwalke2 avatar kybowm avatar mcech99 avatar priyanshu-server avatar riow1983 avatar sabisw avatar sasxianhu avatar shlongsas avatar wenyushi avatar xingdusas avatar yg2288 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-dlpy's Issues

the Design of the model_type attribute from Sequential and Model object

Currently, the default model_type is 'CNN', and only when we add RNN layer (layer.type=='Recurrent' or isinstance(layer, Bidirectional)), then the model_type is modified to be 'RNN'.

One issue of this is that if we are just building a feed forward DNN net, then the model_type is still 'CNN' and can be problematic.

One potential fix might be adding conditions that when we add layer with layer.type=='fc', we change the model_type to 'DNN'. But I am not sure this is a good solution down the road, since we might have CNN layer followed by fully connected layer, or CNN and RNN mixed models in future, where in these cases the model_type become an ambiguous definition (do we call the model CNN?RNN?DNN?)

Anyone any ideas?

wrong model weights saved

Hi,
i tried doing k-fold cross validation while training to fine tune the weights. on the 1st fold i got an error of 17% and at the last fold i got the error down to 4%. when i save the model weights and try to load them, i notice that i get an error rate associated with the first fold (17%). is there something am doing wrong?

Here's the code:
for i in range(18):

    print("Training pass "+str(i))

    train, valid = sampling(conn)
    
    model.fit(data=train, inputs='Survey_Verbatim', texts='Survey_Verbatim', target='Section', nominals='Section', valid_table=valid,
            text_parms=TextParms(init_input_embeddings='glove'), record_seed=909455678,
            mini_batch_size=1, max_epochs=n_epochs, lr=0.01, log_level=2)
    
    n_epochs = 10

    model.save_to_table('/bigdisk/lax/shpath/')

support tensorboard

with some callbacks, we could use tensorboard to visualize our DL models and training history.

support bio-image

In the future, we need to support biomedical applications of deep learning via dlpy.

Issue with YOLOv2 model training

I am trying to train a tiny yolov2 model on a very small dataset. I have defined the model DAG and did the training as well using pre-trained weights from Darknet model. However, I face issues when I try to score the model. I am scoring the model on training set but face an error which I am unable to resolve.

This is the issue:
image

Any suggestions on resolving this issue?

Thanks!!

ETA on this?

Hello SAS devs,

I was browsing the sassoftware group and came across this repo. The description sounds great and I was just wondering if you had an ETA for adding content to it? (Github is telling me the repo is empty)

Thanks!
Ivan

Broken "Getting Started with DLPy" example in readme

The below example in Readme doesn't work without "from dlpy.layers import *"

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

model1.add(InputLayer(3,224,224))

NOTE: Input layer added.

Custom dataset loaders

It would be convenient to have dataset loaders like keras.datasets, torchvision.datasets, etc

Add examples for entity embedding

entity embedding is one of the effective methods to featurize high cardinality variables. This is especially important in the AutoML space. It will be very useful to have an example using dlpy (scores of them using e.g. tensorflow are available online).

improving esppy integration

One specific task is:
model.deploy can deploy the astore model but we need one API to load them
with open('c:/temp/Simple_CNN.astore', mode='rb') as file:
fileContent = file.read()
store_ = sw.blob(fileContent)
s.astore.upload(rstore='test',store = store_)
The above codes are repeated many times. I think we should have a new API to upload the astore model.

get_feature_maps needs a better error message when data subset is empty

When using example1 things work great till I get to:

Model1: View Feature Maps
Feature maps display the output activations for a given filter. The following code uses the test data from the Model1 example to generate and display feature map data. First, create the feature map data. This example uses the test data and filters for images labeled Dolphin. The idx=0 setting indicates that the row 0 index data should be used to construct the feature maps.
In [33]:

model1.get_feature_maps(data=te_img, label='Dolphin', idx=0)

DLPyError Traceback (most recent call last)
in
----> 1 model1.get_feature_maps(data=te_img, label='Dolphin', idx=0)

/usr/local/lib/python3.6/site-packages/dlpy/model.py in get_feature_maps(self, data, label, idx, image_id, **kwargs)
1756 if idx >= uid.shape[0]:
1757 raise DLPyError('image_id should be an integer between 0'
-> 1758 ' and {}.'.format(uid.shape[0] - 1))
1759 uid_value = uid.iloc[idx, 1]
1760 uid_name = uid.columns[1]

DLPyError: image_id should be an integer between 0 and -1.

when I change label from 'Dolphin' to 'dolphin' it works. I think this function should provide a better error message for this case.

Unable to import weights from HDF5 file

The weights saved directly from Keras (e.g. model.save('my_weights.h5') cannot be imported by DLPy with

from_keras_model(s, model, output_model_table='Weights', include_weights=True, input_weights_file='my_weights.h5')

The error thrown indicates that an attribute cannot be found, although it is present. The code is written assuming that the attribute is present at the highest level of the HDF5 file tree. Apparently when the HDF5 file is written by Keras directly, the model weights and the attribute in question reside at a lower level in the HDF5 file tree. The code simply needs to scan the tree to look for the attribute and then proceed with the processing.

Error from Example4-KerasModelConversion.ipynb

In example 4, the command below fails:
model1 = Model.from_keras_model(conn=sess, keras_model=model0, output_model_table='converted_keras_model')

This is the error message:

ValueError Traceback (most recent call last)
in
----> 1 model1 = Model.from_keras_model(conn=sess, keras_model=model0, output_model_table='converted_keras_model')

~\AppData\Local\Continuum\anaconda3\envs\jupyter\lib\site-packages\dlpy\model.py in from_keras_model(cls, conn, keras_model, output_model_table, include_weights, input_weights_file)
274 model_name = model_table_opts['name']
275
--> 276 output_code = keras_to_sas(model=keras_model, model_name=model_name)
277 exec(output_code)
278 temp_name = conn

~\AppData\Local\Continuum\anaconda3\envs\jupyter\lib\site-packages\dlpy\model_conversion\sas_keras_parse.py in keras_to_sas(model, model_name)
53 if (class_name in computation_layer_classes):
54 comp_layer_name = find_previous_computation_layer(
---> 55 model, layer.name, computation_layer_classes)
56 source_str = make_source_str(comp_layer_name)
57 src_layer.update({layer.name: source_str})

~\AppData\Local\Continuum\anaconda3\envs\jupyter\lib\site-packages\dlpy\model_conversion\sas_keras_parse.py in find_previous_computation_layer(model, layer_name, computation_layer_list)
678 node_config = layer._inbound_nodes[0].get_config()
679 for lname in node_config['inbound_layers']:
--> 680 tmp_layer = model.get_layer(name=lname)
681 prev_layer = tmp_layer
682 while (tmp_layer.class.name.lower() not in computation_layer_list):

~\AppData\Local\Continuum\anaconda3\envs\jupyter\lib\site-packages\keras\engine\network.py in get_layer(self, name, index)
356 return layer
357
--> 358 raise ValueError('No such layer: ' + name)
359
360 @Property

ValueError: No such layer: conv2d_1_input

Loading model from sashdat meets error.

model3 = Model.from_sashdat(conn = s, path='/home/sas/DEMO/driver_image/data_scripts/vgg/VGG16_model.sashdat')

It tells me that :

ERROR: The caslib Caslib_qErNjR is a duplicate, parent or subpath of caslib Caslib_Eutm6c.
ERROR: Could not add caslib 'Caslib_qErNjR'. Make sure that the caslib does not already exist and that you have permissions to add caslibs to Cloud Analytic Services.
ERROR: The action stopped due to errors.
ERROR: The caslib 'Caslib_qErNjR' does not exist in this session.
ERROR: The action stopped due to errors.
ERROR: The file or path 'Model_bwlxjJ' is not available in the file system.
ERROR: Table 'Model_bwlxjJ' could not be loaded.
ERROR: Failure opening table 'Model_bwlxjJ': A table could not be loaded.
ERROR: The action stopped due to errors.

What should I do?

Model.from_keras_model throws error "Model layer name not found in Keras definition."

I'm trying to import a Keras model via dlpy, but i'm getting an error I just can't seem to get past!

My error is when i'm trying to load in the weights. Here's my code:

#import packages and connect to server
import swat
import pandas as pd
from dlpy import Model, Sequential
from dlpy.model import *
sess = swat.CAS('rpcger01075.exnet.sas.com', 5570, username='sasdemo', password='Orion123')

#read in dataset and create table - if there's a way to create an empty table via SWAT please show me
churn_df = pd.read_csv('C:\Users\sdktgo\OneDrive - SAS\Code\Data from Kaggle\bank churn\Churn_Modelling.csv')
churn_df.head()

pd.set_option('display.float_format', lambda x: '%.2f' % x)

#upload table to server
out=sess.upload(churn_df,casout=dict(name='Simple_CNN',caslib='casuser'))

#make model
model1 = Sequential(sess, model_table = 'Simple_CNN')
#import weights - fails
model1.load_weights_from_keras('/media/my_model.h5', labels=False)
#output from loading weights:
#note: Model weights attached successfully!
#error: Model layer name not found in Keras definition.
#error: The action stopped due to errors.

Here's the packages I currently use to run in an anaconda env.
Highlight: i'm using keras 2.1.6 as you can se.
absl-py==0.6.1
alabaster==0.7.11
asn1crypto==0.24.0
astor==0.7.1
astroid==2.0.4
Babel==2.6.0
backcall==0.1.0
bleach==2.1.4
certifi==2018.8.24
cffi==1.11.5
chardet==3.0.4
cloudpickle==0.5.5
colorama==0.3.9
cryptography==2.3.1
cycler==0.10.0
decorator==4.3.0
docutils==0.14
entrypoints==0.2.3
gast==0.2.0
graphviz==0.8.4
grpcio==1.16.1
h5py==2.8.0
html5lib==1.0.1
idna==2.7
imagesize==1.1.0
ipykernel==4.10.0
ipython==6.5.0
ipython-genutils==0.2.0
isort==4.3.4
jedi==0.12.1
Jinja2==2.10
jsonschema==2.6.0
jupyter-client==5.2.3
jupyter-core==4.4.0
Keras==2.1.6
Keras-Applications==1.0.6
Keras-Preprocessing==1.0.5
keyring==13.2.1
kiwisolver==1.0.1
lazy-object-proxy==1.3.1
Markdown==3.0.1
MarkupSafe==1.0
matplotlib==3.0.0
mccabe==0.6.1
mistune==0.8.3
mkl-fft==1.0.6
mkl-random==1.0.1
nbconvert==5.3.1
nbformat==4.4.0
numpy==1.15.2
numpydoc==0.8.0
olefile==0.46
packaging==17.1
pandas==0.23.4
pandocfilters==1.4.2
parso==0.3.1
pickleshare==0.7.4
Pillow==5.2.0
prompt-toolkit==1.0.15
protobuf==3.6.1
psutil==5.4.7
pycodestyle==2.4.0
pycparser==2.19
pyflakes==2.0.0
Pygments==2.2.0
pylint==2.1.1
pyOpenSSL==18.0.0
pyparsing==2.2.1
PySocks==1.6.8
python-dateutil==2.7.3
pytz==2018.5
pywin32==223
PyYAML==3.13
pyzmq==17.1.2
QtAwesome==0.4.4
qtconsole==4.4.1
QtPy==1.5.0
requests==2.19.1
rope==0.11.0
sas-dlpy==1.0.0
scipy==1.1.0
simplegeneric==0.8.1
six==1.11.0
snowballstemmer==1.2.1
Sphinx==1.7.9
sphinxcontrib-websupport==1.1.0
spyder==3.3.1
spyder-kernels==0.2.6
swat==1.5.0
tensorboard==1.12.0
tensorflow==1.12.0
termcolor==1.1.0
testpath==0.3.1
tornado==5.1.1
traitlets==4.3.2
typed-ast==1.1.0
urllib3==1.23
wcwidth==0.1.7
webencodings==0.5.1
Werkzeug==0.14.1
win-inet-pton==1.0.1
win-unicode-console==0.5
wincertstore==0.2
wrapt==1.10.11

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.