Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Fix inferencer argument name #2627

Merged
merged 4 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/en/user_guides/inference.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ The inferencer is designed for both visualization and saving predictions. The ta
| `num_instances` | Sets the number of instances to visualize in the results. If set to a negative number, all detected instances will be visualized. | ❌ | ✔️ |
| `return_vis` | Decides whether to include visualization images in the results. | ✔️ | ✔️ |
| `vis_out_dir` | Defines the folder path to save the visualization images. If unset, the visualization images will not be saved. | ✔️ | ✔️ |
| `return_datasample` | Determines if the prediction should be returned in the `PoseDataSample` format. | ✔️ | ✔️ |
| `return_datasamples` | Determines if the prediction should be returned in the `PoseDataSample` format. | ✔️ | ✔️ |
| `pred_out_dir` | Specifies the folder path to save the predictions. If unset, the predictions will not be saved. | ✔️ | ✔️ |
| `out_dir` | If `vis_out_dir` or `pred_out_dir` is unset, these will be set to `f'{out_dir}/visualization'` or `f'{out_dir}/predictions'`, respectively. | ✔️ | ✔️ |

Expand Down
2 changes: 1 addition & 1 deletion docs/zh_cn/user_guides/inference.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ result = next(result_generator)
| `num_instances` | 设置可视化结果中显示的实例数量。如果设置为负数,则所有实例的结果都会可视化。 | ❌ | ✔️ |
| `return_vis` | 决定是否在结果中包含可视化图像。 | ✔️ | ✔️ |
| `vis_out_dir` | 定义保存可视化图像的文件夹路径。如果未设置,将不保存可视化图像。 | ✔️ | ✔️ |
| `return_datasample` | 决定是否以 `PoseDataSample` 格式返回预测。 | ✔️ | ✔️ |
| `return_datasamples` | 决定是否以 `PoseDataSample` 格式返回预测。 | ✔️ | ✔️ |
| `pred_out_dir` | 指定保存预测的文件夹路径。如果未设置,将不保存预测。 | ✔️ | ✔️ |
| `out_dir` | 如果 `vis_out_dir` 或 `pred_out_dir` 未设置,它们将分别设置为 `f'{out_dir}/visualization'` 或 `f'{out_dir}/predictions'`。 | ✔️ | ✔️ |

