首页 > 其他分享 >lightweight处理关键点的顺序

lightweight处理关键点的顺序

时间:2023-01-12 10:23:19浏览次数:44  
标签:顺序 keypoints label batch converted keypoint lightweight other 关键点

 

dataset = CocoTrainDataset(prepared_train_labels, train_images_folder,
stride, sigma, path_thickness,
transform=transforms.Compose([
ConvertKeypoints(),
Scale(),
Rotate(pad=(128, 128, 128)),
CropPad(pad=(128, 128, 128)),
Flip()]))
train_loader = DataLoader(dataset, batch_size=batch_size, shuffle=True, num_workers=num_workers)

for epochId in range(current_epoch, 280):
scheduler.step()
total_losses = [0, 0] * (num_refinement_stages + 1) # heatmaps loss, paf loss per stage
batch_per_iter_idx = 0
for batch_data in train_loader:
if batch_per_iter_idx == 0:
optimizer.zero_grad()

images = batch_data['image'].cuda()
keypoint_masks = batch_data['keypoint_mask'].cuda()
paf_masks = batch_data['paf_mask'].cuda()
keypoint_maps = batch_data['keypoint_maps'].cuda()
paf_maps = batch_data['paf_maps'].cuda()

这一部分先看CocoTrainDataset。CocoTrainDataset里发现convertkeypoints对读取的关键点顺序做更改自己做heatmap和paf。

class ConvertKeypoints:
def __call__(self, sample):
label = sample['label']
h, w, _ = sample['image'].shape
keypoints = label['keypoints']
for keypoint in keypoints: # keypoint[2] == 0: occluded, == 1: visible, == 2: not in image
if keypoint[0] == keypoint[1] == 0:
keypoint[2] = 2
if (keypoint[0] < 0
or keypoint[0] >= w
or keypoint[1] < 0
or keypoint[1] >= h):
keypoint[2] = 2
for other_label in label['processed_other_annotations']:
keypoints = other_label['keypoints']
for keypoint in keypoints:
if keypoint[0] == keypoint[1] == 0:
keypoint[2] = 2
if (keypoint[0] < 0
or keypoint[0] >= w
or keypoint[1] < 0
or keypoint[1] >= h):
keypoint[2] = 2
label['keypoints'] = self._convert(label['keypoints'], w, h)

for other_label in label['processed_other_annotations']:
other_label['keypoints'] = self._convert(other_label['keypoints'], w, h)
return sample

def _convert(self, keypoints, w, h):
# Nose, Neck, R hand, L hand, R leg, L leg, Eyes, Ears
reorder_map = [1, 7, 9, 11, 6, 8, 10, 13, 15, 17, 12, 14, 16, 3, 2, 5, 4]
converted_keypoints = list(keypoints[i - 1] for i in reorder_map)
converted_keypoints.insert(1, [(keypoints[5][0] + keypoints[6][0]) / 2,
(keypoints[5][1] + keypoints[6][1]) / 2, 0]) # Add neck as a mean of shoulders
if keypoints[5][2] == 2 or keypoints[6][2] == 2:
converted_keypoints[1][2] = 2
elif keypoints[5][2] == 1 and keypoints[6][2] == 1:
converted_keypoints[1][2] = 1
if (converted_keypoints[1][0] < 0
or converted_keypoints[1][0] >= w
or converted_keypoints[1][1] < 0
or converted_keypoints[1][1] >= h):
converted_keypoints[1][2] = 2
return converted_keypoints

从这个函数看出来调换的keypoint位置自己做的脖子用未调换的做出来。然后放到1位置。

标签:顺序,keypoints,label,batch,converted,keypoint,lightweight,other,关键点
From: https://www.cnblogs.com/hahaah/p/17045712.html

相关文章

  • C++实现顺序队列(循环队列)相关操作代码
    #include<iostream>#include<cstdlib>usingnamespacestd;#defineMAXSIZE100#defineOK1#defineERROR0#defineOVERFLOW-1typedefintStatus;typedefintElemtype......
  • 记录一次低级错误,关于if语句||的使用是有顺序的
    if(lbhResult==null||lbhResult.Tables[0].Rows.Count==0){return;}if语句是有判断的先后顺序的,从左......
  • C++实现顺序栈相关操作代码
    #include<iostream>#include<cstdlib>usingnamespacestd;#defineMAXSIZE100#defineOK1#defineERROR0#defineOVERFLOW-2typedefintStatus;typedefintElemtype......
  • 顺序查找-1
    #region自组织查找///<summary>//////</summary>///<paramname="arr"></param>///<paramname="sValue"></param>///<returns></returns>publicstaticint......
  • 前端面试题之Promise执行顺序
    执行的先后顺序:constp=newPromise(resolve=>{console.log('a')resolve()console.log('b')})p.then(()=>{console.log('c')})console.l......
  • 调整奇数偶数顺序
    【题目名称】调整奇数偶数顺序【题目内容】调整数组使奇数全部都位于偶数前面。题目:输入一个整数数组,实现一个函数,来调整该数组中数字的顺序使得数组中所有的奇数位于数组的......
  • SpringBoot笔记--文件配置加载顺序+整合其他框架
    内部文件配置加载顺序外部文件配置加载顺序jar包配置整合Junit若是业务管理类和测试类在同一个包下面,那么这句话,可以不加括号,只写注解名称否则,就必须指定到包......
  • 由于i++与++i的运算顺序不同而导致的死循环
    死循环的原因:i++和++i的基本功能是相同的,都是对变量i进行自增1运算,从功能上讲相当于i=i+1;两个的区别在于: inti=1,a=0; i++先运算在赋值​,例如a=i+......
  • 线性表的顺序表示
    顺序表的定义线性表的顺序存储又称顺序表.它是用一组地址连续的存储单元依次存储线性表中的数据元素,从而使逻辑上相邻的两个元素在物理位置上也相邻。publicclassInitL......
  • 顺序结构及if选择结构
    顺序结构JAVA的基本结构就是顺序结构,除非特别指明,否则就按照顺序一句一句执行。顺序结构是最简单的算法结构。语句与语句之间,框与框之间是按从上到下的顺序进行......