Intel® oneAPI Data Analytics Library
Community support for building compute-intensive applications that run fast on Intel® architecture.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
For the latest information on Intel’s response to the Log4j/Log4Shell vulnerability, please see Intel-SA-00646

Persist an SVM Model via Archive

Ian_Watson
Beginner
124 Views

I am new to DAAL, having a mixture of success, failure and mystery.

I want to build an SVM model and write that model to disk. Then subsequent tasks can read that model and use it for scoring.

Start with the example file svm_two_class_csr_batch.cpp which I have altered as shown below

    /* Retrieve the algorithm results */
    trainingResult = algorithm.getResult();

    data_management::InputDataArchive *archive = new data_management::InputDataArchive();
    trainingResult->serializeImpl(archive);
    const size_t nbytes = archive->getSizeOfArchive();
    byte * buffer = new byte[nbytes];
    archive->copyArchiveToArray(buffer, nbytes);     // I would now write this to disk, seems to work...

    services::SharedPtr<svm::training::Result> m2;    // then I would read it back in order to create a copy of trainingResult (m2)
    OutputDataArchive dataArch(buffer, nbytes);
    m2->deserializeImpl(&dataArch);

But this always dies on that last statement, core dump from deep within DAAL.

What am I doing wrong? Again, my objective is to build a model once, persist it to disk, then have multiple other tasks be able to read that model and use it for scoring.

Sorry if this is a dumb question, I am very new to DAAL

Thanks

Ian

0 Kudos
2 Replies
Ilya_B_Intel
Employee
124 Views

Ian,

There are two things you should change in this example:

  1. use serialize() function instead of serializeImpl and deserialize() instead of deserializeImpl
  2. create an empty result object before deserialization: services::SharedPtr<svm::training::Result> m2(new svm::training::Result() )

You can look at serialization example for more details here: examples\cpp\source\serialization\serialization.cpp

Ian_Watson
Beginner
124 Views

Thanks Ilya

works like a charm. I can now write the model to disk, then read it back later, score a test set and get the same results, exactly what I wanted.

Thank you.

Ian

Reply