Safemotion Lib
Loading...
Searching...
No Matches
Classes | Functions | Variables
fastreid.modeling.backbones.resnest Namespace Reference

Classes

class  Bottleneck
 
class  ResNest
 

Functions

 short_hash (name)
 
 build_resnest_backbone (cfg)
 

Variables

 logger = logging.getLogger(__name__)
 
str _url_format = 'https://s3.us-west-1.wasabisys.com/resnest/torch/{}-{}.pth'
 
dict _model_sha256
 
dict model_urls
 

Detailed Description

ResNeSt models

Function Documentation

◆ build_resnest_backbone()

fastreid.modeling.backbones.resnest.build_resnest_backbone ( cfg)
Create a ResNest instance from config.
Returns:
    ResNet: a :class:`ResNet` instance.

Definition at line 359 of file resnest.py.

359def build_resnest_backbone(cfg):
360 """
361 Create a ResNest instance from config.
362 Returns:
363 ResNet: a :class:`ResNet` instance.
364 """
365
366 # fmt: off
367 pretrain = cfg.MODEL.BACKBONE.PRETRAIN
368 pretrain_path = cfg.MODEL.BACKBONE.PRETRAIN_PATH
369 last_stride = cfg.MODEL.BACKBONE.LAST_STRIDE
370 bn_norm = cfg.MODEL.BACKBONE.NORM
371 with_ibn = cfg.MODEL.BACKBONE.WITH_IBN
372 with_se = cfg.MODEL.BACKBONE.WITH_SE
373 with_nl = cfg.MODEL.BACKBONE.WITH_NL
374 depth = cfg.MODEL.BACKBONE.DEPTH
375 # fmt: on
376
377 num_blocks_per_stage = {
378 "50x": [3, 4, 6, 3],
379 "101x": [3, 4, 23, 3],
380 "200x": [3, 24, 36, 3],
381 "269x": [3, 30, 48, 8],
382 }[depth]
383
384 nl_layers_per_stage = {
385 "50x": [0, 2, 3, 0],
386 "101x": [0, 2, 3, 0],
387 "200x": [0, 2, 3, 0],
388 "269x": [0, 2, 3, 0],
389 }[depth]
390
391 stem_width = {
392 "50x": 32,
393 "101x": 64,
394 "200x": 64,
395 "269x": 64,
396 }[depth]
397
398 model = ResNest(last_stride, bn_norm, with_ibn, with_nl, Bottleneck, num_blocks_per_stage,
399 nl_layers_per_stage, radix=2, groups=1, bottleneck_width=64,
400 deep_stem=True, stem_width=stem_width, avg_down=True,
401 avd=True, avd_first=False)
402 if pretrain:
403 # Load pretrain path if specifically
404 if pretrain_path:
405 try:
406 state_dict = torch.load(pretrain_path, map_location=torch.device('cpu'))
407 logger.info(f"Loading pretrained model from {pretrain_path}")
408 except FileNotFoundError as e:
409 logger.info(f'{pretrain_path} is not found! Please check this path.')
410 raise e
411 except KeyError as e:
412 logger.info("State dict keys error! Please check the state dict.")
413 raise e
414 else:
415 state_dict = torch.hub.load_state_dict_from_url(
416 model_urls['resnest' + depth[:-1]], progress=True, check_hash=True, map_location=torch.device('cpu'))
417
418 incompatible = model.load_state_dict(state_dict, strict=False)
419 if incompatible.missing_keys:
420 logger.info(
421 get_missing_parameters_message(incompatible.missing_keys)
422 )
423 if incompatible.unexpected_keys:
424 logger.info(
425 get_unexpected_parameters_message(incompatible.unexpected_keys)
426 )
427 return model

◆ short_hash()

fastreid.modeling.backbones.resnest.short_hash ( name)

Definition at line 32 of file resnest.py.

32def short_hash(name):
33 if name not in _model_sha256:
34 raise ValueError('Pretrained model for {name} is not available.'.format(name=name))
35 return _model_sha256[name][:8]
36
37

Variable Documentation

◆ _model_sha256

dict fastreid.modeling.backbones.resnest._model_sha256
protected
Initial value:
1= {name: checksum for checksum, name in [
2 ('528c19ca', 'resnest50'),
3 ('22405ba7', 'resnest101'),
4 ('75117900', 'resnest200'),
5 ('0cc87c48', 'resnest269'),
6]}

Definition at line 24 of file resnest.py.

◆ _url_format

str fastreid.modeling.backbones.resnest._url_format = 'https://s3.us-west-1.wasabisys.com/resnest/torch/{}-{}.pth'
protected

Definition at line 22 of file resnest.py.

◆ logger

fastreid.modeling.backbones.resnest.logger = logging.getLogger(__name__)

Definition at line 21 of file resnest.py.

◆ model_urls

dict fastreid.modeling.backbones.resnest.model_urls
Initial value:
1= {name: _url_format.format(name, short_hash(name)) for
2 name in _model_sha256.keys()
3 }

Definition at line 38 of file resnest.py.