def build(self, inputs): """Use config dictionary to generate all important attributes for head. Args: inputs: dictionary of the shape of input args as a dictionary of lists. """ keys = [int(key) for key in inputs.keys()] self._min_level = min(keys) self._max_level = max(keys) self._min_depth = inputs[str(self._min_level)][-1] self._depths = self.get_raw_depths(self._min_depth, inputs) # directly connect to an input path and process it self.preprocessors = dict() # resample an input and merge it with the output of another path # inorder to aggregate backbone outputs self.resamples = dict() # set of convoltion layers and upsample layers that are used to # prepare the FPN processors for output for level, depth in zip( reversed(range(self._min_level, self._max_level + 1)), self._depths): if level == self._min_level: self.resamples[str(level)] = nn_blocks.PathAggregationBlock( filters=depth // 2, inverted=True, upsample=True, drop_final=self._csp_stack == 0, upsample_size=2, **self._base_config) self.preprocessors[str(level)] = _IdentityRoute() elif level != self._max_level: self.resamples[str(level)] = nn_blocks.PathAggregationBlock( filters=depth // 2, inverted=True, upsample=True, drop_final=False, upsample_size=2, **self._base_config) self.preprocessors[str(level)] = nn_blocks.DarkRouteProcess( filters=depth, repetitions=self._fpn_depth - int(level == self._min_level), block_invert=True, insert_spp=False, csp_stack=self._csp_stack, **self._base_config) else: self.preprocessors[str(level)] = nn_blocks.DarkRouteProcess( filters=depth, repetitions=self._max_fpn_depth + 1 * int(self._csp_stack == 0), insert_spp=True, block_invert=False, csp_stack=min(self._csp_stack, self._max_fpn_depth), **self._base_config)
def build(self, inputs): """Use config dictionary to generate all important attributes for head. Args: inputs: dictionary of the shape of input args as a dictionary of lists. """ # define the key order keys = [int(key) for key in inputs.keys()] self._min_level = min(keys) self._max_level = max(keys) self._min_depth = inputs[str(self._min_level)][-1] self._depths = self.get_raw_depths(self._min_depth, inputs) # directly connect to an input path and process it self.preprocessors = dict() # resample an input and merge it with the output of another path # inorder to aggregate backbone outputs self.resamples = dict() # FPN will reverse the key process order for the backbone, so we need # adjust the order that objects are created and processed to adjust for # this. not using an FPN will directly connect the decoder to the backbone # therefore the object creation order needs to be done from the largest # to smallest level. if self._fpn_input: # process order {... 3, 4, 5} self._iterator = range(self._min_level, self._max_level + 1) self._check = lambda x: x < self._max_level self._key_shift = lambda x: x + 1 self._input = self._min_level downsample = True upsample = False else: # process order {5, 4, 3, ...} self._iterator = list( reversed(range(self._min_level, self._max_level + 1))) self._check = lambda x: x > self._min_level self._key_shift = lambda x: x - 1 self._input = self._max_level downsample = False upsample = True if self._csp_stack == 0: proc_filters = lambda x: x resample_filters = lambda x: x // 2 else: proc_filters = lambda x: x * 2 resample_filters = lambda x: x for level, depth in zip(self._iterator, self._depths): if level == self._input: self.preprocessors[str(level)] = nn_blocks.DarkRouteProcess( filters=proc_filters(depth), repetitions=self._max_level_process_len, insert_spp=self._embed_spp, block_invert=False, insert_sam=self._use_spatial_attention, csp_stack=self._csp_stack, **self._base_config) else: self.resamples[str(level)] = nn_blocks.PathAggregationBlock( filters=resample_filters(depth), upsample=upsample, downsample=downsample, inverted=False, drop_final=self._csp_stack == 0, **self._base_config) self.preprocessors[str(level)] = nn_blocks.DarkRouteProcess( filters=proc_filters(depth), repetitions=self._path_process_len, insert_spp=False, insert_sam=self._use_spatial_attention, csp_stack=self._csp_stack, **self._base_config)