'boost::archive::archive_exception' what(): unsupported version

╄→гoц情女王★ 提交于 2019-12-24 04:23:26

问题


I cloned this repository:

https://github.com/srianant/computer_vision

built and ran,got this error:

OpenPose/DLIB Gesture, Action and Face Recognition.
resolution: 640x480
net_resolution: 656x368
handNetInputSize: 368x368
face_net_resolution: 368x368
cCamera Resolution set to: 640x480
Push following keys:
p for pause sample generation
f for generating face samples
t for train samples
c for continue camera feed
h for display key commands
q for quit program
terminate called after throwing an instance of 'boost::archive::archive_exception'
  what():  unsupported version

And this exception thrown from this file:line:32

https://github.com/srianant/computer_vision/blob/master/openpose/src/openpose/user_code/pose_model.cpp

I think it is trying to deserialized this file:

https://github.com/srianant/computer_vision/blob/master/openpose/train_data/pose/pose.model

回答1:


You're probably doing something wrong: have you checked your boost version? It could just be (very) old.

I can deserialize all the input archives that use boost.

The only use of boost is in openpose_recognition.cpp, and the only archives being read are text archives from the training data.

It is easy to create a standalone program to verify that these file can be deserialized.

Creating The Minimal Declarations

Extracted from pose_model.hpp:

// Timesteps per samples
const int timesteps = 5; // 5 frames per sample

// 2-dim data to store different postures
const int max_pose_count = 10;
const int max_pose_score_pair = 36;  // 34 pairs for pose + 2 padding for multiples of 4
typedef std::array<std::string, max_pose_count> pose;
typedef std::array<double,max_pose_score_pair*timesteps> pose_sample_type;

// 2-dim data to store different hand actions
const int max_hand_count = 10;
const int max_hand_score_pair = 40;  // 40 pairs for hand
typedef std::array<std::string,max_hand_count> hand;
typedef std::array<double,max_hand_score_pair*timesteps> hand_sample_type;

// 2-dim data to store different faces
const int max_face_count = 10;
const int max_face_score_pair = 96; // 96 pairs (94 + 2 pairs for padding for multiples of 4)
typedef std::array<std::string,max_face_count> face;
typedef std::array<double,max_face_score_pair*timesteps> face_sample_type;

Test Method:

All extractions follow the same pattern, let's add a debug_print method later:

template <typename T>
void read_and_verify(std::string name, T& into) {
    std::ifstream ifs("/tmp/so/computer_vision/openpose/train_data/" + name);
    boost::archive::text_iarchive ia(ifs);
    ia >> into;

    debug_print(name, into);
}

Note: Adjust the path to match your file locations

Reading All The Archives:

int main() {
    {
        pose pose_names;
        std::vector<pose_sample_type> pose_samples; // vector of m_pose_sample vectors
        std::vector<double> pose_labels;            // vector of pose labels (eg. 1,2,3...)

        read_and_verify("pose/pose_names.txt", pose_names);
        read_and_verify("pose/pose_samples.txt", pose_samples);
        read_and_verify("pose/pose_labels.txt", pose_labels);
    }

    {
        face face_names;                            // vector of face emotions names (eg. normal, sad, happy...)
        std::vector<face_sample_type> face_samples; // vector of m_face_sample vectors
        std::vector<double> face_labels;            // vector of face emotions labels (eg. 1,2,3...)
        read_and_verify("face/face_names.txt", face_names);
        read_and_verify("face/face_samples.txt", face_samples);
        read_and_verify("face/face_labels.txt", face_labels);
    }

    {
        hand hand_names;                                    // vector of hand gesture names (eg. fist, victory, stop...);
        std::vector<hand_sample_type> left_hand_samples;    // vector of m_left_hand_sample vectors
        std::vector<hand_sample_type> right_hand_samples;   // vector of m_right_hand_sample vectors
        std::vector<double> left_hand_labels;               // vector of left hand labels (eg. 1,2,3...)
        std::vector<double> right_hand_labels;              // vector of right hand labels (eg. 1,2,3...)
        read_and_verify("hand/hand_names.txt", hand_names);
        read_and_verify("hand/left_hand_samples.txt", left_hand_samples);
        read_and_verify("hand/right_hand_samples.txt", right_hand_samples);
        read_and_verify("hand/left_hand_labels.txt", left_hand_labels);
        read_and_verify("hand/right_hand_labels.txt", right_hand_labels);
    }
}

Printing Debug Info:

We need only three different debug_print overloads, for names, samples and labels:

template <size_t N> // names
void debug_print(std::string name, std::array<std::string, N> const& data) {
    std::cout << name << ": ";

    for (auto& n : data)
        if (!n.empty())
            std::cout << n << " ";

    std::cout << "\n";
}

// labels
void debug_print(std::string name, std::vector<double> const& data) {
    std::cout << name << ": ";

    for (auto& a : data)
        std::cout << a << " ";

    std::cout << "\n";
}

template <size_t N> // samples
void debug_print(std::string name, std::vector<std::array<double, N> > const& data) {
    std::cout << name << ": ";

    for (auto& a : data)
        std::cout << "{" << a[0] << "...} ";

    std::cout << "\n";
}

DEMO TIME

The complete program is here:

Live On Coliru

#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/array.hpp>
#include <boost/serialization/vector.hpp>
#include <fstream>
#include <iostream>