Expand Down
8 changes: 4 additions & 4 deletions mmpose/apis/inferencers/base_mmpose_inferencer.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def postprocess(
self,
preds: List[PoseDataSample],
visualization: List[np.ndarray],
return_datasample=False,
return_datasamples=False,
pred_out_dir: str = '',
) -> dict:
"""Process the predictions and visualization results from ``forward``
Expand All @@ -399,7 +399,7 @@ def postprocess(
Args:
preds (List[Dict]): Predictions of the model.
visualization (np.ndarray): Visualized predictions.
return_datasample (bool): Whether to return results as
return_datasamples (bool): Whether to return results as
datasamples. Defaults to False.
pred_out_dir (str): Directory to save the inference results w/o
visualization. If left as empty, no file will be saved.
Expand All @@ -412,7 +412,7 @@ def postprocess(
- ``visualization (Any)``: Returned by :meth:`visualize`
- ``predictions`` (dict or DataSample): Returned by
:meth:`forward` and processed in :meth:`postprocess`.
If ``return_datasample=False``, it usually should be a
If ``return_datasamples=False``, it usually should be a
json-serializable dict containing only basic data elements such
as strings and numbers.
"""
Expand All @@ -421,7 +421,7 @@ def postprocess(

result_dict['visualization'] = visualization
for pred in preds:
if not return_datasample:
if not return_datasamples:
# convert datasamples to list of instance predictions
pred = split_instances(pred.pred_instances)
result_dict['predictions'].append(pred)
Expand Down
7 changes: 4 additions & 3 deletions mmpose/apis/inferencers/mmpose_inferencer.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def forward(self, inputs: InputType, **forward_kwargs) -> PredType:
def __call__(
self,
inputs: InputsType,
return_datasample: bool = False,
return_datasamples: bool = False,
batch_size: int = 1,
out_dir: Optional[str] = None,
**kwargs,
Expand All @@ -135,7 +135,7 @@ def __call__(

Args:
inputs (InputsType): Inputs for the inferencer.
return_datasample (bool): Whether to return results as
return_datasamples (bool): Whether to return results as
:obj:`BaseDataElement`. Defaults to False.
batch_size (int): Batch size. Defaults to 1.
out_dir (str, optional): directory to save visualization
Expand Down Expand Up @@ -201,7 +201,8 @@ def __call__(

visualization = self.visualize(ori_inputs, preds,
**visualize_kwargs)
results = self.postprocess(preds, visualization, return_datasample,
results = self.postprocess(preds, visualization,
return_datasamples,
**postprocess_kwargs)
yield results

Expand Down
9 changes: 5 additions & 4 deletions mmpose/apis/inferencers/pose2d_inferencer.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def preprocess_single(self,
if self.cfg.data_mode == 'topdown':
if self.detector is not None:
det_results = self.detector(
input, return_datasample=True)['predictions']
input, return_datasamples=True)['predictions']
pred_instance = det_results[0].pred_instances.cpu().numpy()
bboxes = np.concatenate(
(pred_instance.bboxes, pred_instance.scores[:, None]),
Expand Down Expand Up @@ -257,7 +257,7 @@ def forward(self,
def __call__(
self,
inputs: InputsType,
return_datasample: bool = False,
return_datasamples: bool = False,
batch_size: int = 1,
out_dir: Optional[str] = None,
**kwargs,
Expand All @@ -266,7 +266,7 @@ def __call__(

Args:
inputs (InputsType): Inputs for the inferencer.
return_datasample (bool): Whether to return results as
return_datasamples (bool): Whether to return results as
:obj:`BaseDataElement`. Defaults to False.
batch_size (int): Batch size. Defaults to 1.
out_dir (str, optional): directory to save visualization
Expand Down Expand Up @@ -327,7 +327,8 @@ def __call__(

visualization = self.visualize(ori_inputs, preds,
**visualize_kwargs)
results = self.postprocess(preds, visualization, return_datasample,
results = self.postprocess(preds, visualization,
return_datasamples,
**postprocess_kwargs)
yield results

Expand Down
9 changes: 5 additions & 4 deletions mmpose/apis/inferencers/pose3d_inferencer.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def preprocess_single(self,
nms_thr=nms_thr,
bboxes=bboxes,
merge_results=False,
return_datasample=True))['predictions']
return_datasamples=True))['predictions']

for ds in results_pose2d:
ds.pred_instances.set_field(
Expand Down Expand Up @@ -343,7 +343,7 @@ def forward(self,
def __call__(
self,
inputs: InputsType,
return_datasample: bool = False,
return_datasamples: bool = False,
batch_size: int = 1,
out_dir: Optional[str] = None,
**kwargs,
Expand All @@ -352,7 +352,7 @@ def __call__(

Args:
inputs (InputsType): Inputs for the inferencer.
return_datasample (bool): Whether to return results as
return_datasamples (bool): Whether to return results as
:obj:`BaseDataElement`. Defaults to False.
batch_size (int): Batch size. Defaults to 1.
out_dir (str, optional): directory to save visualization
Expand Down Expand Up @@ -412,7 +412,8 @@ def __call__(

visualization = self.visualize(ori_inputs, preds,
**visualize_kwargs)
results = self.postprocess(preds, visualization, return_datasample,
results = self.postprocess(preds, visualization,
return_datasamples,
**postprocess_kwargs)
yield results

Expand Down
2 changes: 1 addition & 1 deletion projects/just_dance/process_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def get_keypoints_from_frame(self, image: np.ndarray) -> np.ndarray:
"""Extract keypoints from a single video frame."""

det_results = self.pose_estimator.detector(
image, return_datasample=True)['predictions']
image, return_datasamples=True)['predictions']
pred_instance = det_results[0].pred_instances

if len(pred_instance) == 0:
Expand Down