Skip to content

Commit

Permalink
[Enhance] refine docs and code (open-mmlab#2330)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tau-J authored May 4, 2023
1 parent d18c4bf commit 57df1e2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
34 changes: 13 additions & 21 deletions mmpose/models/losses/classification_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,10 @@ def __init__(self, beta=1.0, label_softmax=False, use_target_weight=True):

def criterion(self, dec_outs, labels):
"""Criterion function."""

scores = self.log_softmax(dec_outs * self.beta)
log_pt = self.log_softmax(dec_outs * self.beta)
if self.label_softmax:
labels = F.softmax(labels * self.beta, dim=1)
loss = torch.mean(self.kl_loss(scores, labels), dim=1)
loss = torch.mean(self.kl_loss(log_pt, labels), dim=1)
return loss

def forward(self, pred_simcc, gt_simcc, target_weight):
Expand All @@ -156,26 +155,19 @@ def forward(self, pred_simcc, gt_simcc, target_weight):
target_weight (torch.Tensor[N, K] or torch.Tensor[N]):
Weights across different labels.
"""
output_x, output_y = pred_simcc
target_x, target_y = gt_simcc
num_joints = output_x.size(1)
num_joints = pred_simcc[0].size(1)
loss = 0

for idx in range(num_joints):
coord_x_pred = output_x[:, idx].squeeze()
coord_y_pred = output_y[:, idx].squeeze()
coord_x_gt = target_x[:, idx].squeeze()
coord_y_gt = target_y[:, idx].squeeze()

if self.use_target_weight:
weight = target_weight[:, idx].squeeze()
else:
weight = 1.

loss += (
self.criterion(coord_x_pred, coord_x_gt).mul(weight).sum())
loss += (
self.criterion(coord_y_pred, coord_y_gt).mul(weight).sum())
if self.use_target_weight:
weight = target_weight.reshape(-1)
else:
weight = 1.

for pred, target in zip(pred_simcc, gt_simcc):
pred = pred.reshape(-1, pred.size(-1))
target = target.reshape(-1, target.size(-1))

loss += self.criterion(pred, target).mul(weight).sum()

return loss / num_joints

Expand Down
10 changes: 6 additions & 4 deletions projects/rtmpose/examples/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Examples

## List of examples

### 1. RTMPose-Deploy
### 1. RTMPose-Deploy (without MMDeploy)

RTMPose-Deploy is a C ++ code example that does not use MMDEPLOY for RTMPose localized deployment.
RTMPose-Deploy is a C++ code example that does not use MMDEPLOY for RTMPose localized deployment.

- [Original Repository](https://github.com/HW140701/RTMPose-Deploy)

#### 2. RTMPose inference with ONNXRuntime (Python)

This example shows how to run RTMPose inference with ONNXRuntime in Python.
2 changes: 1 addition & 1 deletion projects/rtmpose/examples/RTMPose-Deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ RTMPose-Deploy is a C ++ code example that does **NOT** use MMDEPLOY for RTMPose

At present, RTMPose-Deploy has completed the deployment of RTMDetnano and RTMPose on the Windows system. This example only contains the source code. If you want a complete project example, please refer to:[https://github.com/HW140701/RTMPose-Deploy](https://github.com/HW140701/RTMPose-Deploy) . This project provides a complete VS2019 project and release package.

Subsequent will consider adding the use of C ++ Tensorrt SDK on the Windows system to deploy RTMDetnano and RTMPose.
Subsequent will consider adding the use of C ++ Tensorrt SDK on the Windows system to deploy RTMDet-nano and RTMPose.

0 comments on commit 57df1e2

Please sign in to comment.