serizba / cppflow

Run TensorFlow models in C++ without installation and without Bazel
https://serizba.github.io/cppflow/
MIT License
779 stars 177 forks source link

Support for bool datatype #178

Open sumsuddin opened 2 years ago

sumsuddin commented 2 years ago

tensor::get_data<bool>() call fails. Because internally it calls deduce_tf_type(), but here for bool type TF_BOOL is never returned because of the preceding if block

    template<typename T>
    TF_DataType deduce_tf_type() {
        // ... 
        // As std::is_same<unsigned char, uint8_t>::value is true this condition becomes true here.
        if (std::is_same<T, uint8_t>::value)
            return TF_UINT8;
        // ...
        // This if condition NEVER executes because of the condition above
        if (std::is_same<T, unsigned char>::value)
            return TF_BOOL;
        // ...

This line

Changing it to the following works for me (for inference),

        if (std::is_same<T, bool>::value)
            return TF_BOOL;

Thanks for looking into it.

serizba commented 1 year ago

Lack of support of bool datatype is something that has been around for a long type. Should take a look to this soon.

In #208 there is a proposed solution.