eloquentarduino / EloquentTinyML

Eloquent interface to Tensorflow Lite for Microcontrollers
281 stars 56 forks source link

cannot allocate tensors with own generated model for Sine example #22

Closed Vensim closed 3 years ago

Vensim commented 3 years ago

The output of the serial comms is. image

What I've tried : Increasing and decreasing Tensor arena size, still same error.

Haven't done much changes to the model generation other than outputting straight to a c file :

# Port to C
c_code = port(model, pretty_print = True)
c_file = open("sine_model.h", "w")
c_file.write(c_code)

Here are my files and the model that's being used. Python script :

import math
import numpy as np
import tensorflow as tf
from tensorflow.keras import layers
from tinymlgen import port

def get_model():
    SAMPLES = 1000
    np.random.seed(1337)
    x_values = np.random.uniform(low=0, high=2*math.pi, size=SAMPLES)
    # shuffle and add noise
    np.random.shuffle(x_values)
    y_values = np.sin(x_values)
    y_values += 0.1 * np.random.randn(*y_values.shape)

    # split into train, validation, test
    TRAIN_SPLIT =  int(0.6 * SAMPLES)
    TEST_SPLIT = int(0.2 * SAMPLES + TRAIN_SPLIT)
    x_train, x_test, x_validate = np.split(x_values, [TRAIN_SPLIT, TEST_SPLIT])
    y_train, y_test, y_validate = np.split(y_values, [TRAIN_SPLIT, TEST_SPLIT])

    # create a NN with 2 layers of 16 neurons
    model = tf.keras.Sequential()
    model.add(layers.Dense(8, activation='relu', input_shape=(1,)))
    model.add(layers.Dense(16, activation='relu'))
    model.add(layers.Dense(1))
    model.compile(optimizer='rmsprop', loss='mse', metrics=['mae'])
    model.fit(x_train, y_train, epochs=200, batch_size=16,
                        validation_data=(x_validate, y_validate))
    return model

def test_model(model, verbose=False):
    x_test = np.random.uniform(low=0, high=2*math.pi, size=100)
    y_test = np.sin(x_test)
    y_pred = model.predict(x_test)
    print('MAE', np.abs(y_pred - y_test).mean())

model = get_model()
converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]
tflite_model = converter.convert()
test_model(model)

# Save the model to disk
open("sine_model_quantized.tflite", "wb").write(tflite_model)

# Port to C
c_code = port(model, pretty_print = True)
c_file = open("sine_model.h", "w")
c_file.write(c_code)

Arduino IDE code :

#include <EloquentTinyML.h>
// sine_model.h contains the array you exported from the previous step
// with either xxd or tinymlgen
#include "sine_model.h"

#define NUMBER_OF_INPUTS 1
#define NUMBER_OF_OUTPUTS 1
// in future projects you may need to tweak this value.
// it's a trial and error process
#define TENSOR_ARENA_SIZE 2*1024

Eloquent::TinyML::TfLite<NUMBER_OF_INPUTS, NUMBER_OF_OUTPUTS, TENSOR_ARENA_SIZE> ml;

void setup() {
    Serial.begin(115200);
    ml.begin(model_data);
}

void loop() {
    // pick up a random x and predict its sine
    float x = 3.14 * random(100) / 100;
    float y = sin(x);
    float input[1] = { x };
    float predicted = ml.predict(input);

    Serial.print("sin(");
    Serial.print(x);
    Serial.print(") = ");
    Serial.print(y);
    Serial.print("\t predicted: ");
    Serial.println(predicted);
    delay(1000);
}

sine_model.h


#ifdef __has_attribute
#define HAVE_ATTRIBUTE(x) __has_attribute(x)
#else
#define HAVE_ATTRIBUTE(x) 0
#endif
#if HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__))
#define DATA_ALIGN_ATTRIBUTE __attribute__((aligned(4)))
#else
#define DATA_ALIGN_ATTRIBUTE
#endif

const unsigned char model_data[] DATA_ALIGN_ATTRIBUTE = {
    0x20, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x12, 0x00, 0x1c, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 
    0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x18, 0x00, 0x12, 0x00, 0x00, 0x00, 
    0x03, 0x00, 0x00, 0x00, 0x04, 0x09, 0x00, 0x00, 0x30, 0x04, 0x00, 0x00, 
    0x18, 0x04, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 
    0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 
    0x04, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 
    0x0b, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x6d, 0x69, 0x6e, 0x5f, 
    0x72, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x76, 0x65, 0x72, 0x73, 
    0x69, 0x6f, 0x6e, 0x00, 0x0c, 0x00, 0x00, 0x00, 0xc8, 0x03, 0x00, 0x00, 
    0xb4, 0x03, 0x00, 0x00, 0x78, 0x03, 0x00, 0x00, 0x14, 0x03, 0x00, 0x00, 
    0x00, 0x03, 0x00, 0x00, 0xcc, 0x02, 0x00, 0x00, 0xb8, 0x00, 0x00, 0x00, 
    0x64, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 
    0x30, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xb6, 0xfc, 0xff, 0xff, 
    0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x31, 0x2e, 0x35, 0x2e, 
    0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0xc4, 0xf7, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0xd4, 0xf7, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe4, 0xf7, 0xff, 0xff, 
    0x00, 0x00, 0x00, 0x00, 0x06, 0xfd, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 
    0x40, 0x00, 0x00, 0x00, 0x34, 0xba, 0x9c, 0xbf, 0x9c, 0x6c, 0xb7, 0x3e, 
    0x75, 0xc7, 0x35, 0x3f, 0xcd, 0xc1, 0xe3, 0xbe, 0xe3, 0xef, 0x0e, 0xbf, 
    0x0f, 0x80, 0x37, 0xbf, 0x71, 0xdd, 0xfe, 0x3f, 0x4c, 0x88, 0x10, 0x3f, 
    0xaf, 0x8b, 0xed, 0xbd, 0xe4, 0xfb, 0xa5, 0x3e, 0x47, 0xf7, 0xbb, 0x3f, 
    0xe6, 0x8f, 0x0b, 0x3f, 0xff, 0x86, 0x6f, 0x3f, 0x4a, 0x8f, 0x33, 0xbe, 
    0xa0, 0xcf, 0x2c, 0xbf, 0xbf, 0x80, 0x09, 0x40, 0x00, 0x00, 0x00, 0x00, 
    0x56, 0xfd, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 
    0xc3, 0x9d, 0xb8, 0x3e, 0x14, 0x5e, 0xc2, 0x3e, 0x20, 0xc4, 0x5b, 0xbd, 
    0x75, 0x98, 0x79, 0x3e, 0x68, 0x1c, 0xd2, 0xbe, 0x6e, 0xff, 0xac, 0xbf, 
    0x00, 0x95, 0xef, 0xbd, 0x78, 0x1d, 0x2a, 0x3e, 0x7e, 0xf0, 0x94, 0x3e, 
    0xec, 0x78, 0xad, 0x3e, 0x82, 0xf4, 0x8a, 0x3e, 0xd6, 0x1d, 0xe0, 0xbd, 
    0xc0, 0x86, 0x97, 0xbd, 0xf2, 0xda, 0x97, 0x3e, 0xcc, 0xe2, 0x87, 0x3e, 
    0x2c, 0xab, 0x91, 0x3e, 0xa9, 0xe0, 0x9d, 0xbd, 0xb8, 0x8e, 0x2b, 0xbe, 
    0x52, 0x13, 0xe2, 0xbe, 0x3f, 0x9d, 0xbc, 0xbe, 0x74, 0xf5, 0xb9, 0x3e, 
    0x4d, 0x3e, 0x78, 0x3e, 0x4c, 0xcc, 0xf5, 0xbe, 0x0c, 0x5a, 0xf7, 0xbe, 
    0xd0, 0xbb, 0x65, 0xbe, 0x04, 0xf4, 0x96, 0x3e, 0xb0, 0x6b, 0xbd, 0xbd, 
    0x38, 0xcb, 0xd1, 0x3e, 0x00, 0x18, 0x9e, 0xbe, 0xe0, 0x2e, 0x88, 0xbe, 
    0x90, 0x5e, 0xfa, 0x3d, 0x40, 0xa4, 0xd7, 0xbc, 0xd9, 0xba, 0x83, 0xbe, 
    0x74, 0xaa, 0xf1, 0x3e, 0xff, 0xdc, 0x01, 0x3f, 0xf2, 0xc7, 0xad, 0x3e, 
    0x00, 0xc8, 0xf7, 0x3a, 0x47, 0x53, 0xb9, 0x3e, 0x80, 0x16, 0x57, 0x3e, 
    0xa0, 0x63, 0x25, 0x3d, 0xeb, 0xd5, 0x83, 0xbe, 0x20, 0xad, 0xf0, 0xbd, 
    0x2c, 0x70, 0x84, 0x3d, 0x48, 0x36, 0x46, 0xbf, 0x78, 0xbb, 0x96, 0xbe, 
    0xe2, 0x11, 0x5a, 0x3e, 0x8c, 0xa3, 0xfc, 0xbe, 0x60, 0xca, 0x00, 0xbe, 
    0xa9, 0xbe, 0x39, 0xbe, 0x00, 0xc0, 0x36, 0xb9, 0x42, 0xb4, 0xe4, 0x3e, 
    0x5c, 0x8e, 0xe3, 0x3e, 0x80, 0x31, 0x3b, 0x3d, 0x3f, 0xf0, 0xb3, 0xbc, 
    0x5c, 0x82, 0xad, 0x3e, 0x80, 0x6f, 0xe5, 0x3c, 0x62, 0x28, 0xd4, 0x3d, 
    0xe0, 0xa6, 0xaa, 0xbd, 0x18, 0x22, 0x85, 0x3e, 0x90, 0x12, 0x14, 0xbe, 
    0x50, 0xb3, 0x82, 0x3d, 0x8b, 0x5e, 0xac, 0xbe, 0xa0, 0xe5, 0xe7, 0xbe, 
    0x08, 0x9e, 0xea, 0xbe, 0x5e, 0xa9, 0x43, 0xbe, 0x20, 0x6d, 0x5d, 0xbd, 
    0x61, 0xcb, 0xbb, 0xbe, 0x73, 0x68, 0xac, 0x3d, 0x38, 0xab, 0x9e, 0xbe, 
    0xe6, 0x72, 0x02, 0x3f, 0x18, 0xf3, 0xa1, 0xbe, 0x20, 0x45, 0x99, 0x3e, 
    0x30, 0x68, 0xfc, 0xbe, 0x28, 0x9c, 0xcc, 0x3e, 0x00, 0x42, 0x9b, 0x3c, 
    0x18, 0x58, 0x51, 0x3e, 0x78, 0x0e, 0xd1, 0x3e, 0xcc, 0x33, 0xc9, 0xbe, 
    0x30, 0x5b, 0x0d, 0xbe, 0x80, 0xb9, 0xe6, 0xbc, 0x7b, 0xa1, 0x0a, 0x3d, 
    0xe0, 0xfc, 0x8d, 0x3e, 0x0a, 0x11, 0x83, 0xbf, 0x80, 0x48, 0x63, 0xbf, 
    0x00, 0xef, 0x6e, 0x3e, 0xd8, 0xbf, 0xd1, 0x3e, 0x1c, 0x56, 0x97, 0xbe, 
    0xb8, 0xca, 0x5f, 0x3e, 0xb8, 0x3a, 0x27, 0xbe, 0x80, 0x81, 0x68, 0xbe, 
    0x40, 0xe1, 0x4e, 0xbd, 0x30, 0x35, 0xb9, 0xbd, 0x78, 0x98, 0xad, 0xbe, 
    0xe0, 0x94, 0xf0, 0xbe, 0x88, 0xe4, 0x6a, 0x3e, 0x28, 0xda, 0x12, 0xbe, 
    0x84, 0x4c, 0x65, 0x3c, 0x90, 0xa3, 0x8d, 0xbe, 0x28, 0x2e, 0xc8, 0xbe, 
    0x9a, 0x89, 0x2e, 0xbf, 0x9c, 0xee, 0x89, 0xbe, 0x89, 0x48, 0x33, 0x3e, 
    0x24, 0xff, 0xdc, 0xbe, 0x80, 0x37, 0x03, 0xbd, 0x6a, 0x74, 0x07, 0xbf, 
    0x24, 0x2d, 0xcb, 0xbe, 0xf3, 0x29, 0x1d, 0xbe, 0xa2, 0x1c, 0xc7, 0x3e, 
    0x78, 0x6a, 0xbc, 0x3e, 0xb4, 0x6e, 0x57, 0xbd, 0x40, 0x70, 0xd1, 0x3c, 
    0xf8, 0xc4, 0x3d, 0x3e, 0x26, 0xff, 0xe3, 0x3b, 0x60, 0xbb, 0xa7, 0x3d, 
    0x71, 0x3b, 0x32, 0xbe, 0xbb, 0x44, 0xd0, 0xbe, 0x60, 0x40, 0x91, 0x3e, 
    0xc4, 0xe7, 0x0c, 0x3f, 0xa8, 0x6c, 0x9c, 0x3e, 0xc0, 0xb4, 0x96, 0xbd, 
    0x7a, 0x97, 0x09, 0xbf, 0x18, 0xbf, 0x4c, 0xbe, 0x9e, 0xc6, 0xa8, 0x3e, 
    0x9d, 0x6a, 0x4b, 0x3f, 0x28, 0x4b, 0x93, 0x3e, 0xf0, 0xfb, 0x81, 0xbd, 
    0x68, 0xd6, 0x8f, 0xbe, 0xf0, 0x44, 0xc6, 0xbd, 0x00, 0x00, 0x00, 0x00, 
    0x66, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 
    0xdd, 0x1d, 0x78, 0x3b, 0x44, 0x56, 0x92, 0xbe, 0x52, 0x12, 0x71, 0x3e, 
    0xc9, 0x98, 0x8c, 0x3e, 0xd6, 0x0e, 0x29, 0xbf, 0x17, 0xe1, 0xb4, 0x3e, 
    0xbc, 0x3f, 0x00, 0xbf, 0x59, 0x51, 0x07, 0xbf, 0x00, 0x00, 0x00, 0x00, 
    0x96, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 
    0x3b, 0xb2, 0x70, 0xbe, 0xa6, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 
    0x40, 0x00, 0x00, 0x00, 0x57, 0xa5, 0xe2, 0x3e, 0x2a, 0x95, 0x1b, 0xbe, 
    0x5f, 0x99, 0xfe, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x3d, 0xc2, 0x3c, 
    0x09, 0x8b, 0x1b, 0xbc, 0x19, 0x4a, 0xf9, 0xbe, 0x58, 0xb0, 0xdc, 0xbc, 
    0x6c, 0x7a, 0x36, 0xbd, 0x00, 0x00, 0x00, 0x00, 0x97, 0x71, 0x98, 0x3e, 
    0x00, 0x00, 0x00, 0x00, 0x80, 0x47, 0xa6, 0x3e, 0xa5, 0x0b, 0x28, 0xbd, 
    0xdd, 0xb4, 0xbd, 0xbd, 0x45, 0x12, 0x0f, 0xbf, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 
    0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 
    0x20, 0x00, 0x00, 0x00, 0x3d, 0x89, 0xdf, 0x3e, 0x00, 0x00, 0x00, 0x00, 
    0x94, 0x8b, 0xd0, 0xbe, 0x0c, 0x62, 0x26, 0xbf, 0x00, 0x00, 0x00, 0x00, 
    0x18, 0xab, 0x83, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x24, 0xfb, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x34, 0xfb, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x4d, 0x4c, 0x49, 0x52, 
    0x20, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x65, 0x64, 0x2e, 0x00, 
    0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 
    0x18, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00, 
    0x0e, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xf4, 0x00, 0x00, 0x00, 
    0xe8, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 
    0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 
    0x03, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 
    0x04, 0x00, 0x00, 0x00, 0xce, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x08, 
    0x18, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 
    0xb4, 0xfb, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 
    0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 
    0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, 
    0x08, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x10, 0x00, 0x0e, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x08, 0x1c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 
    0x04, 0x00, 0x00, 0x00, 0xba, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 
    0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 
    0x07, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x0e, 0x00, 0x16, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 
    0x07, 0x00, 0x10, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 
    0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x07, 0x00, 0x06, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 
    0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 
    0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 
    0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 
    0x68, 0x03, 0x00, 0x00, 0xf8, 0x02, 0x00, 0x00, 0x8c, 0x02, 0x00, 0x00, 
    0x30, 0x02, 0x00, 0x00, 0xec, 0x01, 0x00, 0x00, 0xa4, 0x01, 0x00, 0x00, 
    0x5c, 0x01, 0x00, 0x00, 0xd8, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 
    0x04, 0x00, 0x00, 0x00, 0xd4, 0xfc, 0xff, 0xff, 0x34, 0x00, 0x00, 0x00, 
    0x0a, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 
    0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 
    0x01, 0x00, 0x00, 0x00, 0xc0, 0xfc, 0xff, 0xff, 0x08, 0x00, 0x00, 0x00, 
    0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x00, 0x00, 0x00, 0x00, 
    0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 
    0x18, 0xfd, 0xff, 0xff, 0x78, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 
    0x1c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 
    0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 
    0x04, 0xfd, 0xff, 0xff, 0x4c, 0x00, 0x00, 0x00, 0x73, 0x65, 0x71, 0x75, 
    0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x64, 0x65, 0x6e, 0x73, 0x65, 
    0x5f, 0x31, 0x2f, 0x4d, 0x61, 0x74, 0x4d, 0x75, 0x6c, 0x3b, 0x73, 0x65, 
    0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x64, 0x65, 0x6e, 
    0x73, 0x65, 0x5f, 0x31, 0x2f, 0x52, 0x65, 0x6c, 0x75, 0x3b, 0x73, 0x65, 
    0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x64, 0x65, 0x6e, 
    0x73, 0x65, 0x5f, 0x31, 0x2f, 0x42, 0x69, 0x61, 0x73, 0x41, 0x64, 0x64, 
    0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 
    0x10, 0x00, 0x00, 0x00, 0xa0, 0xfd, 0xff, 0xff, 0x70, 0x00, 0x00, 0x00, 
    0x08, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 
    0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 
    0x08, 0x00, 0x00, 0x00, 0x8c, 0xfd, 0xff, 0xff, 0x46, 0x00, 0x00, 0x00, 
    0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x64, 
    0x65, 0x6e, 0x73, 0x65, 0x2f, 0x4d, 0x61, 0x74, 0x4d, 0x75, 0x6c, 0x3b, 
    0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x64, 
    0x65, 0x6e, 0x73, 0x65, 0x2f, 0x52, 0x65, 0x6c, 0x75, 0x3b, 0x73, 0x65, 
    0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x64, 0x65, 0x6e, 
    0x73, 0x65, 0x2f, 0x42, 0x69, 0x61, 0x73, 0x41, 0x64, 0x64, 0x00, 0x00, 
    0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 
    0x86, 0xfe, 0xff, 0xff, 0x34, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 
    0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xfc, 0xfd, 0xff, 0xff, 
    0x19, 0x00, 0x00, 0x00, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 
    0x61, 0x6c, 0x2f, 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x32, 0x2f, 0x4d, 
    0x61, 0x74, 0x4d, 0x75, 0x6c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 
    0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xca, 0xfe, 0xff, 0xff, 
    0x34, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 
    0x04, 0x00, 0x00, 0x00, 0x40, 0xfe, 0xff, 0xff, 0x19, 0x00, 0x00, 0x00, 
    0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x64, 
    0x65, 0x6e, 0x73, 0x65, 0x5f, 0x31, 0x2f, 0x4d, 0x61, 0x74, 0x4d, 0x75, 
    0x6c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 
    0x08, 0x00, 0x00, 0x00, 0x0e, 0xff, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, 
    0x05, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 
    0x84, 0xfe, 0xff, 0xff, 0x17, 0x00, 0x00, 0x00, 0x73, 0x65, 0x71, 0x75, 
    0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x64, 0x65, 0x6e, 0x73, 0x65, 
    0x2f, 0x4d, 0x61, 0x74, 0x4d, 0x75, 0x6c, 0x00, 0x02, 0x00, 0x00, 0x00, 
    0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x4e, 0xff, 0xff, 0xff, 
    0x4c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 
    0x04, 0x00, 0x00, 0x00, 0xc4, 0xfe, 0xff, 0xff, 0x32, 0x00, 0x00, 0x00, 
    0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x64, 
    0x65, 0x6e, 0x73, 0x65, 0x5f, 0x32, 0x2f, 0x42, 0x69, 0x61, 0x73, 0x41, 
    0x64, 0x64, 0x2f, 0x52, 0x65, 0x61, 0x64, 0x56, 0x61, 0x72, 0x69, 0x61, 
    0x62, 0x6c, 0x65, 0x4f, 0x70, 0x2f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 
    0x63, 0x65, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 
    0xa6, 0xff, 0xff, 0xff, 0x4c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 
    0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x1c, 0xff, 0xff, 0xff, 
    0x32, 0x00, 0x00, 0x00, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 
    0x61, 0x6c, 0x2f, 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x31, 0x2f, 0x42, 
    0x69, 0x61, 0x73, 0x41, 0x64, 0x64, 0x2f, 0x52, 0x65, 0x61, 0x64, 0x56, 
    0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x4f, 0x70, 0x2f, 0x72, 0x65, 
    0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 
    0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x04, 0x00, 
    0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x0e, 0x00, 0x00, 0x00, 
    0x4c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 
    0x04, 0x00, 0x00, 0x00, 0x84, 0xff, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, 
    0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x64, 
    0x65, 0x6e, 0x73, 0x65, 0x2f, 0x42, 0x69, 0x61, 0x73, 0x41, 0x64, 0x64, 
    0x2f, 0x52, 0x65, 0x61, 0x64, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 
    0x65, 0x4f, 0x70, 0x2f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 
    0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 
    0x14, 0x00, 0x18, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 
    0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x14, 0x00, 0x00, 0x00, 
    0x38, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 
    0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 
    0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 
    0x04, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x64, 0x65, 0x6e, 0x73, 
    0x65, 0x5f, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x00, 0x02, 0x00, 0x00, 0x00, 
    0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 
    0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x07, 0x00, 0x00, 0x00, 
    0x08, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 
    0x09, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00
};
const int model_data_len = 2384;
Vensim commented 3 years ago

files.zip

Vensim commented 3 years ago

Model output fixed upon inspection of Issue 17's comments.

Replace

c_code = port(model, pretty_print=True)

with

c_code = port(model, pretty_print=True, optimize=False)

Sent request.

whubaichuan commented 1 year ago

@eloquentarduino I suggest changing the code in the original file. It seems lots of people ask the same question including me at the beginning. Thanks.

Vensim commented 1 year ago

@eloquentarduino Is this the same issue as was posted here? I see on updated example of Sine , optimize=False is missing, did adding it fix it for you?

eloquentarduino commented 1 year ago

Publishing EloquentTinyML==2.4.4 with optimize=False in every Python example. I will migrate the tinymlgen.port function into my new everywhereml package.