Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CCARTree serialization/deserialization error #3481

Open
tt83 opened this issue Oct 28, 2016 · 9 comments
Open

CCARTree serialization/deserialization error #3481

tt83 opened this issue Oct 28, 2016 · 9 comments

Comments

@tt83
Copy link

tt83 commented Oct 28, 2016

I'm trying to serialize/deserialize a CCARTree object in C++, but when I call load_serializable I'm getting an error:
In file ~/Library/shogun-develop/src/shogun/base/Parameter.cpp line 2212: TParameter::new_sgserial(): Class CBinaryTreeMachineNode' was not listed during compiling Shogun :( ... Can not construct it form_root'!
Fragment of code:

        {
            auto tree = new shogun::CCARTree(ft, shogun::PT_REGRESSION);
            tree->set_labels(std::get<1>(dataset));
            tree->set_weights(std::get<2>(dataset));
            tree->train(std::get<0>(dataset));

            auto file = new shogun::CSerializableAsciiFile("test.dat", 'w');
            if (!tree->save_serializable(file))
            {
                std::cerr << "Error saving file" << std::endl;
            }
            file->close();
            SG_UNREF(file);
            SG_UNREF(tree);
        }

        auto tree = new shogun::CCARTree();
        auto file = new shogun::CSerializableAsciiFile("test.dat", 'r');
        if (!tree->load_serializable(file))
        {
            std::cerr << "Error loading file" << std::endl;
            file->close();
            SG_UNREF(file);
            SG_UNREF(tree);
            return -1;
        }
        file->close();
        SG_UNREF(file);
@karlnapf
Copy link
Member

Thanks for reporting this
I will investigate and get back to you

@karlnapf
Copy link
Member

#3537

@zrlkau
Copy link

zrlkau commented Apr 12, 2018

Hi @karlnapf,

I ran into the same issue with 6.0.0 (shogun-6.0.0-4.fc26) and with the latest git code (d8c84e9) while I was trying to load a CARTree in C++ that I trained and serialized in Python. Do you have an outlook on when this might be fixed (or a workaround for now, since I'm working towards a looming paper submission deadline).

thanks,
Michael

@karlnapf
Copy link
Member

Ah yes this one.
I’ll try to have a look later today.
Pls ping again next week if nothing happened.
This is definitely something that needs fixing asap

@zrlkau
Copy link

zrlkau commented Apr 12, 2018

Thanks for looking into it @karlnapf. I dug into it a little bit myself and I found that one problem might be that in src/shogun/multiclass/tree/BinaryTreeMachineNode.h the class definition is split across multiple lines, i.e.

template <typename T>
class CBinaryTreeMachineNode
       : public CTreeMachineNode<T>

instead of

template <typename T> class CBinaryTreeMachineNode : public CTreeMachineNode<T>

If I change that, then src/shogun/base/class_list.cpp.py picks it up (but unfortunately, twice, as simple and as template class - I manually removed it as simple class.) and adds the necessary functions for it into class_list.cpp. Unfortunately, I still get the same error (which is somewhat confusing to me, because I found _ZL28__new_CBinaryTreeMachineNodeN6shogun14EPrimitiveTypeE in libshogun.so):

[...]/shogun/src/shogun/base/Parameter.cpp line 2210: TParameter::new_sgserial(): Class
CBinaryTreeMachineNode was not listed during compiling Shogun :( ... Can not construct it for m_root![GCDEBUG] unref() refcount 4294967295, obj SerializableAsciiFile (0x7f24b4008f50) destroying

Update: It's because the object it tries to deserialize is a CBinaryTreeMachineNode<PT_SGOBJECT> which it can't because the corresponding 'case' statement is empty.

@karlnapf
Copy link
Member

karlnapf commented Apr 12, 2018 via email

@zrlkau
Copy link

zrlkau commented Apr 12, 2018

Hi @karlnapf ,

thanks for looking into it. I was afraid that it's something more fundamental since that case isn't covered in any templated class. If you can find a fix, it'd really appreciate it but I understand that it's not a simple problem.

thanks,
Michael

@karlnapf
Copy link
Member

karlnapf commented Apr 13, 2018

The reason is not that this case is not covered in templated classes (or at least that is easy to fix), but the problem is that the tree implementations were never written in a way that they can be serialized (which is our bad for having not enforced that back when the GSoC student wrote this).

I opened an issue that suggests a workaround #4242

@karlnapf
Copy link
Member

We might pick this up at this weekend's hackathon, or maybe delegate it to a GSoC student, as it is a cool task to learn more about shogun's internals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants