首页 > 系统相关 >想把计算一个人的相似度展成18个进程肯定不行。

想把计算一个人的相似度展成18个进程肯定不行。

时间:2023-05-03 16:46:30浏览次数:35  
标签:kpt 度展 18 self Pose keypoints np 进程 id

代码只进行了18次循环处理俩个人18个关键点的距离。单进程耗时0.001秒,多进程耗时6.34秒。

import cv2 import numpy as np from modules.keypoints import BODY_PARTS_KPT_IDS, BODY_PARTS_PAF_IDS from modules.one_euro_filter import OneEuroFilter import pandas as pd class Pose:     num_kpts = 18     kpt_names = ['nose', 'neck',                  'r_sho', 'r_elb', 'r_wri', 'l_sho', 'l_elb', 'l_wri',                  'r_hip', 'r_knee', 'r_ank', 'l_hip', 'l_knee', 'l_ank',                  'r_eye', 'l_eye',                  'r_ear', 'l_ear']     sigmas = np.array([.26, .79, .79, .72, .62, .79, .72, .62, 1.07, .87, .89, 1.07, .87, .89, .25, .25, .35, .35],                       dtype=np.float32) / 10.0     vars = (sigmas * 2) ** 2     last_id = -1     color = [0, 224, 255]
    def __init__(self, keypoints, confidence):         super().__init__()         self.all_save_image=0         self.keypoints = keypoints         self.confidence = confidence         self.bbox = Pose.get_bbox(self.keypoints)         self.id = None         self.filters = [[OneEuroFilter(), OneEuroFilter()] for _ in range(Pose.num_kpts)]
    @staticmethod     def get_bbox(keypoints):         found_keypoints = np.zeros((np.count_nonzero(keypoints[:, 0] != -1), 2), dtype=np.int32)         found_kpt_id = 0         for kpt_id in range(Pose.num_kpts):             if keypoints[kpt_id, 0] == -1:                 continue             found_keypoints[found_kpt_id] = keypoints[kpt_id]             found_kpt_id += 1         bbox = cv2.boundingRect(found_keypoints)
        return bbox
    def update_id(self, id=None):         self.id = id         if self.id is None:             self.id = Pose.last_id + 1             Pose.last_id += 1                 def update_all(self, id=None):         self.all_save_image = id         if self.all_save_image is None:             self.all_save_image = 0
                def draw(self, img):         assert self.keypoints.shape == (Pose.num_kpts, 2)
        for part_id in range(len(BODY_PARTS_PAF_IDS) - 2):             kpt_a_id = BODY_PARTS_KPT_IDS[part_id][0]             global_kpt_a_id = self.keypoints[kpt_a_id, 0]             if global_kpt_a_id != -1:                 x_a, y_a = self.keypoints[kpt_a_id]                 cv2.circle(img, (int(x_a), int(y_a)), 3, Pose.color, -1)             kpt_b_id = BODY_PARTS_KPT_IDS[part_id][1]             global_kpt_b_id = self.keypoints[kpt_b_id, 0]             if global_kpt_b_id != -1:                 x_b, y_b = self.keypoints[kpt_b_id]                 cv2.circle(img, (int(x_b), int(y_b)), 3, Pose.color, -1)             if global_kpt_a_id != -1 and global_kpt_b_id != -1:                 cv2.line(img, (int(x_a), int(y_a)), (int(x_b), int(y_b)), Pose.color, 2)

def get_similarity(a, b, threshold=0.5):     num_similar_kpt = 0     for kpt_id in range(Pose.num_kpts):         if a.keypoints[kpt_id, 0] != -1 and b.keypoints[kpt_id, 0] != -1:             distance = np.sum((a.keypoints[kpt_id] - b.keypoints[kpt_id]) ** 2)             area = max(a.bbox[2] * a.bbox[3], b.bbox[2] * b.bbox[3])             similarity = np.exp(-distance / (2 * (area + np.spacing(1)) * Pose.vars[kpt_id]))             if similarity > threshold:                 num_similar_kpt += 1     return num_similar_kpt
import time import numpy as np from concurrent.futures import ProcessPoolExecutor

def s(kpt_id,threshold=0.5):     if a.keypoints[kpt_id, 0] != -1 and b.keypoints[kpt_id, 0] != -1:         distance = np.sum((a.keypoints[kpt_id] - b.keypoints[kpt_id]) ** 2)         area = max(a.bbox[2] * a.bbox[3], b.bbox[2] * b.bbox[3])         similarity = np.exp(-distance / (2 * (area + np.spacing(1)) * Pose.vars[kpt_id]))         if similarity > threshold:             return 1 if __name__=='__main__':     keypoint=np.random.random((18,2))     pose=Pose(keypoint,1)     a=pose     b=pose     start=time.time()     get_similarity(pose,pose)     end=time.time()     print(end-start)
    ind=18     num_similar_kpt=0     start=time.time()                         with ProcessPoolExecutor() as pool:         results=pool.map(s,[i for i in range(ind)])     end=time.time()     sum1=end-start     print(sum1)

 

标签:kpt,度展,18,self,Pose,keypoints,np,进程,id
From: https://www.cnblogs.com/hahaah/p/17369235.html

相关文章

  • 用进程池的多进程和单进程分别运行查看结果
    时间single0.09075808525085449multi4.713615894317627。因此计算量不是特别大不建议使用多进程。importthreadingimporttimeind=100defsingle():  forjinrange(ind):    foriinrange(5000):      w=2*i      #print(w)......
  • 使用volatility3识别进程上下文——识别进程名欺骗、父进程欺骗、进程镂空(进程掏空)
     注意:我自己使用vol3实验了下,pslist和pstree都看不到进程的完整磁盘路径,但是使用dlllist可以。如下:PSD:\Application\volatility3-stable>python.\vol.py-fD:\book\malwarecookbook-master\malwarecookbook-master\15\6\prolaco.vmem\prolaco.vmemwindows.dlllist--......
  • 多进程的学习
    只有在I/O时thread才释放GIL让thread2运行同时thread1在进行I/O只有进行输入和输出操作thraeding才行。I/O跟cpu分开的所以进行I/O时进程会释放交给另一个进程运行。如果没有I/O的话多线程就是串行执行。线程不断的切换导致性能较低。......
  • 使用psscan检测dkom攻击——对于那些直接修改内存对象的rootkit,例如通过dkom实现进程
    pslist和psscan的区别列表:“pslist”模块使用与将在实时计算机上执行的任务列表命令相同的算法。而且,Windows任务管理器也使用相同的方法。上面提到的命令“pslist”遍历Windows内核维护的活动进程结构列表。windows内核使用EPROCESS数据结构来描述每一个......
  • CF1817C Similar Polynomials 题解
    可能更好的阅读体验题目传送门Div.1C拉格朗日差值,赛时开香槟。题目大意给定\(d\)次两个多项式\(A(x),B(x)\)。求\(s\),使得\(B(x)\equivA(x+s)\pmod{10^9+7}\),保证\(s\)存在。给出多项式的形式为给出\(x=0,1,\cdots,d\)模\(10^9+7\)的值。\(d\le2.5\times......
  • 「CTSC2018」青蕈领主
    题目点这里看题目。对于一个长度为\(m\)的、由互不相同整数组成的序列\(a\),其为“连续”的当且仅当\(\maxa-\mina=m-1\),也即\(a\)的值构成整数上一个连续的区间。给定正整数参数\(n\),有\(T\)次询问。每次询问给出一个长度为\(n\)的正整数序列\(L\),你需要求出满......
  • [PKUWC2018]猎人杀
    概率的分母在不断变化很麻烦,我们不妨令它可以打到已死的人。由于还活着的人概率之比没有变,显然是不会影响答案的。考虑容斥,设\(p(S)\)表示集合\(S\)中的人在\(1\)后被打的方案数,那么答案就是\(\sum_{S}(-1)^{|S|}p(S)\)。\(p(S)\)实际上就是无限开枪,每次不打\(S\cup\{1......
  • HJ18 识别有效的IP地址和掩码并进行分类统计
    思路:程序实现不难,困难的是看懂题目。需要右一点IP地址和子网掩码的基本知识。困难点1:255.255.255.32就是一个非法的掩码。32的二进制0b100000,不足8位,需要补全为00100000,因此1前面有‘0’是非法掩码。困难2:当成对的子网掩码或IP地址为非法时,计算为一个错误,并不再对IP地址的类别......
  • IT工具知识-18: ADB操作笔记(自用)
    Linux下的常用命令(持续更新)终端使用bashshell查询安卓设备当前活动的APP包名和活动窗口名adbshelldumpsyswindowwindows|grep-E'mCurrentFocus|mFocusedApp'启动指定app下的指定窗口app包名和活动窗口名都要提供,否则无法启动adbshellamstart包名/活动窗口......
  • 守护进程
    #终端  #进程组   #会话   #守护进程  //创建一个会话,每隔2s获取系统时间,并将时间写入到磁盘文件中#include<stdio.h>#include<sys/types.h>#include<unistd.h>#include<stdlib.h>#include<sys/stat.h>#include<fcntl.h>#include......