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

Meet RuntimeError about scalar type when train faster-rcnn on custom dataset #458

Closed
DarkstartsUp opened this issue Apr 1, 2019 · 2 comments

Comments

@DarkstartsUp
Copy link

Error report:
2019-04-01 16:58:20,122 - INFO - Start running, host: hostname@hostname1, work_dir: /home/hostname/mmdetection/work_dirs/my_faster_rcnn_r50_fpn_1x
2019-04-01 16:58:20,122 - INFO - workflow: [('train', 1)], max: 30 epochs
Traceback (most recent call last):
File "./tools/train.py", line 90, in
main()
File "./tools/train.py", line 86, in main
logger=logger)
File "/home/hostname/mmdetection/mmdet/apis/train.py", line 57, in train_detector
_dist_train(model, dataset, cfg, validate=validate)
File "/home/hostname/mmdetection/mmdet/apis/train.py", line 96, in _dist_train
runner.run(data_loaders, cfg.workflow, cfg.total_epochs)
File "/home/hostname/anaconda3/envs/dl/lib/python3.6/site-packages/mmcv/runner/runner.py", line 355, in run
epoch_runner(data_loaders[i], **kwargs)
File "/home/hostname/anaconda3/envs/dl/lib/python3.6/site-packages/mmcv/runner/runner.py", line 261, in train
self.model, data_batch, train_mode=True, **kwargs)
File "/home/hostname/mmdetection/mmdet/apis/train.py", line 37, in batch_processor
losses = model(**data)
File "/home/hostname/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 489, in call
result = self.forward(*input, **kwargs)
File "/home/hostname/anaconda3/envs/dl/lib/python3.6/site-packages/mmcv/parallel/distributed.py", line 50, in forward
return self.module(*inputs[0], **kwargs[0])
File "/home/hostname/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 489, in call
result = self.forward(*input, **kwargs)
File "/home/hostname/mmdetection/mmdet/models/detectors/base.py", line 80, in forward
return self.forward_train(img, img_meta, **kwargs)
File "/home/hostname/mmdetection/mmdet/models/detectors/two_stage.py", line 98, in forward_train
*rpn_loss_inputs, gt_bboxes_ignore=gt_bboxes_ignore)
File "/home/hostname/mmdetection/mmdet/models/anchor_heads/rpn_head.py", line 51, in loss
gt_bboxes_ignore=gt_bboxes_ignore)
File "/home/hostname/mmdetection/mmdet/models/anchor_heads/anchor_head.py", line 198, in loss
sampling=sampling)
File "/home/hostname/mmdetection/mmdet/core/anchor/anchor_target.py", line 63, in anchor_target
unmap_outputs=unmap_outputs)
File "/home/hostname/mmdetection/mmdet/core/utils/misc.py", line 24, in multi_apply
return tuple(map(list, zip(*map_results)))
File "/home/hostname/mmdetection/mmdet/core/anchor/anchor_target.py", line 116, in anchor_target_single
anchors, gt_bboxes, gt_bboxes_ignore, None, cfg)
File "/home/hostname/mmdetection/mmdet/core/bbox/assign_sampling.py", line 32, in assign_and_sample
gt_labels)
File "/home/hostname/mmdetection/mmdet/core/bbox/assigners/max_iou_assigner.py", line 76, in assign
overlaps = bbox_overlaps(gt_bboxes, bboxes)
File "/home/hostname/mmdetection/mmdet/core/bbox/geometry.py", line 48, in bbox_overlaps
lt = torch.max(bboxes1[:, None, :2], bboxes2[:, :2]) # [rows, cols, 2]
RuntimeError: Expected object of scalar type Double but got scalar type Float for argument #2 'other'

Part of my custom dataset:
[{'filename': 'IMG_12_1.jpg', 'width': 793, 'height': 595, 'ann': {'bboxes': array([[432, 180, 492, 280],
[450, 108, 550, 168],
[540, 108, 640, 168],
[450, 162, 550, 222],
[486, 90, 546, 190],
[486, 180, 546, 280],
[270, 162, 370, 222],
[360, 216, 460, 276],
[450, 216, 550, 276],
[270, 90, 330, 190],
[594, 90, 654, 190],
[450, 432, 550, 492],
[378, 180, 438, 280],
[432, 450, 492, 550],
[180, 162, 280, 222],
[360, 162, 460, 222],
[630, 216, 730, 276],
[450, 324, 550, 384],
[540, 324, 640, 384],
[216, 90, 276, 190],
[324, 90, 384, 190],
[540, 90, 600, 190],
[702, 180, 762, 280],
[180, 108, 280, 168],
[270, 108, 370, 168]], dtype=int32), 'labels': array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0], dtype=int32), 'bboxes_ignore': array([], dtype=int32), 'labels_ignore': array([], dtype=int32)}}, {'filename': 'IMG_9_1.jpg', 'width': 664, 'height': 373, 'ann': {'bboxes': array([[360, 162, 460, 222],
[ 54, 180, 114, 280],
[378, 180, 438, 280],
[486, 180, 546, 280],
[ 0, 162, 100, 222],
[108, 180, 168, 280],
[450, 162, 550, 222],
[ 90, 162, 190, 222],
[450, 216, 550, 276],
[432, 180, 492, 280],
[324, 180, 384, 280],
[ 90, 216, 190, 276],
[540, 180, 600, 280],
[540, 162, 640, 222],
[ 0, 216, 100, 276],
[180, 216, 280, 276],
[540, 216, 640, 276],
[162, 180, 222, 280],
[ 0, 180, 60, 280],
[594, 180, 654, 280],
[360, 216, 460, 276],
[216, 180, 276, 280],
[270, 162, 370, 222],
[270, 216, 370, 276],
[270, 270, 370, 330]], dtype=int32), 'labels': array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0], dtype=int32), 'bboxes_ignore': array([], dtype=int32), 'labels_ignore': array([], dtype=int32)}}]

Part of config file:

dataset settings

dataset_type = 'CustomDataset'
data_root = 'data/CrowdImages/'
img_norm_cfg = dict(
mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)
data = dict(
imgs_per_gpu=2,
workers_per_gpu=2,
train=dict(
type=dataset_type,
ann_file=data_root + 'annotations/annos_train.pkl',
img_prefix=data_root + 'trainImgs/',
img_scale=(1000, 600),
img_norm_cfg=img_norm_cfg,
size_divisor=32,
flip_ratio=0.5,
with_mask=False,
with_crowd=False,
with_label=True),
val=dict(
type=dataset_type,
ann_file=data_root + 'annotations/annos_val.pkl',
img_prefix=data_root + 'valImgs/',
img_scale=(1000, 600),
img_norm_cfg=img_norm_cfg,
size_divisor=32,
flip_ratio=0,
with_mask=False,
with_crowd=False,
with_label=True),
test=dict(
type=dataset_type,
ann_file=data_root + 'annotations/annos_test.pkl',
img_prefix=data_root + 'testImgs/',
img_scale=(1000, 600),
img_norm_cfg=img_norm_cfg,
size_divisor=32,
flip_ratio=0,
with_mask=False,
with_label=True,
test_mode=True))

optimizer

optimizer = dict(type='SGD', lr=0.0025, momentum=0.9, weight_decay=0.0001)
optimizer_config = dict(grad_clip=dict(max_norm=35, norm_type=2))

learning policy

'''
lr_config = dict(
policy='step',
warmup='linear',
warmup_iters=500,
warmup_ratio=1.0 / 3,
step=[8, 11])
'''
lr_config = dict(policy='step', step=[3])
checkpoint_config = dict(interval=1)

yapf:disable

log_config = dict(
interval=50,
hooks=[
dict(type='TextLoggerHook'),
# dict(type='TensorboardLoggerHook')
])

yapf:enable

runtime settings

total_epochs = 30
dist_params = dict(backend='nccl')
log_level = 'INFO'
work_dir = './work_dirs/my_faster_rcnn_r50_fpn_1x'
load_from = None
resume_from = None
workflow = [('train', 1)]

Could anyone help? THX!

@DarkstartsUp
Copy link
Author

This problem has been solved:
In customed dataset, the datatype of anno should be:
'bboxes': np.array(dtype=np.float32),
'labels': np.array(dtype=np.int64),
'bboxes_ignore': np.array(dtype=np.float32),
'labels_ignore': np.array(dtype=np.int64)

@mejihero
Copy link

Hi, I have the same issue when training the model. Can I ask how to sort it out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants