-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[Enhancement] Update analyze_results.py for dev-1.x #1071
[Enhancement] Update analyze_results.py for dev-1.x #1071
Conversation
result['gt_label']).set_pred_label( | ||
result['pred_label']).set_pred_score( | ||
torch.Tensor(result['pred_scores'])) | ||
img = mmcv.imread(result['img_path'], channel_order='rgb') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some images are too small to visualize, better to provide --rescale-factor
option to rescale images before visualizing them. Please refers to https://github.com/open-mmlab/mmclassification/blob/ae37d7fd276d983eba3acc2676a2f6e2d720bd69/tools/visualizations/browse_dataset.py#L64-L69
output['img_path'] = outputs[i]['img_path'] | ||
output['filename'] = Path(outputs[i]['img_path']).name | ||
output['gt_label'] = int(outputs[i]['gt_label']['label'][0]) | ||
output['pred_score'] = float( | ||
torch.max(outputs[i]['pred_label']['score']).item()) | ||
output['pred_scores'] = outputs[i]['pred_label']['score'].tolist() | ||
output['pred_label'] = int(outputs[i]['pred_label']['label'][0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not all datasets have the img_path
key. For example, the CIFAR dataset directly loads all images during initialization and only has img
key.
Better to use sample_idx
to get the data info from the dataset directly.
output['img_path'] = outputs[i]['img_path'] | |
output['filename'] = Path(outputs[i]['img_path']).name | |
output['gt_label'] = int(outputs[i]['gt_label']['label'][0]) | |
output['pred_score'] = float( | |
torch.max(outputs[i]['pred_label']['score']).item()) | |
output['pred_scores'] = outputs[i]['pred_label']['score'].tolist() | |
output['pred_label'] = int(outputs[i]['pred_label']['label'][0]) | |
output['sample_idx'] = outputs[i]['sample_idx'] | |
output['gt_label'] = outputs[i]['gt_label']['label'] | |
output['pred_score'] = float( | |
torch.max(outputs[i]['pred_label']['score']).item()) | |
output['pred_scores'] = outputs[i]['pred_label']['score'] | |
output['pred_label'] = outputs[i]['pred_label']['label'] |
And in the save_imgs
:
for result in results:
data_sample = ClsDataSample()\
.set_gt_label(result['gt_label'])\
.set_pred_label(result['pred_label'])\
.set_pred_score(result['pred_scores'])
data_info = dataset.get_data_info(result['sample_idx'])
if 'img' in data_info:
img = data_info['img']
name = str(result['sample_idx'])
elif 'img_path' in data_info:
img = mmcv.imread(data_info['img_path'], channel_order='rgb')
name = Path(data_info['img_path']).name
else:
raise ValueError('Cannot load images from the dataset infos.')
if rescale_factor is not None:
img = mmcv.imrescale(img, rescale_factor)
vis.add_datasample(name, img, data_sample)
for k, v in result.items():
if isinstance(v, torch.Tensor):
result[k] = v.tolist()
* update analyze_results * lint * add --rescale-factor and fix filename logic * lint
Motivation
Update analyze_results.py for mmcls v1.0.
Results
Checklist
Before PR:
After PR: