question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Weird behaviour with instance segmentation

See original GitHub issue

Hello, I’m trying to use Detr for instance segmentation and trained following the guidelines:

  1. Train Box-Model 2. train with --masks without any coco_panoptic flags. The training curve for my segm mAP looks good, however, i noticed that the mask spans all instances for every valid prediction instead of the expected one mask per instance. Boxes work fine though.
out = model(img)
probas = out['pred_logits'].softmax(-1)[0, :, :-1]
keep = probas.max(-1).values > 0.5
ncols = 2
fig, axs = plt.subplots(ncols=ncols, nrows=math.ceil(keep.sum().item() / ncols), figsize=(18, 10))
for line in axs:
    for a in line:
        a.axis('off')
for i, mask in enumerate(out["pred_masks"][keep]):
    ax = axs[i // ncols, i % ncols]
    ax.imshow(mask, cmap="cividis")
    ax.axis('off')
  1. Target masks in each image are separated (e.g. 4 individual masks for each instance) in train/valid dataloader
  2. Not a (big) issue using the out-of-the-box panoptic model (although obviously poor results due to lack of fine tuning):
model, postprocessor = torch.hub.load('facebookresearch/detr', 'detr_resnet101_panoptic', pretrained=True, return_postprocessor=True, num_classes=250)

So what could be the cause of this problem?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:18 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
m-klasencommented, Jul 3, 2020

Training both bbox&segm straight on the pretrained panoptic weights with only class weights removed and nothing frozen was the solution. Got box mAP 0.65 & segm mAP 0.60 right now. Thank you for your help. image

0reactions
gfiamenicommented, Aug 23, 2021

Hi @m-klasen

(1) Use a pretrained object detection model from the Model ZOO to prepare a model_weights file that includes all pretrained weights except for the fully connected class layer (or just resume a model zoo one an deal with the class layer shape mismatch in the main.py file)

what do you exactly mean with point #1?

I delete class embed weights and biases before fine tuning.

checkpoint = torch.hub.load_state_dict_from_url(
            url='https://dl.fbaipublicfiles.com/detr/detr-r50-e632da11.pth',
            map_location='cpu',
            check_hash=True)

del checkpoint["model"]["class_embed.weight"]
del checkpoint["model"]["class_embed.bias"]

The output of this operation becomes the --resume input.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Thermal Imaging-Based Instance Segmentation for Automated ...
The report will investigate the usage of Instance Segmentation ... However, it quickly led to weird behaviour in the training, where.
Read more >
Is segmentation fault actual undefined behavior when we refer ...
Undefined behavior means that anything can happen with a standard conforming implementation. Really anything. (and your point 2 is UB).
Read more >
Multi-instance Object Segmentation with Occlusion Handling
We present a multi-instance object segmentation algo- rithm to tackle occlusions. As an object is split into two parts by an occluder, ...
Read more >
What Is Instance Segmentation? [2022 Guide & Tutorial]
Instance segmentation is the task of detecting and segmenting objects in images. See different approaches to instance segmentation, including Mask R-CNN.
Read more >
INSTR: Unknown Object Segmentation from Stereo Images
This is the IROS2021 presentation of our recent work "Unknown Object Segmentation from Stereo Images" by M. Durner, W. Boerdijk, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found