def test_create_flock_params(): """Read from the params class and convert to list of params class instances""" params = MultipleLayersParams() params.seq_length = [1, 2, 3] params.n_cluster_centers = [1, 2, 3] params.cluster_boost_threshold = 123 params.num_conv_layers = 3 params_list = params.convert_to_expert_params() assert len(params_list) == 3 conv_classes = params.read_list_of_params('conv_classes') assert len(conv_classes) == 3 conv_classes += [params.read_param('conv_classes', 0)] assert len(conv_classes) == 4 conv_classes += params.read_list_of_params('conv_classes') assert len(conv_classes) == 7 num_cc = params.read_list_of_params('n_cluster_centers') assert len(num_cc) == 3 n_cc = params.read_param('n_cluster_centers', 1) assert n_cc == 2 cbt = params.read_list_of_params('cluster_boost_threshold') assert isinstance(cbt, list) assert len(cbt) == 3 top_params = MultipleLayersParams() cbt = top_params.read_list_of_params('cluster_boost_threshold') assert isinstance(cbt, list) assert len(cbt) == 1
def __init__( self, top_layer_params: Optional[ MultipleLayersParams] = MultipleLayersParams(), conv_layers_params: MultipleLayersParams = MultipleLayersParams(), model_seed: int = 321, # DATASET image_size=SeDatasetSize.SIZE_24, baseline_seed: int = 123, class_filter: List[int] = None, random_order: bool = False, noise_amp: float = 0.0): """ Constructor of the TA topology which should solve the Task0. Args: model_seed: seed of the model image_size: size of the dataset image class_filter: filters the classes in the dataset baseline_seed: seed for the baseline nodes """ super().__init__('cuda') layer_sizes = conv_layers_params.read_list_of_params( 'n_cluster_centers') if top_layer_params is not None: layer_sizes += top_layer_params.read_list_of_params( 'n_cluster_centers') self.se_group = SeNodeGroup(baseline_seed=baseline_seed, layer_sizes=layer_sizes, class_filter=class_filter, image_size=image_size, random_order=random_order, noise_amp=noise_amp) self.add_node(self.se_group) if top_layer_params is None: self.model = NCMGroup(conv_layers_params=conv_layers_params, image_size=(image_size.value, image_size.value, 3), model_seed=model_seed) else: self.model = Nc1r1GroupWithAdapter( conv_layers_params=conv_layers_params, top_layer_params=top_layer_params, num_labels=20, image_size=(image_size.value, image_size.value, 3), model_seed=model_seed) self.add_node(self.model) Connector.connect(self.se_group.outputs.image, self.model.inputs.image) if isinstance(self.model, Nc1r1GroupWithAdapter): Connector.connect(self.se_group.outputs.labels, self.model.inputs.label)
def __init__(self, inputs: TNCMGroupInputs, outputs: TOutputs, conv_layers_params: MultipleLayersParams, model_seed: Optional[int] = 321, image_size: Tuple[int, int, int] = (24, 24, 3), name: str = "TA Model"): """ Create the multilayer topology of configuration: N conv layers Args: conv_layers_params: parameters for each layer (or default ones) model_seed: seed of the topology image_size: small resolution by default """ super().__init__(name=name, inputs=inputs, outputs=outputs) self._num_layers = conv_layers_params.num_conv_layers + 1 self._input_dims = image_size # parse conv layers to ExpertParams self._conv_params_list = conv_layers_params.convert_to_expert_params() # other parameters for the convolution conv_classes = conv_layers_params.read_list_of_params('conv_classes') rf_sizes = conv_layers_params.read_list_of_params('rf_size') rf_strides = conv_layers_params.read_list_of_params('rf_stride') num_flocks = conv_layers_params.read_list_of_params('n_flocks') self._conv_params = self.create_conv_layer_params(param_list=self._conv_params_list, rf_sizes=rf_sizes, rf_strides=rf_strides, num_flocks=num_flocks, conv_classes=conv_classes, model_seed=model_seed) self.conv_layers, self.output_projection_sizes = create_connected_conv_layers(self._conv_params, self._input_dims) for layer in self.conv_layers: self.add_node(layer) # image -> Conv0 Connector.connect( self.inputs.image.output, self.conv_layers[0].inputs.data)