///////////////// from pose_model.hpp
//
    // Timesteps per samples
    const int timesteps = 5; // 5 frames per sample

    // 2-dim data to store different postures
    const int max_pose_count = 10;
    const int max_pose_score_pair = 36;  // 34 pairs for pose + 2 padding for multiples of 4
    typedef std::array<std::string, max_pose_count> pose;
    typedef std::array<double,max_pose_score_pair*timesteps> pose_sample_type;

    // 2-dim data to store different hand actions
    const int max_hand_count = 10;
    const int max_hand_score_pair = 40;  // 40 pairs for hand
    typedef std::array<std::string,max_hand_count> hand;
    typedef std::array<double,max_hand_score_pair*timesteps> hand_sample_type;

    // 2-dim data to store different faces
    const int max_face_count = 10;
    const int max_face_score_pair = 96; // 96 pairs (94 + 2 pairs for padding for multiples of 4)
    typedef std::array<std::string,max_face_count> face;
    typedef std::array<double,max_face_score_pair*timesteps> face_sample_type;
//
///////////////// end pose_model.hpp

template <size_t N> // names
void debug_print(std::string name, std::array<std::string, N> const& data) {
    std::cout << name << ": ";

    for (auto& n : data)
        if (!n.empty())
            std::cout << n << " ";

    std::cout << "\n";
}

// labels
void debug_print(std::string name, std::vector<double> const& data) {
    std::cout << name << ": ";

    for (auto& a : data)
        std::cout << a << " ";

    std::cout << "\n";
}

template <size_t N> // samples
void debug_print(std::string name, std::vector<std::array<double, N> > const& data) {
    std::cout << name << ": ";

    for (auto& a : data)
        std::cout << "{" << a[0] << "...} ";

    std::cout << "\n";
}

template <typename T>
void read_and_verify(std::string name, T& into) {
    std::ifstream ifs("/tmp/so/computer_vision/openpose/train_data/" + name);
    boost::archive::text_iarchive ia(ifs);
    ia >> into;

    debug_print(name, into);
}

int main() {
    {
        pose pose_names;
        std::vector<pose_sample_type> pose_samples; // vector of m_pose_sample vectors
        std::vector<double> pose_labels;            // vector of pose labels (eg. 1,2,3...)

        read_and_verify("pose/pose_names.txt", pose_names);
        read_and_verify("pose/pose_samples.txt", pose_samples);
        read_and_verify("pose/pose_labels.txt", pose_labels);
    }

    {
        face face_names;                            // vector of face emotions names (eg. normal, sad, happy...)
        std::vector<face_sample_type> face_samples; // vector of m_face_sample vectors
        std::vector<double> face_labels;            // vector of face emotions labels (eg. 1,2,3...)
        read_and_verify("face/face_names.txt", face_names);
        read_and_verify("face/face_samples.txt", face_samples);
        read_and_verify("face/face_labels.txt", face_labels);
    }

    {
        hand hand_names;                                    // vector of hand gesture names (eg. fist, victory, stop...);
        std::vector<hand_sample_type> left_hand_samples;    // vector of m_left_hand_sample vectors
        std::vector<hand_sample_type> right_hand_samples;   // vector of m_right_hand_sample vectors
        std::vector<double> left_hand_labels;               // vector of left hand labels (eg. 1,2,3...)
        std::vector<double> right_hand_labels;              // vector of right hand labels (eg. 1,2,3...)
        read_and_verify("hand/hand_names.txt", hand_names);
        read_and_verify("hand/left_hand_samples.txt", left_hand_samples);
        read_and_verify("hand/right_hand_samples.txt", right_hand_samples);
        read_and_verify("hand/left_hand_labels.txt", left_hand_labels);
        read_and_verify("hand/right_hand_labels.txt", right_hand_labels);
    }
}

Printing (lines truncated at 100 characters):

pose/pose_names.txt: unknown close_to_camera standing sitting 
pose/pose_samples.txt: {204.658...} {196.314...} {210.322...} {191.529...} {192.8...} {187.155...} {...
pose/pose_labels.txt: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
face/face_names.txt: unknown normal happy sad surprise 
face/face_samples.txt: {89.5967...} {93.7026...} {97.6529...} {91.7247...} {91.8048...} {91.3076...}...
face/face_labels.txt: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
hand/hand_names.txt: unknown fist pinch wave victory stop thumbsup 
hand/left_hand_samples.txt: {0...} {0.000524104...} {0...} {0...} {0...} {0...} {0...} {0...} {0...}...
hand/right_hand_samples.txt: {0...} {0.00166845...} {0.00161618...} {0.00176376...} {0.00167096...} ...
hand/left_hand_labels.txt: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
hand/right_hand_labels.txt: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

BONUS:

I had to use a hack to circumvent the file-size limit on Coliru: I changed to code to read bzip2 compressed files:

#include <boost/iostreams/filter/bzip2.hpp>
#include <boost/iostreams/filtering_stream.hpp>

template <typename T>
void read_and_verify(std::string name, T& into) {
    std::ifstream compressed("/tmp/so/computer_vision/openpose/train_data/" + name + ".bz2");

    boost::iostreams::filtering_istream fs;
    fs.push(boost::iostreams::bzip2_decompressor{});
    fs.push(compressed);

    boost::archive::text_iarchive ia(fs);
    ia >> into;

    debug_print(name, into);
}

Now you can actually see the output Live On Coliru




回答2:


After replacing ::archive 14 with ::archive 12 in all txt files,this problem gone,@sehe thanks very much



来源:https://stackoverflow.com/questions/47120076/boostarchivearchive-exception-what-unsupported-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!