serizba / cppflow

Run TensorFlow models in C++ without installation and without Bazel

Home Page:https://serizba.github.io/cppflow/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Errors when entering a data vector Matrix size-incompatible

alex290 opened this issue · comments

reate_model.py

import tensorflow as tf

input_1 = tf.keras.Input(shape=(9,))

output_1 = tf.keras.layers.Dense(6, activation=tf.nn.relu)(input_1)
output_1 = tf.keras.layers.Dense(3, activation=tf.nn.sigmoid)(input_1)
output_1 = tf.keras.layers.Dense(2, activation=tf.nn.sigmoid)(output_1)
model = tf.keras.Model(inputs=input_1, outputs=output_1)

model.compile()

# Export the model to a SavedModel
model.save('model', save_format='tf')

main.cpp

#include <iostream>
#include <cppflow/ops.h>
#include <cppflow/model.h>

int main()
{
    auto input_vector = std::vector<float>({1, 1, 1, 0, 0, 0, 0, 0, 0});
    auto input = cppflow::tensor(input_vector, {9, 1});

    cppflow::model model(std::string(MODEL_PATH));
    auto output = model(input);


    return 0;
}

The assembly is going great

[build] Consolidate compiler generated dependencies of target example
[build] [ 50%] Building CXX object CMakeFiles/example.dir/src/main.cpp.obj
[build] [100%] Linking CXX executable bin\example.exe
[build] [100%] Built target example
[build] Build finished with exit code 0

When executing, it returns an error

terminate called after throwing an instance of 'std::runtime_error'
  what():  2 root error(s) found.
  (0) INVALID_ARGUMENT: Matrix size-incompatible: In[0]: [9,1], In[1]: [9,3]
         [[{{function_node __inference__wrapped_model_123}}{{node model/dense_1/MatMul}}]]
         [[StatefulPartitionedCall/_29]]
  (1) INVALID_ARGUMENT: Matrix size-incompatible: In[0]: [9,1], In[1]: [9,3]
         [[{{function_node __inference__wrapped_model_123}}{{node model/dense_1/MatMul}}]]
0 successful operations.
0 derived errors ignored.

Found my mistake

auto input = cppflow::tensor(input_vector, {1, 9});

I mixed up the number of inputs in places 2 digits