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.

Why mAp is 0, even after so many iterations ?

See original GitHub issue

Please help I am new to this, mAp is 0 even after this much iterations 92600 !! ,

[342]   92600 || B: 0.130 | C: 0.274 | M: 0.520 | S: 0.041 | T: 0.965 || ETA: 27 days, 23:08:49 || timer: 0.182
Computing validation mAP (this may take a while)...
Calculating mAP...

       |  all  |  .50  |  .55  |  .60  |  .65  |  .70  |  .75  |  .80  |  .85  |  .90  |  .95  |
-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+
   box |  0.00 |  0.00 |  0.00 |  0.00 |  0.00 |  0.00 |  0.00 |  0.00 |  0.00 |  0.00 |  0.00 |
  mask |  0.00 |  0.00 |  0.00 |  0.00 |  0.00 |  0.00 |  0.00 |  0.00 |  0.00 |  0.00 |  0.00 |
-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+

settings

– batch_size=1 If i set batch_size=5, getting an error “GPU out of memory”

My dataset:

Training: 480 images (4302 * 2140) Validate: 6 images (4302 * 2140) Clases: 5

config.py

# ----------------------- DATASETS ----------------------- #
CIRCUIT_CLASSES = ("circuitA1", "circuitA2", "circuitB1", "circuitB2", "circuitC1")

my_custom_dataset = dataset_base.copy({
    'name': 'Circuit Dataset',

    'train_images': './data/coco/images/train',
    'train_info':   './data/coco/annotations/train/instances_train.json',

    'valid_images': './data/coco/images/val',
    'valid_info':   './data/coco/annotations/val/instances_val.json',

    # Whether or not to load GT. If this is False, eval.py quantitative evaluation won't work.
    'has_gt': False,

    'class_names': CIRCUIT_CLASSES,

    # COCO class ids aren't sequential, so this is a bandage fix. If your ids aren't sequential,
    # provide a map from category_id -> index in class_names + 1 (the +1 is there because it's 1-indexed).
    # If not specified, this just assumes category ids start at 1 and increase sequentially.
    'label_map': { 1: 1, 2: 2, 3: 3, 4: 4, 5: 5 }
})
# ----------------------- YOLACT v1.0 CONFIGS ----------------------- #
yolact_base_config = coco_base_config.copy({
    'name': 'yolact_base',

    # Dataset stuff
    # 'dataset': coco2017_dataset,
    'dataset': my_custom_dataset,
    'num_classes': len(my_custom_dataset.class_names) + 1,

    # Image Size
    'max_size': 550,
    
    # Training params
    'lr_steps': (280000, 600000, 700000, 750000),
    'max_iter': 800000,
    
    # Backbone Settings
    'backbone': resnet101_backbone.copy({
        'selected_layers': list(range(1, 4)),
        'use_pixel_scales': True,
        'preapply_sqrt': False,
        'use_square_anchors': True, # This is for backward compatability with a bug

        'pred_aspect_ratios': [ [[1, 1/2, 2]] ]*5,
        'pred_scales': [[24], [48], [96], [192], [384]],
    }),

    # FPN Settings
    'fpn': fpn_base.copy({
        'use_conv_downsample': True,
        'num_downsample': 2,
    }),

    # Mask Settings
    'mask_type': mask_type.lincomb,
    'mask_alpha': 6.125,
    'mask_proto_src': 0,
    'mask_proto_net': [(256, 3, {'padding': 1})] * 3 + [(None, -2, {}), (256, 3, {'padding': 1})] + [(32, 1, {})],
    'mask_proto_normalize_emulate_roi_pooling': True,

    # Other stuff
    'share_prediction_module': True,
    'extra_head_net': [(256, 3, {'padding': 1})],

    'positive_iou_threshold': 0.5,
    'negative_iou_threshold': 0.4,

    'crowd_iou_threshold': 0.7,

    'use_semantic_segmentation_loss': True,
})

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

1reaction
monforte-dtcommented, Aug 26, 2021

I was having the same issue with a smaller dataset, I don’t think the model can learn that easily once gradient pathways to the backbone are too deep.

My workaround to it was to download pre-trained coco weights and use them to initialize the model. Modify this method in yolact.Yolact:

def load_weights(self, path):
        """ Loads weights from a compressed save file. """
        keys_vin = torch.load(path)
        current_model = self.state_dict()
        
        state_dict={k:v if v.size()==current_model[k].size()  else  current_model[k] for k,v in zip(current_model.keys(), keys_vin.values())}

        # For backward compatability, remove these (the new variable is called layers)
        for key in list(state_dict.keys()):
            if key.startswith('backbone.layer') and not key.startswith('backbone.layers'):
                del state_dict[key]
        
            # Also for backward compatibility with v1.0 weights, do this check
            if key.startswith('fpn.downsample_layers.'):
                if cfg.fpn is not None and int(key.split('.')[2]) >= cfg.fpn.num_downsample:
                    del state_dict[key]
        self.load_state_dict(state_dict)

Then just add this to line 214 of train.py

yolact_net.load_weights("./weights/yolact_resnet50_54_800000.pth") # Change model name if using different backbone 
0reactions
Camilochiangcommented, Jun 25, 2022

The definition is calc_map in eval.py

def calc_map(ap_data):
    print('Calculating mAP...')
    aps = [{'box': [], 'mask': []} for _ in iou_thresholds]

    for _class in range(len(cfg.dataset.class_names)):
        for iou_idx in range(len(iou_thresholds)):
            for iou_type in ('box', 'mask'):
                ap_obj = ap_data[iou_type][iou_idx][_class]

                if not ap_obj.is_empty():
                    aps[iou_idx][iou_type].append(ap_obj.get_ap())

    all_maps = {'box': OrderedDict(), 'mask': OrderedDict()}

    # Looking back at it, this code is really hard to read :/
    for iou_type in ('box', 'mask'):
        all_maps[iou_type]['all'] = 0 # Make this first in the ordereddict
        for i, threshold in enumerate(iou_thresholds):
            mAP = sum(aps[i][iou_type]) / len(aps[i][iou_type]) * 100 if len(aps[i][iou_type]) > 0 else 0
            all_maps[iou_type][int(threshold*100)] = mAP
        all_maps[iou_type]['all'] = (sum(all_maps[iou_type].values()) / (len(all_maps[iou_type].values())-1))
    
    print_maps(all_maps)
    
    # Put in a prettier format so we can serialize it to json during training
    all_maps = {k: {j: round(u, 2) for j, u in v.items()} for k, v in all_maps.items()}
    return all_maps

Did you also have this problem during training?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why are iterations over maps random? - Stack Overflow
When iterating over a map with a range loop, the iteration order is not specified and is not guaranteed to be the same...
Read more >
map vs. for loop - Medium
True iteration — you know that your code is going to run on each element of the array in the right order. Immutability...
Read more >
Searching with iterated maps - PNAS
When n is <10, the algorithm finds a coloring in few iterations, with the displacement Δ making systematic progress toward zero. For the...
Read more >
Python's map(): Processing Iterables Without a Loop
This first argument to map() is a transformation function. In other words, it's the function that transforms each original item into a new...
Read more >
Array.prototype.map() - JavaScript - MDN Web Docs
The map() method creates a new array populated with the results of calling a provided function on every element in the calling array....
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