Tf-pose-estimation: Where do I go to find _pafprocess module.

Created on 25 May 2018  ·  9Comments  ·  Source: ildoonet/tf-pose-estimation

@ildoonet @leighton @kimdwkimdw @toshiy104 when i run python3 src/run.py --model=mobilenet_thin --resolution=432x368 --image=images/cat.jpg an error occur, how can i import _pafprocess,Where do I go to find this module.
File "/home/tf-openpose/src/pafprocess/pafprocess.py", line 28, in
_pafprocess = swig_import_helper()
File "/home/tf-openpose/src/pafprocess/pafprocess.py", line 20, in swig_import_helper
import _pafprocess
ModuleNotFoundError: No module named '_pafprocess'

Most helpful comment

  1. Go to tf-pose-estimation/tree/master/src/pafprocess
  2. Run
    $ sudo apt install swig
    $ swig -python -c++ pafprocess.i && python3 setup.py build_ext --inplace

@measke, I think this c++ program is written for linux. You may need to check with different compiler on windows. Am i right @ildoonet ?

All 9 comments

I could use some directions or help on how to get the pafprocess compiled correctly. I downloaded Swig and Visual Studio Build Tools, however I'm getting some errors and do not know how to fix them. Please see attached terminal log.
error.txt

probably tf-pose-estimation does not support windows.
my environment is nvidia-docker on ubuntu 18.04.

On 2018/05/25 19:59, measke wrote:
>

I could use some directions or help on how to get the pafprocess compiled
correctly. I downloaded Swig and Visual Stodio Build Tools, however I'm
getting some errors and do not know how to fix them. Please see attached
terminal log.
error.txt https://github.com/ildoonet/tf-pose-estimation/files/2039054/error.txt


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/ildoonet/tf-pose-estimation/issues/177#issuecomment-392018156,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABjY2Q0FDfzLNl1u0T15gwQ3qitnDVbzks5t1-QDgaJpZM4UNNEO.

--

安井 俊之 [email protected]
TakumiVision株式会社
〒 600-8310
京都府京都市下京区夷之町686-3 コタニビル3F
TEL: 075-354-7808 FAX: 075-365-2238

http://www.takumivision.co.jp

I'm trying to follow this tutorial, which has tf-pose-estimation working on windows: https://www.youtube.com/watch?v=nUjGLjOmF7o

However I run into the error described above and need directions/help with compiling the pafprocess.

  1. Go to tf-pose-estimation/tree/master/src/pafprocess
  2. Run
    $ sudo apt install swig
    $ swig -python -c++ pafprocess.i && python3 setup.py build_ext --inplace

@measke, I think this c++ program is written for linux. You may need to check with different compiler on windows. Am i right @ildoonet ?

I don't have windows machine so I didn't check.

But I guess that.. if swig is working for windows, it will work.

After I modified some of pafprocess.cpp, I could build and run it on windows

On 2018/05/27 23:16, Ildoo Kim wrote:
>

I don't have windows machine so I didn't check.

But I guess that.. if swig is working for windows, it will work.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/ildoonet/tf-pose-estimation/issues/177#issuecomment-392334164,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABjY2YPNFECrSwtWfbVqqWFoA14DH1npks5t2rU2gaJpZM4UNNEO.

--

安井 俊之 [email protected]
TakumiVision株式会社
〒 600-8310
京都府京都市下京区夷之町686-3 コタニビル3F
TEL: 075-354-7808 FAX: 075-365-2238

http://www.takumivision.co.jp

include

include

include

include "pafprocess.h"

define PEAKS(i, j, k) peaks[k+p3(j+p2i)]

define HEAT(i, j, k) heatmap[k+h3(j+h2i)]

define PAF(i, j, k) pafmap[k+f3(j+f2i)]

using namespace std;

vector > subset;
vector peak_infos_line;

int tf_round(float v);
vector get_paf_vectors(float *pafmap, const int& ch_id1, const int& ch_id2, int& f2, int& f3, Peak& peak1, Peak& peak2);
bool comp_candidate(ConnectionCandidate a, ConnectionCandidate b);

