Dobiasd / frugally-deep

A lightweight header-only library for using Keras (TensorFlow) models in C++.
MIT License
1.07k stars 236 forks source link

error building frugally-deep, fplus::subtract not found #361

Closed frak0d closed 2 years ago

frak0d commented 2 years ago
ninja: Entering directory `build'
[1/3] Compiling C++ object CamPlay_v0.1.p/src_main.cpp.o
FAILED: CamPlay_v0.1.p/src_main.cpp.o 
clang++ -ICamPlay_v0.1.p -I. -I.. -I../libs/fplus/fplus/include -I../libs/frugally-deep/include -I../libs/json/single_include -I/usr/include/opencv4 -I/usr/include/eigen3 -fcolor-diagnostics -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -Wextra -Wpedantic -std=c++20 -O1 -g -pthread -MD -MQ CamPlay_v0.1.p/src_main.cpp.o -MF CamPlay_v0.1.p/src_main.cpp.o.d -o CamPlay_v0.1.p/src_main.cpp.o -c ../src/main.cpp
In file included from ../src/main.cpp:13:
In file included from ../src/predictor.hpp:1:
In file included from ../libs/frugally-deep/include/fdeep/model.hpp:9:
In file included from ../libs/frugally-deep/include/fdeep/import_model.hpp:30:
In file included from ../libs/frugally-deep/include/fdeep/layers/add_layer.hpp:9:
In file included from ../libs/frugally-deep/include/fdeep/layers/layer.hpp:11:
../libs/frugally-deep/include/fdeep/tensor.hpp:758:47: error: no member named 'subtract' in namespace 'fplus'
    const auto dims = fplus::transform(fplus::subtract<std::size_t>(1), dims_raw);
                                       ~~~~~~~^
../libs/frugally-deep/include/fdeep/tensor.hpp:758:67: error: expected '(' for function-style cast or type construction
    const auto dims = fplus::transform(fplus::subtract<std::size_t>(1), dims_raw);
                                                       ~~~~~~~~~~~^
../libs/frugally-deep/include/fdeep/tensor.hpp:763:28: error: no matching function for call to 'create_tensor_shape_from_dims'
    const auto out_shape = create_tensor_shape_from_dims(
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../libs/frugally-deep/include/fdeep/tensor_shape.hpp:176:21: note: candidate function not viable: cannot convert argument of incomplete type 'void' to 'const std::vector<std::size_t>' (aka 'const vector<unsigned long>') for 1st argument
inline tensor_shape create_tensor_shape_from_dims(
                    ^
In file included from ../src/main.cpp:13:
In file included from ../src/predictor.hpp:1:
In file included from ../libs/frugally-deep/include/fdeep/model.hpp:9:
In file included from ../libs/frugally-deep/include/fdeep/import_model.hpp:30:
In file included from ../libs/frugally-deep/include/fdeep/layers/add_layer.hpp:9:
In file included from ../libs/frugally-deep/include/fdeep/layers/layer.hpp:11:
../libs/frugally-deep/include/fdeep/tensor.hpp:833:49: error: 'tensor' does not refer to a value
        fplus::all_the_same_on(fplus_c_mem_fn_t(tensor, shape, tensor_shape), ts),
                                                ^
../libs/frugally-deep/include/fdeep/tensor.hpp:28:7: note: declared here
class tensor
      ^
../libs/frugally-deep/include/fdeep/tensor.hpp:833:64: error: 'tensor_shape' does not refer to a value
        fplus::all_the_same_on(fplus_c_mem_fn_t(tensor, shape, tensor_shape), ts),
                                                               ^
../libs/frugally-deep/include/fdeep/tensor_shape.hpp:23:7: note: declared here
class tensor_shape
      ^
In file included from ../src/main.cpp:13:
In file included from ../src/predictor.hpp:1:
In file included from ../libs/frugally-deep/include/fdeep/model.hpp:9:
In file included from ../libs/frugally-deep/include/fdeep/import_model.hpp:30:
In file included from ../libs/frugally-deep/include/fdeep/layers/add_layer.hpp:9:
In file included from ../libs/frugally-deep/include/fdeep/layers/layer.hpp:11:
../libs/frugally-deep/include/fdeep/tensor.hpp:833:57: error: use of undeclared identifier 'shape'
        fplus::all_the_same_on(fplus_c_mem_fn_t(tensor, shape, tensor_shape), ts),
                                                        ^
../libs/frugally-deep/include/fdeep/tensor.hpp:836:26: error: 'tensor' does not refer to a value
        fplus_c_mem_fn_t(tensor, as_vector, shared_float_vec), ts);
                         ^
../libs/frugally-deep/include/fdeep/tensor.hpp:28:7: note: declared here
class tensor
      ^
../libs/frugally-deep/include/fdeep/tensor.hpp:836:45: error: unexpected type name 'shared_float_vec': expected expression
        fplus_c_mem_fn_t(tensor, as_vector, shared_float_vec), ts);
                                            ^
../libs/frugally-deep/include/fdeep/tensor.hpp:836:34: error: use of undeclared identifier 'as_vector'
        fplus_c_mem_fn_t(tensor, as_vector, shared_float_vec), ts);
                                 ^
../libs/frugally-deep/include/fdeep/tensor.hpp:888:49: error: 'tensor' does not refer to a value
        fplus::all_the_same_on(fplus_c_mem_fn_t(tensor, shape, tensor_shape), ts),
                                                ^
../libs/frugally-deep/include/fdeep/tensor.hpp:28:7: note: declared here
class tensor
      ^
../libs/frugally-deep/include/fdeep/tensor.hpp:888:64: error: 'tensor_shape' does not refer to a value
        fplus::all_the_same_on(fplus_c_mem_fn_t(tensor, shape, tensor_shape), ts),
                                                               ^
../libs/frugally-deep/include/fdeep/tensor_shape.hpp:23:7: note: declared here
class tensor_shape
      ^
In file included from ../src/main.cpp:13:
In file included from ../src/predictor.hpp:1:
In file included from ../libs/frugally-deep/include/fdeep/model.hpp:9:
In file included from ../libs/frugally-deep/include/fdeep/import_model.hpp:30:
In file included from ../libs/frugally-deep/include/fdeep/layers/add_layer.hpp:9:
In file included from ../libs/frugally-deep/include/fdeep/layers/layer.hpp:11:
../libs/frugally-deep/include/fdeep/tensor.hpp:888:57: error: use of undeclared identifier 'shape'
        fplus::all_the_same_on(fplus_c_mem_fn_t(tensor, shape, tensor_shape), ts),
                                                        ^
../libs/frugally-deep/include/fdeep/tensor.hpp:892:26: error: 'tensor' does not refer to a value
        fplus_c_mem_fn_t(tensor, as_vector, shared_float_vec), ts);
                         ^
../libs/frugally-deep/include/fdeep/tensor.hpp:28:7: note: declared here
class tensor
      ^
../libs/frugally-deep/include/fdeep/tensor.hpp:892:45: error: unexpected type name 'shared_float_vec': expected expression
        fplus_c_mem_fn_t(tensor, as_vector, shared_float_vec), ts);
                                            ^
../libs/frugally-deep/include/fdeep/tensor.hpp:892:34: error: use of undeclared identifier 'as_vector'
        fplus_c_mem_fn_t(tensor, as_vector, shared_float_vec), ts);
                                 ^
../libs/frugally-deep/include/fdeep/tensor.hpp:906:26: error: 'tensor' does not refer to a value
        fplus_c_mem_fn_t(tensor, rank, std::size_t),
                         ^
../libs/frugally-deep/include/fdeep/tensor.hpp:28:7: note: declared here
class tensor
      ^
../libs/frugally-deep/include/fdeep/tensor.hpp:906:34: error: variable 'rank' declared with deduced type 'const auto' cannot appear in its own initializer
        fplus_c_mem_fn_t(tensor, rank, std::size_t),
                                 ^
../libs/frugally-deep/include/fdeep/tensor.hpp:906:51: error: expected '(' for function-style cast or type construction
        fplus_c_mem_fn_t(tensor, rank, std::size_t),
                                       ~~~~~~~~~~~^
../libs/frugally-deep/include/fdeep/tensor.hpp:932:49: error: 'tensor' does not refer to a value
        fplus::all_the_same_on(fplus_c_mem_fn_t(tensor, shape, tensor_shape), ts),
                                                ^
../libs/frugally-deep/include/fdeep/tensor.hpp:28:7: note: declared here
class tensor
      ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
ninja: build stopped: subcommand failed.

What am i doing wrong ?

Dobiasd commented 2 years ago

Please make sure you're:

Dobiasd commented 2 years ago

Ok, in your command (clang++ [...] -std=c++20 [...]), the C++ version seems ok. So please try updating FunctionalPlus, and let know if that helped. :slightly_smiling_face:

frak0d commented 2 years ago

Both fplus and frugally-deep, are up to date.

Dobiasd commented 2 years ago

-I../libs/fplus/fplus/include might be wrong (double fplus). But I of course don't know where you have your files. :slightly_smiling_face:

I suggest you try to minimize the problem, by throwing everything out which is not essential to reproducing this compilation error, e.g., your custom code, and other libs like OpenCV, etc.

And then maybe try to compile manually, i.e., without ninja, also for example with -std=c++14 instead of -std=c++20, or with g++ instead of clang.

I guess somewhere on this path, you'll find the cause.

frak0d commented 2 years ago

ok my bad. i was using wrong repo for functional plus. it was some outdated fork that came up in google search.

frak0d commented 2 years ago

i used a premade .h5 model from teachablemachine and converted it to .json in colaboratory

When trying to use it with fdeep :

Loading json ... done. elapsed time: 0.008460 s
[json.exception.type_error.302] type must be string, but is null

here is the model i used : test_model.zip

Dobiasd commented 2 years ago

Please make sure you are using the latest versions of TensorFlow and Keras, and then re-run the convert_model call. 🙂

Dobiasd commented 2 years ago

@0xB00B Ah, I just see you tried to load some arbitrary .json file using frugally-deep. This won't work. It has to be a .json file that was created using convert_model.py from frugally-deep/keras_export (as described in the docs).

frak0d commented 2 years ago

oh! thanks, it works now. I had mistaken .json file as tensorflow.js model, since both use json.

fdeep really removes the pain of linking to tensorflow. thanks for this project again.