We are currently looking to see if we can convert a Keras model with ml4f. The current model is exported Tensorflow Micro to run on the micro:bit for the Next Gen project and we wanted to see how it'd perform with ml4f.
Layer: Conv2D; data: [250,3,1]@0 => [76,1,20]@1520 1237604 cycles (13.7% opt)
_________________________________________________________________
Layer (type) Output shape Param #
=================================================================
input_1 (InputLayer) [null,250,3] 0
_________________________________________________________________
reshape (Reshape) [null,250,3,1] 0
_________________________________________________________________
conv2d (Conv2D) [null,76,1,20] 1520
_________________________________________________________________
activation (Activation) [null,76,1,20] 0
_________________________________________________________________
batch_normalization (BatchNo [null,76,1,20] 80
_________________________________________________________________
average_pooling2d (AveragePo [null,38,1,20] 0
_________________________________________________________________
sequential (Sequential) [null,11,1,64] 1856
_________________________________________________________________
sequential_1 (Sequential) [null,2,1,64] 4864
_________________________________________________________________
flatten (Flatten) [null,128] 0
_________________________________________________________________
transfer_dense_1 (Dense) [null,32] 4128
_________________________________________________________________
dropout (Dropout) [null,32] 0
_________________________________________________________________
transfer_dense_out (Dense) [null,4] 132
_________________________________________________________________
softmax (Softmax) [null,4] 0
=================================================================
Total params: 12580
Trainable params: 12284
Non-trainable params: 296
_________________________________________________________________
Layer: InputLayer; data: [250,3]@0 => [250,3]@0 (no computation)
Layer: Reshape; data: [250,3]@0 => [250,3,1]@0 (no computation)
[ null, 250, 3, 1 ] [ null, 76, 1, 20 ] {
filters: 20,
kernelInitializer: {
className: 'VarianceScaling',
config: { scale: 1, mode: 'fanAvg', distribution: 'uniform', seed: null }
},
kernelRegularizer: null,
kernelConstraint: null,
kernelSize: [ 25, 3 ],
strides: [ 3, 1 ],
padding: 'valid',
dataFormat: 'channelsLast',
dilationRate: [ 1, 1 ],
activation: 'linear',
useBias: true,
biasInitializer: { className: 'Zeros', config: {} },
biasRegularizer: null,
activityRegularizer: null,
biasConstraint: null,
name: 'conv2d',
trainable: true
}
Layer: Conv2D; data: [250,3,1]@0 => [76,1,20]@1520 1237604 cycles (13.7% opt)
Error: Unsupported operator or config: layer: Activation
at unsupported (/Users/microbit-carlos/workspace/mbef/microbit-ml-adl/node_modules/ml4f/built/ml4f.js:2605:15)
at compileModelCore (/Users/microbit-carlos/workspace/mbef/microbit-ml-adl/node_modules/ml4f/built/ml4f.js:3074:17)
at compileAndTest (/Users/microbit-carlos/workspace/mbef/microbit-ml-adl/node_modules/ml4f/built/ml4f.js:4015:24)
at Object.compileModelAndFullValidate (/Users/microbit-carlos/workspace/mbef/microbit-ml-adl/node_modules/ml4f/built/ml4f.js:3982:16)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async processModelFile (/Users/microbit-carlos/workspace/mbef/microbit-ml-adl/node_modules/ml4f/built/cli/cli.js:124:66)
at async Object.mainCli (/Users/microbit-carlos/workspace/mbef/microbit-ml-adl/node_modules/ml4f/built/cli/cli.js:180:9)
We are in the process to open source everything, but right now the repos are still private. @mmoskal in the meantime I've invited you to the repositories in case you'd like have a look at the code creating the model and the model itself:
mlf4f full output can be expanded here
$ npx ml4f --output ml4fbuild --debug models/transfer_finetuned_model_dw250_c1_5.h5
RUN tensorflowjs_converter --input_format keras --output_format tfjs_layers_model models/transfer_finetuned_model_dw250_c1_5.h5 ml4fbuild/converted.tfjs
2024-03-07 17:21:21.805144: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
RUN OK
_________________________________________________________________
Layer (type) Output shape Param #
=================================================================
input_1 (InputLayer) [null,250,3] 0
_________________________________________________________________
reshape (Reshape) [null,250,3,1] 0
_________________________________________________________________
conv2d (Conv2D) [null,76,1,20] 1520
_________________________________________________________________
activation (Activation) [null,76,1,20] 0
_________________________________________________________________
batch_normalization (BatchNo [null,76,1,20] 80
_________________________________________________________________
average_pooling2d (AveragePo [null,38,1,20] 0
_________________________________________________________________
sequential (Sequential) [null,11,1,64] 1856
_________________________________________________________________
sequential_1 (Sequential) [null,2,1,64] 4864
_________________________________________________________________
flatten (Flatten) [null,128] 0
_________________________________________________________________
transfer_dense_1 (Dense) [null,32] 4128
_________________________________________________________________
dropout (Dropout) [null,32] 0
_________________________________________________________________
transfer_dense_out (Dense) [null,4] 132
_________________________________________________________________
softmax (Softmax) [null,4] 0
=================================================================
Total params: 12580
Trainable params: 12284
Non-trainable params: 296
_________________________________________________________________
Validating partial models...
testing Conv2D: [250,3,1] => [76,1,20]...
_________________________________________________________________
Layer (type) Output shape Param #
=================================================================
conv2d (Conv2D) [null,76,1,20] 1520
=================================================================
Total params: 1520
Trainable params: 1520
Non-trainable params: 0
_________________________________________________________________
[ null, 250, 3, 1 ] [ null, 76, 1, 20 ] {
filters: 20,
kernelInitializer: {
className: 'VarianceScaling',
config: { scale: 1, mode: 'fanAvg', distribution: 'uniform', seed: null }
},
kernelRegularizer: null,
kernelConstraint: null,
kernelSize: [ 25, 3 ],
strides: [ 3, 1 ],
padding: 'valid',
dataFormat: 'channelsLast',
dilationRate: [ 1, 1 ],
activation: 'linear',
useBias: true,
biasInitializer: { className: 'Zeros', config: {} },
biasRegularizer: null,
activityRegularizer: null,
biasConstraint: null,
name: 'conv2d',
trainable: true,
batchInputShape: [ null, 250, 3, 1 ],
dtype: 'float32'
}
Layer: Conv2D; data: [250,3,1]@0 => [76,1,20]@750 1237084 cycles (13.7% opt)
total cycles: 1237084 (14.727ms at 84MHz)
Test output Float32Array(1520) [
-0.6543942093849182, -1.5987398624420166, 4.679758071899414,
0.3610239624977112, 0.5543566942214966, -1.8997654914855957,
-1.243112564086914, 0.3233872354030609, -3.5152804851531982,
-1.9008723497390747, 1.3731722831726074, -0.9202901124954224,
-3.6674437522888184, -2.608750104904175, 2.9830570220947266,
1.1572322845458984, -1.3406109809875488, -2.059849977493286,
-6.13929557800293, -2.2732644081115723, -3.8865113258361816,
3.6685848236083984, 0.3366440534591675, -0.7717487812042236,
-1.2727856636047363, 1.4740164279937744, -2.459336042404175,
-3.834590196609497, 3.2260305881500244, 1.4937301874160767,
-0.23774562776088715, 0.16589975357055664, 1.9998061656951904,
3.917616605758667, 1.1070278882980347, -0.13852745294570923,
2.6381006240844727, -6.204899311065674, 1.2381953001022339,
-0.7501019835472107, 3.885274648666382, 1.8398363590240479,
-1.3074214458465576, 0.49256426095962524, -4.247359275817871,
-2.6867311000823975, -3.137449026107788, -0.7782284021377563,
0.4831981658935547, 0.046072423458099365, -3.9969711303710938,
-6.7271270751953125, 1.109713077545166, 1.979538083076477,
1.2244105339050293, 1.5509064197540283, 3.8467490673065186,
3.6345109939575195, -2.223506212234497, -1.3395938873291016,
4.270734786987305, -2.9101133346557617, 2.987860918045044,
-1.573803424835205, -0.9366786479949951, 4.285688400268555,
2.9084129333496094, 1.4391733407974243, -2.573387861251831,
1.3292585611343384, 4.322605133056641, 2.8347506523132324,
-0.7743972539901733, 1.4138282537460327, -3.13751482963562,
-1.7189602851867676, 5.751336574554443, -0.8854779005050659,
5.005840301513672, -1.3907403945922852, 0.10051273554563522,
1.4028103351593018, 3.4799532890319824, -0.1328551471233368,
2.20620059967041, 1.5114022493362427, -2.716763734817505,
-3.8681015968322754, 2.4142608642578125, -4.160702228546143,
-0.9808037281036377, 3.083132743835449, 5.198317050933838,
-7.352654933929443, 0.9993666410446167, 0.6479471921920776,
-5.731224060058594, -1.0054080486297607, -0.2493310570716858,
4.042226791381836,
... 1420 more items
]
also with no activation...
_________________________________________________________________
Layer (type) Output shape Param #
=================================================================
conv2d (Conv2D) [null,76,1,20] 1520
=================================================================
Total params: 1520
Trainable params: 1520
Non-trainable params: 0
_________________________________________________________________
[ null, 250, 3, 1 ] [ null, 76, 1, 20 ] {
filters: 20,
kernelInitializer: {
className: 'VarianceScaling',
config: { scale: 1, mode: 'fanAvg', distribution: 'uniform', seed: null }
},
kernelRegularizer: null,
kernelConstraint: null,
kernelSize: [ 25, 3 ],
strides: [ 3, 1 ],
padding: 'valid',
dataFormat: 'channelsLast',
dilationRate: [ 1, 1 ],
activation: 'linear',
useBias: true,
biasInitializer: { className: 'Zeros', config: {} },
biasRegularizer: null,
activityRegularizer: null,
biasConstraint: null,
name: 'conv2d',
trainable: true,
batchInputShape: [ null, 250, 3, 1 ],
dtype: 'float32'
}
Layer: Conv2D; data: [250,3,1]@0 => [76,1,20]@750 1237084 cycles (13.7% opt)
total cycles: 1237084 (14.727ms at 84MHz)
Test output Float32Array(1520) [
0.20257160067558289, 1.6592046022415161, 0.9287804961204529,
-3.1827306747436523, 1.4833396673202515, -3.6374905109405518,
-1.307392954826355, 6.236717700958252, 3.702615737915039,
1.3866358995437622, 0.5585417747497559, 2.096182346343994,
3.0644049644470215, -0.08257564902305603, 4.523300647735596,
-2.895974636077881, 3.872354507446289, -4.038097381591797,
-0.6986581087112427, -3.5762250423431396, 2.978877067565918,
2.5779786109924316, 6.626351833343506, 1.472097635269165,
-1.8630352020263672, 3.0687551498413086, -1.8141788244247437,
-2.99149227142334, -0.8446914553642273, 2.2210276126861572,
-4.096405506134033, 0.5246019959449768, 0.1524740755558014,
-1.3061646223068237, 1.8644702434539795, -0.3695562481880188,
4.641002178192139, 4.524179935455322, 0.9788439869880676,
1.153949499130249, -0.38989484310150146, -2.404341459274292,
0.14737750589847565, 0.22244125604629517, -3.4457149505615234,
3.8636856079101562, 2.3340110778808594, -3.4669487476348877,
-0.12754786014556885, 4.619879245758057, 1.9956555366516113,
-1.1953635215759277, 2.8809518814086914, 5.2587995529174805,
-0.3462246060371399, -0.5038015842437744, -2.4923758506774902,
-2.686619520187378, -0.029805511236190796, -1.2059459686279297,
-1.4842612743377686, 0.2929033041000366, 1.2422633171081543,
4.855828285217285, 0.17732632160186768, 1.7062472105026245,
4.689605712890625, 3.9562244415283203, 6.329590797424316,
2.384840965270996, 4.796898365020752, 6.4863691329956055,
0.5371824502944946, 1.8567073345184326, -3.7192957401275635,
0.3204510807991028, 0.5646308660507202, -2.6706080436706543,
-0.48085135221481323, -0.768836259841919, 3.879024028778076,
-0.6133213043212891, -2.619417667388916, -4.077198505401611,
2.1510939598083496, -1.627598524093628, -0.12062239646911621,
-2.6387510299682617, -5.229059219360352, -0.20706093311309814,
0.10825824737548828, -1.6642056703567505, -5.233810901641846,
-1.6764822006225586, -8.184328079223633, 1.6689088344573975,
2.380209445953369, 0.8928894400596619, -1.1060518026351929,
-0.8695858716964722,
... 1420 more items
]
testing Dense: [128] => [32]...
_________________________________________________________________
Layer (type) Output shape Param #
=================================================================
transfer_dense_1 (Dense) [null,32] 4128
=================================================================
Total params: 4128
Trainable params: 4128
Non-trainable params: 0
_________________________________________________________________
Layer: Dense; data: [128]@0 => [32]@128 19027 cycles (1.3% opt)
total cycles: 19027 (0.227ms at 84MHz)
Test output Float32Array(32) [
0, 0,
0, 0,
5.463869094848633, 0,
0, 0.48411697149276733,
0, 0,
1.4437663555145264, 6.386779308319092,
1.6513590812683105, 1.1667512655258179,
0, 2.8119921684265137,
0.12458282709121704, 0,
0, 2.3636178970336914,
0, 0.6894450187683105,
6.159544467926025, 0,
0, 0,
1.2253615856170654, 0.12330290675163269,
0, 0,
1.349872350692749, 0.45826905965805054
]
also with no activation...
_________________________________________________________________
Layer (type) Output shape Param #
=================================================================
transfer_dense_1 (Dense) [null,32] 4128
=================================================================
Total params: 4128
Trainable params: 4128
Non-trainable params: 0
_________________________________________________________________
Layer: Dense; data: [128]@0 => [32]@128 18821 cycles (0.7% opt)
total cycles: 18821 (0.224ms at 84MHz)
Test output Float32Array(32) [
-0.7999378442764282, 6.2634100914001465,
1.3373290300369263, 5.851600646972656,
0.9642249345779419, 3.3023276329040527,
1.7263872623443604, -1.882416009902954,
3.913378953933716, -1.0334539413452148,
-9.435567855834961, 3.393305778503418,
1.5487284660339355, 4.065755844116211,
-6.1509785652160645, -6.310978889465332,
0.5820216536521912, -0.7537862062454224,
4.397172451019287, -2.292424440383911,
-4.048943996429443, -1.9891817569732666,
-0.1750953197479248, 5.590221881866455,
-2.137423515319824, -0.376464307308197,
-3.073636054992676, 2.9212992191314697,
-3.37052059173584, 1.7125061750411987,
-0.25794073939323425, 1.8945446014404297
]
testing Dense: [32] => [4]...
_________________________________________________________________
Layer (type) Output shape Param #
=================================================================
transfer_dense_out (Dense) [null,4] 132
=================================================================
Total params: 132
Trainable params: 132
Non-trainable params: 0
_________________________________________________________________
Layer: Dense; data: [32]@0 => [4]@32 625 cycles (2.5% opt)
total cycles: 625 (0.007ms at 84MHz)
Test output Float32Array(4) [
-1.1431775093078613,
-1.435903549194336,
-2.116854429244995,
1.8963240385055542
]
also with no activation...
_________________________________________________________________
Layer (type) Output shape Param #
=================================================================
transfer_dense_out (Dense) [null,4] 132
=================================================================
Total params: 132
Trainable params: 132
Non-trainable params: 0
_________________________________________________________________
Layer: Dense; data: [32]@0 => [4]@32 625 cycles (2.5% opt)
total cycles: 625 (0.007ms at 84MHz)
Test output Float32Array(4) [
1.3852261304855347,
1.2913734912872314,
-3.3826866149902344,
-2.540109634399414
]
Compiling full model...
_________________________________________________________________
Layer (type) Output shape Param #
=================================================================
input_1 (InputLayer) [null,250,3] 0
_________________________________________________________________
reshape (Reshape) [null,250,3,1] 0
_________________________________________________________________
conv2d (Conv2D) [null,76,1,20] 1520
_________________________________________________________________
activation (Activation) [null,76,1,20] 0
_________________________________________________________________
batch_normalization (BatchNo [null,76,1,20] 80
_________________________________________________________________
average_pooling2d (AveragePo [null,38,1,20] 0
_________________________________________________________________
sequential (Sequential) [null,11,1,64] 1856
_________________________________________________________________
sequential_1 (Sequential) [null,2,1,64] 4864
_________________________________________________________________
flatten (Flatten) [null,128] 0
_________________________________________________________________
transfer_dense_1 (Dense) [null,32] 4128
_________________________________________________________________
dropout (Dropout) [null,32] 0
_________________________________________________________________
transfer_dense_out (Dense) [null,4] 132
_________________________________________________________________
softmax (Softmax) [null,4] 0
=================================================================
Total params: 12580
Trainable params: 12284
Non-trainable params: 296
_________________________________________________________________
Layer: InputLayer; data: [250,3]@0 => [250,3]@0 (no computation)
Layer: Reshape; data: [250,3]@0 => [250,3,1]@0 (no computation)
[ null, 250, 3, 1 ] [ null, 76, 1, 20 ] {
filters: 20,
kernelInitializer: {
className: 'VarianceScaling',
config: { scale: 1, mode: 'fanAvg', distribution: 'uniform', seed: null }
},
kernelRegularizer: null,
kernelConstraint: null,
kernelSize: [ 25, 3 ],
strides: [ 3, 1 ],
padding: 'valid',
dataFormat: 'channelsLast',
dilationRate: [ 1, 1 ],
activation: 'linear',
useBias: true,
biasInitializer: { className: 'Zeros', config: {} },
biasRegularizer: null,
activityRegularizer: null,
biasConstraint: null,
name: 'conv2d',
trainable: true
}
Layer: Conv2D; data: [250,3,1]@0 => [76,1,20]@1520 1237604 cycles (13.7% opt)
_________________________________________________________________
Layer (type) Output shape Param #
=================================================================
input_1 (InputLayer) [null,250,3] 0
_________________________________________________________________
reshape (Reshape) [null,250,3,1] 0
_________________________________________________________________
conv2d (Conv2D) [null,76,1,20] 1520
_________________________________________________________________
activation (Activation) [null,76,1,20] 0
_________________________________________________________________
batch_normalization (BatchNo [null,76,1,20] 80
_________________________________________________________________
average_pooling2d (AveragePo [null,38,1,20] 0
_________________________________________________________________
sequential (Sequential) [null,11,1,64] 1856
_________________________________________________________________
sequential_1 (Sequential) [null,2,1,64] 4864
_________________________________________________________________
flatten (Flatten) [null,128] 0
_________________________________________________________________
transfer_dense_1 (Dense) [null,32] 4128
_________________________________________________________________
dropout (Dropout) [null,32] 0
_________________________________________________________________
transfer_dense_out (Dense) [null,4] 132
_________________________________________________________________
softmax (Softmax) [null,4] 0
=================================================================
Total params: 12580
Trainable params: 12284
Non-trainable params: 296
_________________________________________________________________
Layer: InputLayer; data: [250,3]@0 => [250,3]@0 (no computation)
Layer: Reshape; data: [250,3]@0 => [250,3,1]@0 (no computation)
[ null, 250, 3, 1 ] [ null, 76, 1, 20 ] {
filters: 20,
kernelInitializer: {
className: 'VarianceScaling',
config: { scale: 1, mode: 'fanAvg', distribution: 'uniform', seed: null }
},
kernelRegularizer: null,
kernelConstraint: null,
kernelSize: [ 25, 3 ],
strides: [ 3, 1 ],
padding: 'valid',
dataFormat: 'channelsLast',
dilationRate: [ 1, 1 ],
activation: 'linear',
useBias: true,
biasInitializer: { className: 'Zeros', config: {} },
biasRegularizer: null,
activityRegularizer: null,
biasConstraint: null,
name: 'conv2d',
trainable: true
}
Layer: Conv2D; data: [250,3,1]@0 => [76,1,20]@1520 1237604 cycles (13.7% opt)
Error: Unsupported operator or config: layer: Activation
at unsupported (/Users/microbit-carlos/workspace/mbef/microbit-ml-adl/node_modules/ml4f/built/ml4f.js:2605:15)
at compileModelCore (/Users/microbit-carlos/workspace/mbef/microbit-ml-adl/node_modules/ml4f/built/ml4f.js:3074:17)
at compileAndTest (/Users/microbit-carlos/workspace/mbef/microbit-ml-adl/node_modules/ml4f/built/ml4f.js:4015:24)
at Object.compileModelAndFullValidate (/Users/microbit-carlos/workspace/mbef/microbit-ml-adl/node_modules/ml4f/built/ml4f.js:3982:16)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async processModelFile (/Users/microbit-carlos/workspace/mbef/microbit-ml-adl/node_modules/ml4f/built/cli/cli.js:124:66)
at async Object.mainCli (/Users/microbit-carlos/workspace/mbef/microbit-ml-adl/node_modules/ml4f/built/cli/cli.js:180:9)