int process_paf(int p1, int p2, int p3, float *peaks, int h1, int h2, int h3, float *heatmap, int f1, int f2, int f3, float *pafmap) {
// const int THRE_CNT = 4;
// const double THRESH_PAF = 0.40;
vector peak_infos[NUM_PART];
int peak_cnt = 0;
for (int part_id = 0; part_id < NUM_PART; part_id ++) {
for (int y = 0; y < p1; y ++) {
for (int x = 0; x < p2; x ++) {
if (PEAKS(y, x, part_id) > THRESH_HEAT) {
Peak info;
info.id = peak_cnt++;
info.x = x;
info.y = y;
info.score = HEAT(y, x, part_id);
peak_infos[part_id].push_back(info);
}
}
}
}

peak_infos_line.clear();
for (int part_id = 0; part_id < NUM_PART; part_id ++) {
    for (int i = 0; i < (int) peak_infos[part_id].size(); i ++) {
        peak_infos_line.push_back(peak_infos[part_id][i]);
    }
}

// Start to Connect
vector<Connection> connection_all[COCOPAIRS_SIZE];
for (int pair_id = 0; pair_id < COCOPAIRS_SIZE; pair_id ++) {
    vector<ConnectionCandidate> candidates;
    vector<Peak>& peak_a_list = peak_infos[COCOPAIRS[pair_id][0]];
    vector<Peak>& peak_b_list = peak_infos[COCOPAIRS[pair_id][1]];

    if (peak_a_list.size() == 0 || peak_b_list.size() == 0) {
        continue;
    }

    for (int peak_a_id = 0; peak_a_id < (int) peak_a_list.size(); peak_a_id ++) {
        Peak& peak_a = peak_a_list[peak_a_id];
        for (int peak_b_id = 0; peak_b_id < (int) peak_b_list.size(); peak_b_id ++) {
            Peak& peak_b = peak_b_list[peak_b_id];

            // calculate vector(direction)
            VectorXY vec;
            vec.x = peak_b.x - peak_a.x;
            vec.y = peak_b.y - peak_a.y;
            float norm = (float) sqrt(vec.x * vec.x + vec.y * vec.y);
            if (norm < 1e-12) continue;
            vec.x = vec.x / norm;
            vec.y = vec.y / norm;

            vector<VectorXY> paf_vecs = get_paf_vectors(pafmap, COCOPAIRS_NET[pair_id][0], COCOPAIRS_NET[pair_id][1], f2, f3, peak_a, peak_b);
            float scores = 0.0f;

            // criterion 1 : score treshold count
            int criterion1 = 0;
            for (int i = 0; i < STEP_PAF; i ++) {
                float score = vec.x * paf_vecs[i].x + vec.y * paf_vecs[i].y;
                scores += score;

                if (score > THRESH_VECTOR_SCORE) criterion1 += 1;
            }

            float criterion2 = scores / STEP_PAF + min(0.0, 0.5 * h1 / norm - 1.0);

            if (criterion1 > THRESH_VECTOR_CNT1 && criterion2 > 0) {
                ConnectionCandidate candidate;
                candidate.idx1 = peak_a_id;
                candidate.idx2 = peak_b_id;
                candidate.score = criterion2;
                candidate.etc = criterion2 + peak_a.score + peak_b.score;
                candidates.push_back(candidate);
            }
        }
    }

    vector<Connection>& conns = connection_all[pair_id];
    sort(candidates.begin(), candidates.end(), comp_candidate);
    for (int c_id = 0; c_id < (int) candidates.size(); c_id ++) {
        ConnectionCandidate& candidate = candidates[c_id];
        bool assigned = false;
        for (int conn_id = 0; conn_id < (int) conns.size(); conn_id ++) {
            if (conns[conn_id].peak_id1 == candidate.idx1) {
                // already assigned
                assigned = true;
                break;
            }
            if (assigned) break;
            if (conns[conn_id].peak_id2 == candidate.idx2) {
                // already assigned
                assigned = true;
                break;
            }
            if (assigned) break;
        }
        if (assigned) continue;

        Connection conn;
        conn.peak_id1 = candidate.idx1;
        conn.peak_id2 = candidate.idx2;
        conn.score = candidate.score;
        conn.cid1 = peak_a_list[candidate.idx1].id;
        conn.cid2 = peak_b_list[candidate.idx2].id;
        conns.push_back(conn);
    }
}

// Generate subset
subset.clear();
for (int pair_id = 0; pair_id < COCOPAIRS_SIZE; pair_id ++) {
    vector<Connection>& conns = connection_all[pair_id];
    int part_id1 = COCOPAIRS[pair_id][0];
    int part_id2 = COCOPAIRS[pair_id][1];

    for (int conn_id = 0; conn_id < (int) conns.size(); conn_id ++) {
        int found = 0;
        int subset_idx1=0, subset_idx2=0;
        for (int subset_id = 0; subset_id < (int) subset.size(); subset_id ++) {
            if (subset[subset_id][part_id1] == conns[conn_id].cid1 || subset[subset_id][part_id2] == conns[conn_id].cid2) {
                if (found == 0) subset_idx1 = subset_id;
                if (found == 1) subset_idx2 = subset_id;
                found += 1;
            }
        }

        if (found == 1) {
            if (subset[subset_idx1][part_id2] != conns[conn_id].cid2) {
                subset[subset_idx1][part_id2] = conns[conn_id].cid2;
                subset[subset_idx1][19] += 1;
                subset[subset_idx1][18] += peak_infos_line[conns[conn_id].cid2].score + conns[conn_id].score;
            }
        } else if (found == 2) {
            int membership;
            for (int subset_id = 0; subset_id < 18; subset_id ++) {
                if (subset[subset_idx1][subset_id] > 0 && subset[subset_idx2][subset_id] > 0) {
                    membership = 2;
                }
            }

            if (membership == 0) {
                for (int subset_id = 0; subset_id < 18; subset_id ++) subset[subset_idx1][subset_id] += (subset[subset_idx2][subset_id] + 1);

                subset[subset_idx1][19] += subset[subset_idx2][19];
                subset[subset_idx1][18] += subset[subset_idx2][18];
                subset[subset_idx1][18] += conns[conn_id].score;
                subset.erase(subset.begin() + subset_idx2);
            } else {
                subset[subset_idx1][part_id2] = conns[conn_id].cid2;
                subset[subset_idx1][19] += 1;
                subset[subset_idx1][18] += peak_infos_line[conns[conn_id].cid2].score + conns[conn_id].score;
            }
        } else if (found == 0 && pair_id < 17) {
            vector<float> row(20);
            for (int i = 0; i < 20; i ++) row[i] = -1;
            row[part_id1] = conns[conn_id].cid1;
            row[part_id2] = conns[conn_id].cid2;
            row[19] = 2;
            row[18] = peak_infos_line[conns[conn_id].cid1].score +
                      peak_infos_line[conns[conn_id].cid2].score +
                      conns[conn_id].score;
            subset.push_back(row);
        }
    }
}

// delete some rows
for (int i = subset.size() - 1; i >= 0; i --) {
    if (subset[i][19] < THRESH_PART_CNT || subset[i][18] / subset[i][19] < THRESH_HUMAN_SCORE)
        subset.erase(subset.begin() + i);
}

return 0;

}

int get_num_humans() {
return subset.size();
}

int get_part_cid(int human_id, int part_id) {
return subset[human_id][part_id];
}

float get_score(int human_id) {
return subset[human_id][18] / subset[human_id][19];
}

int get_part_x(int cid) {
return peak_infos_line[cid].x;
}
int get_part_y(int cid) {
return peak_infos_line[cid].y;
}
float get_part_score(int cid) {
return peak_infos_line[cid].score;
}

vector get_paf_vectors(float *pafmap, const int& ch_id1, const int& ch_id2, int& f2, int& f3, Peak& peak1, Peak& peak2) {
vector paf_vectors;

const float STEP_X = (peak2.x - peak1.x) / float(STEP_PAF);
const float STEP_Y = (peak2.y - peak1.y) / float(STEP_PAF);

for (int i = 0; i < STEP_PAF; i ++) {
    int location_x = tf_round(peak1.x + i * STEP_X);
    int location_y = tf_round(peak1.y + i * STEP_Y);

    VectorXY v;
    v.x = PAF(location_y, location_x, ch_id1);
    v.y = PAF(location_y, location_x, ch_id2);
    paf_vectors.push_back(v);
}

return paf_vectors;

}

int tf_round(float v) {
return (int) (v + 0.5);
}

bool comp_candidate(ConnectionCandidate a, ConnectionCandidate b) {
return a.score > b.score;
}

I have compiled again according to the tutorial,but the error still occur.I cry but I can't cry.

@cognitiveRobot thank you!!! we could try as he said when we met this problem.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

guofuzheng picture guofuzheng  ·  6Comments

zerolim820 picture zerolim820  ·  3Comments

gavinzhang1995 picture gavinzhang1995  ·  6Comments

vladbelo picture vladbelo  ·  4Comments

jpizarrom picture jpizarrom  ·  6Comments