<jupyter_start><jupyter_text>Keras Model Conversion<jupyter_code>%matplotlib inline<jupyter_output><empty_output><jupyter_text>Start a CAS session<jupyter_code>import swat

sess = swat.CAS(cashost, casport)<jupyter_output><empty_output><jupyter_text>Define a MNIST classification model in Keras<jupyter_code>from keras import Sequential
from keras.layers import *
model = Sequential()
model.add(Conv2D(32, kernel_size=(5, 5), strides=(1, 1),
                 activation='relu',padding='same',
                 input_shape=(28,28,1)))
model.add(MaxPooling2D(pool_size=(2, 2), padding='same', strides=(2, 2)))
model.add(Conv2D(64, (5, 5), padding='same', activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2), padding='same'))
model.add(Flatten())
model.add(Dense(1000, activation='relu'))
model.add(Dense(10, activation='softmax'))<jupyter_output><empty_output><jupyter_text>**Note:** DLPy now only support for padding='same'.<jupyter_code>model.summary()<jupyter_output>_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_1 (Conv2D)            (None, 28, 28, 32)        832       
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 14, 14, 32)        0         
_________________________________________________________________
conv2d_2 (Conv2D)            (None, 14, 14, 64)        51264     
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 7, 7, 64)          0         
_________________________________________________________________
flatten_1 (Flatten)          (None, 3136)              0         
_________________________________________________________________
dense_1 (Dense)              (None, 1000)              3137000   
_________________________________________________________________
dense_2 (D[...]<jupyter_text>Convert Keras model to DLPy model<jupyter_code>from dlpy import Model
model1 = Model.from_keras_model(conn=sess, keras_model=model, output_model_table='converted_keras_model')<jupyter_output>NOTE: Added action set 'deeplearn'.
NOTE: Model table is attached successfully!
NOTE: Model is named to "converted_keras_model" according to the model name in the table.<jupyter_text>Now model1 is a DLPy model, fully supporting all the function in DLPy.<jupyter_code>model1.print_summary()
model1.plot_network()
sess.terminate()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12224842767295598, 'fraction_numerical': 0.03852201257861635, 'mean_word_length': 5.475826972010178, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '495094', 'license': 'Apache-2.0', 'n_tokens_mistral': 783, 'n_tokens_neox': 717, 'n_words': 151, 'path': 'examples/Example 3 - Keras Model Conversion.ipynb', 'repo_name': 'rwayne/python-dlpy', 'size': '2544'}