Intel® oneAPI Data Analytics Library
Learn from community members on how to build compute-intensive applications that run efficiently on Intel® architecture.

Persist an SVM Model via Archive

Ian_Watson
Beginner
846 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
846 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

0 Kudos
Ian_Watson
Beginner
846 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

0 Kudos
Reply