Skip to content

Commit

Permalink
MLP MNIST model for fully updatable example
Browse files Browse the repository at this point in the history
  • Loading branch information
SichangHe committed Jan 2, 2024
1 parent 3e78fa6 commit 1e00554
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 24 deletions.
20 changes: 2 additions & 18 deletions convert_model/mnist_eg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,13 @@
n_classes = 10


def conv_layer():
return k.layers.Conv2D(
32,
(3, 3),
activation="relu",
kernel_initializer="he_uniform",
)


def pool_layer():
return k.layers.MaxPool2D((2, 2), strides=(2, 2))


def mnist_model():
model = k.Sequential(
[
k.Input(shape=in_shape),
conv_layer(),
pool_layer(),
conv_layer(),
pool_layer(),
k.layers.Flatten(),
k.layers.Dense(500, activation="relu", kernel_initializer="he_uniform"),
k.layers.Dense(128, activation="relu"),
k.layers.Dense(500, activation="relu"),
k.layers.Dense(n_classes),
]
)
Expand Down
2 changes: 1 addition & 1 deletion convert_model/mnist_eg/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def main():
mlmodel = convert(model)
builder = nn_builder(mlmodel)
config_builder(builder)
try_make_layers_updatable(builder, 2)
try_make_layers_updatable(builder)
builder.inspect_layers()
save_builder(builder, COREML_FILE)
print(f"Successfully converted to Core ML model at {COREML_FILE}.")
Expand Down
8 changes: 3 additions & 5 deletions upload_mnist_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
tflite_file = "mnist.tflite"
coreml_file = "mnist.mlmodel"
name = "mnist_unified"
tflite_layers = [1152, 128, 36864, 128, 1600000, 2000, 20000, 40]
tflite_layers = [401408, 512, 256000, 2000, 20000, 40]
coreml_layers = [
{"name": "sequential/conv2d/BiasAdd", "type": "weights", "updatable": False},
{"name": "sequential/conv2d/BiasAdd", "type": "bias", "updatable": False},
{"name": "sequential/conv2d_1/BiasAdd", "type": "weights", "updatable": False},
{"name": "sequential/conv2d_1/BiasAdd", "type": "bias", "updatable": False},
{"name": "sequential/dense/BiasAdd", "type": "weights", "updatable": True},
{"name": "sequential/dense/BiasAdd", "type": "bias", "updatable": True},
{"name": "sequential/dense_1/BiasAdd", "type": "weights", "updatable": True},
{"name": "sequential/dense_1/BiasAdd", "type": "bias", "updatable": True},
{"name": "Identity", "type": "weights", "updatable": True},
{"name": "Identity", "type": "bias", "updatable": True},
]
Expand Down

0 comments on commit 1e00554

Please sign in to comment.