在mmclassification0.25.0这个版本中,获取图片id的代码在什么位置
时间: 2024-03-01 22:53:53 浏览: 26
在 mmclassification0.25.0 版本中,获取图片 ID 的代码在 `mmcls/datasets/pipelines/formatting.py` 文件中的 `DefaultFormatBundle` 类的 `__call__` 函数中。
具体来说,`__call__` 函数会将数据按照指定的格式进行打包,其中包括数据 ID。部分代码如下:
```python
class DefaultFormatBundle(object):
"""Default formatting bundle.
It simplifies the pipeline of formatting common fields, including "img",
"proposals", "gt_bboxes", "gt_labels", "gt_masks", "gt_semantic_seg",
"gt_semantic_seg" and "group_flags". If you want to use your own format,
please refer to this implementation to write your own format bundle.
Args:
to_tensor (dict): Keys are the names of fields to be converted to
tensor. Values are dicts indicating the parameters of the
`to_tensor` function. Keys of the inner dicts are the arguments
of the `to_tensor` function.
"""
def __init__(self, to_tensor=None):
self.to_tensor = to_tensor if to_tensor is not None else {}
def __call__(self, results):
"""Call function to format results.
Args:
results (dict): The resulting dict to be modified and passed
to the next transform in pipeline.
Returns:
dict: The modified result dict, which includes the following keys.
- img (Tensor): Tensor of images.
- proprosals (Tensor): Proposals.
- gt_bboxes (Tensor): Ground truth boxes.
- gt_labels (Tensor): Ground truth labels.
- gt_masks (Tensor): Ground truth masks.
- gt_semantic_seg (Tensor): Ground truth semantic segmentation
maps.
- gt_semantic_seg (Tensor): Ground truth semantic segmentation
maps.
- group_flags (Tensor): Group flags.
"""
# format fields as tensor
for key in self.to_tensor:
if key not in results:
continue
results[key] = to_tensor(results[key], **self.to_tensor[key])
results = collect(results, keys=['img', 'proposals', 'gt_bboxes',
'gt_labels', 'gt_masks',
'gt_semantic_seg', 'group_flags'])
# get image file name as "id" field
if 'filename' in results['img_metas'][0]:
results['id'] = results['img_metas'][0]['filename']
elif 'ori_filename' in results['img_metas'][0]:
results['id'] = results['img_metas'][0]['ori_filename']
else:
raise ValueError('Image must have "filename" or "ori_filename" '
f'in meta info, but found {results["img_metas"][0]}.')
return results
```
其中,通过 `if 'filename' in results['img_metas'][0]:` 和 `elif 'ori_filename' in results['img_metas'][0]:` 判断图片 ID 的来源,分别将图片文件名或原始文件名作为 ID。最终通过 `results['id'] = ...` 将图片 ID 存入结果字典中返回。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)