Commit 86b64e4e by baihe

updated

parent fa59fd22
...@@ -11,5 +11,5 @@ _ext ...@@ -11,5 +11,5 @@ _ext
tmp tmp
*.o* *.o*
*~ *~
.idea .idea/
.DS_Store .DS_Store
\ No newline at end of file
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<component name="PyNamespacePackagesService"> <component name="PyNamespacePackagesService">
<option name="namespacePackageFolders"> <option name="namespacePackageFolders">
<list> <list>
<option value="$MODULE_DIR$/models" /> <option value="$MODULE_DIR$/mymodels" />
</list> </list>
</option> </option>
</component> </component>
......
...@@ -22,8 +22,8 @@ class TinyYOLOv3_onecls(object): ...@@ -22,8 +22,8 @@ class TinyYOLOv3_onecls(object):
""" """
def __init__(self, def __init__(self,
input_size=416, input_size=416,
config_file='models/yolo-tiny-onecls/yolov3-tiny-onecls.cfg', config_file='mymodels/yolo-tiny-onecls/yolov3-tiny-onecls.cfg',
weight_file='models/yolo-tiny-onecls/best-model.pth', weight_file='mymodels/yolo-tiny-onecls/best-model.pth',
nms=0.2, nms=0.2,
conf_thres=0.45, conf_thres=0.45,
device='cuda'): device='cuda'):
......
...@@ -4,7 +4,7 @@ import os ...@@ -4,7 +4,7 @@ import os
import torch import torch
import numpy as np import numpy as np
import torch.utils.data import torch.utils.data
import utils.img import myutils.img
class GenerateHeatmap(): class GenerateHeatmap():
def __init__(self, output_res, num_parts): def __init__(self, output_res, num_parts):
...@@ -64,10 +64,10 @@ class Dataset(torch.utils.data.Dataset): ...@@ -64,10 +64,10 @@ class Dataset(torch.utils.data.Dataset):
s = ds.get_scale(idx) s = ds.get_scale(idx)
normalize = ds.get_normalized(idx) normalize = ds.get_normalized(idx)
cropped = utils.img.crop(orig_img, c, s, (self.input_res, self.input_res)) cropped = myutils.img.crop(orig_img, c, s, (self.input_res, self.input_res))
for i in range(np.shape(orig_keypoints)[1]): for i in range(np.shape(orig_keypoints)[1]):
if orig_keypoints[0,i,0] > 0: if orig_keypoints[0,i,0] > 0:
orig_keypoints[0,i,:2] = utils.img.transform(orig_keypoints[0,i,:2], c, s, (self.input_res, self.input_res)) orig_keypoints[0,i,:2] = myutils.img.transform(orig_keypoints[0,i,:2], c, s, (self.input_res, self.input_res))
keypoints = np.copy(orig_keypoints) keypoints = np.copy(orig_keypoints)
## augmentation -- to be done to cropped image ## augmentation -- to be done to cropped image
...@@ -81,11 +81,11 @@ class Dataset(torch.utils.data.Dataset): ...@@ -81,11 +81,11 @@ class Dataset(torch.utils.data.Dataset):
aug_scale = np.random.random() * (1.25 - 0.75) + 0.75 aug_scale = np.random.random() * (1.25 - 0.75) + 0.75
scale *= aug_scale scale *= aug_scale
mat_mask = utils.img.get_transform(center, scale, (self.output_res, self.output_res), aug_rot)[:2] mat_mask = myutils.img.get_transform(center, scale, (self.output_res, self.output_res), aug_rot)[:2]
mat = utils.img.get_transform(center, scale, (self.input_res, self.input_res), aug_rot)[:2] mat = myutils.img.get_transform(center, scale, (self.input_res, self.input_res), aug_rot)[:2]
inp = cv2.warpAffine(cropped, mat, (self.input_res, self.input_res)).astype(np.float32)/255 inp = cv2.warpAffine(cropped, mat, (self.input_res, self.input_res)).astype(np.float32)/255
keypoints[:,:,0:2] = utils.img.kpt_affine(keypoints[:,:,0:2], mat_mask) keypoints[:,:,0:2] = myutils.img.kpt_affine(keypoints[:,:,0:2], mat_mask)
if np.random.randint(2) == 0: if np.random.randint(2) == 0:
inp = self.preprocess(inp) inp = self.preprocess(inp)
inp = inp[:, ::-1] inp = inp[:, ::-1]
......
...@@ -2,9 +2,9 @@ import cv2 ...@@ -2,9 +2,9 @@ import cv2
import torch import torch
import data.MPII.ref as ds import data.MPII.ref as ds
import utils.img import myutils.img
from utils.group import HeatmapParser from myutils.group import HeatmapParser
from utils.posture import * from myutils.posture import *
# 歪头的斜率阈值 # 歪头的斜率阈值
CROOKED_HEAD_THRE=8 CROOKED_HEAD_THRE=8
...@@ -105,13 +105,13 @@ def post_process(det, mat_, trainval, c=None, s=None, resolution=None): ...@@ -105,13 +105,13 @@ def post_process(det, mat_, trainval, c=None, s=None, resolution=None):
cropped_preds = parser.parse(np.float32([det]))[0] cropped_preds = parser.parse(np.float32([det]))[0]
if len(cropped_preds) > 0: if len(cropped_preds) > 0:
cropped_preds[:, :, :2] = utils.img.kpt_affine(cropped_preds[:, :, :2] * 4, mat) # size 1x16x3 cropped_preds[:, :, :2] = myutils.img.kpt_affine(cropped_preds[:, :, :2] * 4, mat) # size 1x16x3
preds = np.copy(cropped_preds) preds = np.copy(cropped_preds)
##for inverting predictions from input res on cropped to original image ##for inverting predictions from input res on cropped to original image
if trainval != 'cropped': if trainval != 'cropped':
for j in range(preds.shape[1]): for j in range(preds.shape[1]):
preds[0, j, :2] = utils.img.transform(preds[0, j, :2], c, s, resolution, invert=1) preds[0, j, :2] = myutils.img.transform(preds[0, j, :2], c, s, resolution, invert=1)
return preds return preds
...@@ -130,7 +130,7 @@ def inference(img, func, config, c, s): ...@@ -130,7 +130,7 @@ def inference(img, func, config, c, s):
res = (config['train']['input_res'], config['train']['input_res']) res = (config['train']['input_res'], config['train']['input_res'])
# [[1,0,0],[0,1,0]] # [[1,0,0],[0,1,0]]
mat_ = utils.img.get_transform(center, scale, res)[:2] mat_ = myutils.img.get_transform(center, scale, res)[:2]
inp = img / 255 inp = img / 255
def array2dict(tmp): def array2dict(tmp):
...@@ -190,17 +190,26 @@ if __name__ == '__main__': ...@@ -190,17 +190,26 @@ if __name__ == '__main__':
input_res = 256 input_res = 256
orig_img = cv2.imread(image_path) orig_img = cv2.imread(image_path)
orig_img_reverse = cv2.imread(image_path)[:,:,::-1] orig_img_reverse = cv2.imread(image_path)[:,:,::-1]
shape = orig_img_reverse.shape[0:2]
shape = orig_img_reverse.shape[0:2]
# 这里需要使用yolo检测图片中的人体矩形区域,返回矩形的中心和矩形较长边的边长/200 # 这里需要使用yolo检测图片中的人体矩形区域,返回矩形的中心和矩形较长边的边长/200
# 这里要起一个yolo5的服务。因为yolo5的模型的相对路径已经定死了,无法直接引入到项目中。除非通过命令行的方式 # 这里要起一个yolo5的服务。因为yolo5的模型的相对路径已经定死了,无法直接引入到项目中。除非通过命令行的方式
import requests # import requests
DETECTION_URL = "http://localhost:5000/v1/object-detection/yolov5s" # DETECTION_URL = "http://localhost:5000/v1/object-detection/yolov5s"
image_data = open(image_path, "rb").read() # image_data = open(image_path, "rb").read()
response = requests.post(DETECTION_URL, files={"image": image_data}).json() # response = requests.post(DETECTION_URL, files={"image": image_data}).json()
# for box in response:
# if box['class']!=0:
# continue
# else:
# c = [(box['xmax']+box['xmin'])/2,(box['ymax']+box['ymin'])/2]
# s = max((box['xmax']-box['xmin'])/200,(box['ymax']-box['ymin'])/200)+1
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
response = model(image_path).pandas().xyxy[0].to_dict(orient='records')
for box in response: for box in response:
if box['class']!=0: if box['class']!=0:
continue continue
...@@ -211,7 +220,7 @@ if __name__ == '__main__': ...@@ -211,7 +220,7 @@ if __name__ == '__main__':
# # 矩形中心坐标点 # # 矩形中心坐标点
# # 缩放比例 实验结果:720*1280的图片,人物占据大部分的情况下,7比较好。 # # 缩放比例 实验结果:720*1280的图片,人物占据大部分的情况下,7比较好。
# s = 7 # s = 7
im = utils.img.crop(orig_img_reverse,c,s,(input_res,input_res)) im = myutils.img.crop(orig_img_reverse,c,s,(input_res,input_res))
pred = do(im,c,s) pred = do(im,c,s)
......
import torch import torch
from torch import nn from torch import nn
from models.layers import Conv, Hourglass, Pool, Residual from mymodels.layers import Conv, Hourglass, Pool, Residual
from task.loss import HeatmapLoss from task.loss import HeatmapLoss
class UnFlatten(nn.Module): class UnFlatten(nn.Module):
......
...@@ -7,11 +7,11 @@ import numpy as np ...@@ -7,11 +7,11 @@ import numpy as np
from torch import nn from torch import nn
import os import os
from torch.nn import DataParallel from torch.nn import DataParallel
from utils.misc import make_input, make_output, importNet from myutils.misc import make_input, make_output, importNet
__config__ = { __config__ = {
'data_provider': 'data.MPII.dp', 'data_provider': 'data.MPII.dp',
'network': 'models.posenet.PoseNet', 'network': 'mymodels.posenet.PoseNet',
'inference': { 'inference': {
'nstack': 8, 'nstack': 8,
'inp_dim': 256, 'inp_dim': 256,
...@@ -80,7 +80,7 @@ def make_network(configs): ...@@ -80,7 +80,7 @@ def make_network(configs):
## creating new posenet ## creating new posenet
print(configs['network']) print(configs['network'])
configs['network'] = "models.posenet.PoseNet" configs['network'] = "mymodels.posenet.PoseNet"
PoseNet = importNet(configs['network']) PoseNet = importNet(configs['network'])
poseNet = PoseNet(**config) poseNet = PoseNet(**config)
# forward_net = DataParallel(poseNet.cuda()) # forward_net = DataParallel(poseNet.cuda())
......
...@@ -6,8 +6,8 @@ import numpy as np ...@@ -6,8 +6,8 @@ import numpy as np
import h5py import h5py
import copy import copy
from utils.group import HeatmapParser from myutils.group import HeatmapParser
import utils.img import myutils.img
import data.MPII.ref as ds import data.MPII.ref as ds
parser = HeatmapParser() parser = HeatmapParser()
...@@ -18,13 +18,13 @@ def post_process(det, mat_, trainval, c=None, s=None, resolution=None): ...@@ -18,13 +18,13 @@ def post_process(det, mat_, trainval, c=None, s=None, resolution=None):
cropped_preds = parser.parse(np.float32([det]))[0] cropped_preds = parser.parse(np.float32([det]))[0]
if len(cropped_preds) > 0: if len(cropped_preds) > 0:
cropped_preds[:,:,:2] = utils.img.kpt_affine(cropped_preds[:,:,:2] * 4, mat) #size 1x16x3 cropped_preds[:,:,:2] = myutils.img.kpt_affine(cropped_preds[:,:,:2] * 4, mat) #size 1x16x3
preds = np.copy(cropped_preds) preds = np.copy(cropped_preds)
##for inverting predictions from input res on cropped to original image ##for inverting predictions from input res on cropped to original image
if trainval != 'cropped': if trainval != 'cropped':
for j in range(preds.shape[1]): for j in range(preds.shape[1]):
preds[0,j,:2] = utils.img.transform(preds[0,j,:2], c, s, resolution, invert=1) preds[0,j,:2] = myutils.img.transform(preds[0,j,:2], c, s, resolution, invert=1)
return preds return preds
def inference(img, func, config, c, s): def inference(img, func, config, c, s):
...@@ -38,7 +38,7 @@ def inference(img, func, config, c, s): ...@@ -38,7 +38,7 @@ def inference(img, func, config, c, s):
scale = max(height, width)/200 scale = max(height, width)/200
res = (config['train']['input_res'], config['train']['input_res']) res = (config['train']['input_res'], config['train']['input_res'])
mat_ = utils.img.get_transform(center, scale, res)[:2] mat_ = myutils.img.get_transform(center, scale, res)[:2]
inp = img/255 inp = img/255
def array2dict(tmp): def array2dict(tmp):
...@@ -158,7 +158,7 @@ def get_img(config, num_eval=2958, num_train=300): ...@@ -158,7 +158,7 @@ def get_img(config, num_eval=2958, num_train=300):
orig_img = cv2.imread(path_t)[:,:,::-1] orig_img = cv2.imread(path_t)[:,:,::-1]
c = train_f['center'][i] c = train_f['center'][i]
s = train_f['scale'][i] s = train_f['scale'][i]
im = utils.img.crop(orig_img, c, s, (input_res, input_res)) im = myutils.img.crop(orig_img, c, s, (input_res, input_res))
## kp ## kp
kp = train_f['part'][i] kp = train_f['part'][i]
...@@ -182,7 +182,7 @@ def get_img(config, num_eval=2958, num_train=300): ...@@ -182,7 +182,7 @@ def get_img(config, num_eval=2958, num_train=300):
orig_img = cv2.imread(path_t)[:,:,::-1] orig_img = cv2.imread(path_t)[:,:,::-1]
c = val_f['center'][i] c = val_f['center'][i]
s = val_f['scale'][i] s = val_f['scale'][i]
im = utils.img.crop(orig_img, c, s, (input_res, input_res)) im = myutils.img.crop(orig_img, c, s, (input_res, input_res))
## kp ## kp
kp = val_f['part'][i] kp = val_f['part'][i]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment