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

我在测试culane时,KeyError: 'seg' #3

Closed
ChenSi521 opened this issue Mar 29, 2023 · 4 comments
Closed

我在测试culane时,KeyError: 'seg' #3

ChenSi521 opened this issue Mar 29, 2023 · 4 comments

Comments

@ChenSi521
Copy link

python tools/detect.py configs/condlane/resnet50_culane.py --img /data/our_testset --load_from /PPlanedet/models/resnet50_culane/model.pd --savedir ./vis
出现下面的错误:
image
dict_keys(['seeds', 'hm'])是我打印出来的 out[1].keys(),没有'seg'这个键值。

请问怎么破?

@zkyseu
Copy link
Owner

zkyseu commented Mar 29, 2023

@ChenSi521 您好这个应该是程序的一个bug,我已经修复了,将detect.py中的下面函数进行修改,非常感谢哈。

def run(self, data,image_dir):
    img_path = copy(data)
    data = self.preprocess(data)
    out = self.inference(data)
#        data['lanes'] = out[0][0]
#        data['lanes'],seg = self.inference(data)[0],self.inference(data)[1]
    if self.cfg.show or self.cfg.savedir:
        if not self.cfg.seg:
            data['lanes'] = self.net.get_lanes(out[1])[0]
            self.show(data)
        else:
            #将seg移到这个地方即可
            seg = out[1]['seg']
            self.show_seg(seg,data,image_dir,img_path,)
    return data

@zkyseu
Copy link
Owner

zkyseu commented Mar 30, 2023

@ChenSi521 我收到您的问题邮件了,这个和skip load没有关系,这部分权重就是不导入的,您需要在您的配置文件中加上seg=False ,如果不加的话会默认模型是分割模型而不是关键点模型。以下是我测试成功的配置文件

model = dict(
    name='Detector',
)

backbone = dict(
    name='ResNetWrapper',
    resnet='resnet50',
    pretrained=True,
    replace_stride_with_dilation=[False, False, False],
    out_conv=False,
    in_channels=[64, 128, 256, 512]
)

sample_y = range(590, 270, -8)

batch_size = 16
aggregator = dict(
    name='TransConvEncoderModule',
    in_dim=2048,
    attn_in_dims=[2048, 256],
    attn_out_dims=[256, 256],
    strides=[1, 1],
    ratios=[4, 4],
    pos_shape=(batch_size, 10, 25),
)

neck=dict(
    name='FPN',
    in_channels=[256, 512, 1024, 256],
    out_channels=64,
    num_outs=4,
    #trans_idx=-1,
)

loss_weights=dict(
        hm_weight=1,
        kps_weight=0.4,
        row_weight=1.,
        range_weight=1.,
    )

num_lane_classes=1
heads=dict(
    name='CondLaneHead',
    heads=dict(hm=num_lane_classes),
    in_channels=(64, ),
    num_classes=num_lane_classes,
    head_channels=64,
    head_layers=1,
    disable_coords=False,
    branch_in_channels=64,
    branch_channels=64,
    branch_out_channels=64,
    reg_branch_channels=64,
    branch_num_conv=1,
    hm_idx=2,
    mask_idx=0,
    compute_locations_pre=True,
    location_configs=dict(size=(batch_size, 1, 80, 200), device='cuda:0'),
    crit_loss = dict(name = 'Condlane_focalLoss'),
    crit_kp_loss = dict(name = 'RegL1KpLoss'),
    crit_ce_loss = dict(name = 'CrossEntropyLoss_nn')
    
)

epochs = 16
total_iter = (88880 // batch_size) * epochs

lr_scheduler = dict(
    name = 'MultiStepDecay',
    learning_rate = 3e-4,
    milestones=[8,14], 
    gamma=0.1
)

optimizer = dict(name='AdamW',  
                 beta1 =  0.9,
                 beta2 = 0.999, 
                 epsilon=1e-8)

seg_loss_weight = 1.0
eval_ep = 1
save_ep = 1 

img_norm = dict(
    mean=[0.295, 0.300, 0.304],
    std=[0.198, 0.211, 0.213]
)

img_height = 320 
img_width = 800
cut_height = 0 
ori_img_h = 590
ori_img_w = 1640

mask_down_scale = 4
hm_down_scale = 16
num_lane_classes = 1
line_width = 3
radius = 6
nms_thr = 4
img_scale = (800, 320)
crop_bbox = [0, 270, 1640, 590]
mask_size = (1, 80, 200)

train_process = [
    dict(name='Alaug',
    transforms=[dict(name='Compose', params=dict(bboxes=False, keypoints=True, masks=False)),
    dict(
        name='Crop',
        x_min=crop_bbox[0],
        x_max=crop_bbox[2],
        y_min=crop_bbox[1],
        y_max=crop_bbox[3],
        p=1),
    dict(name='Resize', height=img_scale[1], width=img_scale[0], p=1),
    dict(
        name='OneOf',
        transforms=[
            dict(
                name='RGBShift',
                r_shift_limit=10,
                g_shift_limit=10,
                b_shift_limit=10,
                p=1.0),
            dict(
                name='HueSaturationValue',
                hue_shift_limit=(-10, 10),
                sat_shift_limit=(-15, 15),
                val_shift_limit=(-10, 10),
                p=1.0),
        ],
        p=0.7),
    dict(name='JpegCompression', quality_lower=85, quality_upper=95, p=0.2),
    dict(
        name='OneOf',
        transforms=[
            dict(name='Blur', blur_limit=3, p=1.0),
            dict(name='MedianBlur', blur_limit=3, p=1.0)
        ],
        p=0.2),
    dict(name='RandomBrightness', limit=0.2, p=0.6),
    dict(
        name='ShiftScaleRotate',
        shift_limit=0.1,
        scale_limit=(-0.2, 0.2),
        rotate_limit=10,
        border_mode=0,
        p=0.6),
    dict(
        name='RandomResizedCrop',
        height=img_scale[1],
        width=img_scale[0],
        scale=(0.8, 1.2),
        ratio=(1.7, 2.7),
        p=0.6),
    dict(name='Resize', height=img_scale[1], width=img_scale[0], p=1),]
    ),
    dict(name='CollectLane',
        down_scale=mask_down_scale,
        hm_down_scale=hm_down_scale,
        max_mask_sample=5,
        line_width=line_width,
        radius=radius,
        keys=['img', 'gt_hm'],
        meta_keys=[
            'gt_masks', 'mask_shape', 'hm_shape',
            'down_scale', 'hm_down_scale', 'gt_points'
        ]
    ),
    #dict(name='Resize', size=(img_width, img_height)),
    dict(name='Normalize', img_norm=img_norm),
    dict(name='ToTensor', keys=['img', 'gt_hm'], collect_keys=['img_metas']),
]


val_process = [
    dict(name='Alaug',
        transforms=[dict(name='Compose', params=dict(bboxes=False, keypoints=True, masks=False)),
            dict(name='Crop',
            x_min=crop_bbox[0],
            x_max=crop_bbox[2],
            y_min=crop_bbox[1],
            y_max=crop_bbox[3],
            p=1),
        dict(name='Resize', height=img_scale[1], width=img_scale[0], p=1)]
    ),
    #dict(name='Resize', size=(img_width, img_height)),
    dict(name='Normalize', img_norm=img_norm),
    dict(name='ToTensor', keys=['img']),
]

dataset_path = '/root/autodl-tmp/culane'
dataset = dict(
    train=dict(
        name='CULane',
        data_root=dataset_path,
        split='train',
        processes=train_process,
    ),
    val=dict(
        name='CULane',
        data_root=dataset_path,
        split='test',
        processes=val_process,
    ),
    test=dict(
        name='CULane',
        data_root=dataset_path,
        split='test',
        processes=val_process,
    )
)

log_config = dict(
    name = 'LogHook',
    interval = 50
    )

custom_config = [dict(
    name = 'EvaluateHook'
    )]

device = 'gpu'
seed =  0
save_inference_dir = './inference'
output_dir = './output_dir'
best_dir = './output_dir/best_dir'
pred_save_dir = './pred_save'
num_workers = 4
view = False
ignore_label = 255
seg = False #这里需要加上这行代码才可以正常运行

@ChenSi521
Copy link
Author

后来我也跑通了,感谢感谢!

@zkyseu
Copy link
Owner

zkyseu commented Apr 1, 2023

我先关闭这个issue了哈,如果您有任何问题欢迎重新打开issue

@zkyseu zkyseu closed this as completed Apr 1, 2023
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