MCPcopy Create free account
hub / github.com/Pixel-Talk/EHM-Tracker / PixieEncoder

Class PixieEncoder

src/modules/pixie/pixie_encoder.py:35–641  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33
34
35class PixieEncoder(nn.Module):
36 def __init__(self, config=None, ckpt_fp=''):
37 super().__init__()
38 if config is None:
39 self.cfg = cfg
40 else:
41 self.cfg = config
42
43 if os.path.exists(ckpt_fp):
44 self.cfg.pretrained_modelpath = ckpt_fp
45
46 # parameters setting
47 self.param_list_dict = {}
48 for lst in self.cfg.params.keys():
49 param_list = cfg.params.get(lst)
50 self.param_list_dict[lst] = {
51 i: cfg.model.get('n_'+i) for i in param_list}
52
53 # Build the models
54 self._create_model()
55 # Set up the cropping modules used to generate face/hand crops from the body predictions
56 self._setup_cropper()
57
58 def _setup_cropper(self):
59 self.Cropper = {}
60 for crop_part in ['head', 'hand']:
61 data_cfg = self.cfg.dataset[crop_part]
62 scale_size = (data_cfg.scale_min + data_cfg.scale_max)*0.5
63 self.Cropper[crop_part] = tensor_cropper.Cropper(
64 crop_size=data_cfg.image_size,
65 scale=[scale_size, scale_size],
66 trans_scale=0)
67
68 def _create_model(self):
69 self.model_dict = {}
70 # Build all image encoders
71 # Hand encoder only works for right hand, for left hand, flip inputs and flip the results back
72 self.Encoder = {}
73 for key in self.cfg.network.encoder.keys():
74 if self.cfg.network.encoder.get(key).type == 'resnet50':
75 self.Encoder[key] = ResnetEncoder()
76 elif self.cfg.network.encoder.get(key).type == 'hrnet':
77 self.Encoder[key] = HRNEncoder()
78 self.model_dict[f'Encoder_{key}'] = self.Encoder[key].state_dict()
79
80 # Build the parameter regressors
81 self.Regressor = {}
82 for key in self.cfg.network.regressor.keys():
83 n_output = sum(self.param_list_dict[f'{key}_list'].values())
84 channels = [2048] + \
85 self.cfg.network.regressor.get(key).channels + [n_output]
86 if self.cfg.network.regressor.get(key).type == 'mlp':
87 self.Regressor[key] = MLP(channels=channels)
88 self.model_dict[f'Regressor_{key}'] = self.Regressor[key].state_dict(
89 )
90
91 # Build the extractors
92 # to extract separate head/left hand/right hand feature from body feature

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected