SOL’s TensorFlow integration supports to translate Keras models into SOL models. You can also use methods from tf.math
or tf.nn
but they need to be embedded into the Keras model.
import tensorflow as tf
import sol
import keras
def AlexNet(input_shape=(224, 224, 3), format="channels_last"):
inputs = keras.Input(shape=(input_shape))
model = inputs
model = keras.layers.Conv2D(input_shape=input_shape, filters=64, kernel_size=(11,11), strides=(4,4), padding='same', activation='relu', data_format=format)(model)
model = keras.layers.MaxPooling2D(pool_size=3, strides=2, padding='valid', data_format=format)(model)
model = keras.layers.Conv2D(filters=192, kernel_size=5, strides=1, padding='same', activation='relu', data_format=format)(model)
model = keras.layers.MaxPooling2D(pool_size=3, strides=2, padding="valid", data_format=format)(model)
model = keras.layers.Conv2D(filters=384, kernel_size=3, strides=1, padding="same", activation='relu', data_format=format)(model)
model = keras.layers.Conv2D(filters=256, kernel_size=3, strides=1, padding="same", activation='relu', data_format=format)(model)
model = keras.layers.Conv2D(filters=256, kernel_size=3, strides=1, padding="same", activation='relu', data_format=format)(model)
model = keras.layers.MaxPooling2D(pool_size=3, strides=2, padding="valid", data_format=format)(model)
model = keras.layers.Flatten(data_format=format)(model)
model = keras.layers.Dropout(rate=0.5)(model)
model = keras.layers.Dense(4096, input_shape=(256*6*6,), activation='relu')(model)
model = keras.layers.Dropout(rate=0.5)(model)
model = keras.layers.Dense(4096, activation="relu")(model)
model = keras.layers.Dense(units=args.channels)(model)
return keras.models.Model(inputs=inputs, outputs=model)
with tf.device('/CPU:0'):
model = AlexNet()
sol_model = sol.optimize(model, batch_size=1)
sol_model.convert("x86") # See https://issue.sol-ai.org/289
# Inference
output = sol_model(inputs)
# Training
sol_model.compile(...)
sol_model.fit(inputs, targets)
Please refer to https://www.tensorflow.org/api/stable for how these functions are used. This documentation only contains which layers, functions and tensor functionality is currently implemented within SOL.
Please see the following list of all supported operators.