How to use the mlblocks.import_object function in mlblocks

To help you get started, we’ve selected a few mlblocks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github HDI-Project / MLBlocks / mlblocks / parsers / keras.py View on Github external
def build_mlblock_model(self, fixed_hyperparameters, tunable_hyperparameters):
        # Load the class for this primitive block.
        full_module_class = self.metadata['class']
        assert (full_module_class == 'keras.models.Sequential')
        sequential_class = import_object(full_module_class)
        model = sequential_class()

        layers = self.metadata['layers']
        for layer_metadata in layers:
            layer_module_class = layer_metadata['class']
            layer_class = import_object(layer_module_class)
            layer_kwargs = {}
            for param in layer_metadata['parameters']:
                hp_name = layer_metadata['parameters'][param]
                if hp_name in tunable_hyperparameters:
                    layer_kwargs[param] = tunable_hyperparameters[hp_name].value
                else:
                    layer_kwargs[param] = fixed_hyperparameters[hp_name]

            layer = layer_class(**layer_kwargs)
            model.add(layer)
github HDI-Project / MLBlocks / mlblocks / parsers / keras.py View on Github external
def build_mlblock_model(self, fixed_hyperparameters, tunable_hyperparameters):
        # Load the class for this primitive block.
        full_module_class = self.metadata['class']
        assert (full_module_class == 'keras.models.Sequential')
        sequential_class = import_object(full_module_class)
        model = sequential_class()

        layers = self.metadata['layers']
        for layer_metadata in layers:
            layer_module_class = layer_metadata['class']
            layer_class = import_object(layer_module_class)
            layer_kwargs = {}
            for param in layer_metadata['parameters']:
                hp_name = layer_metadata['parameters'][param]
                if hp_name in tunable_hyperparameters:
                    layer_kwargs[param] = tunable_hyperparameters[hp_name].value
                else:
                    layer_kwargs[param] = fixed_hyperparameters[hp_name]

            layer = layer_class(**layer_kwargs)
            model.add(layer)

        optimizer = import_object(fixed_hyperparameters['optimizer'])()
        loss = import_object(fixed_hyperparameters['loss'])
        metrics = fixed_hyperparameters.get('metrics')
        model.compile(loss=loss, optimizer=optimizer, metrics=metrics)
github HDI-Project / MLBlocks / mlblocks / parsers / keras.py View on Github external
layers = self.metadata['layers']
        for layer_metadata in layers:
            layer_module_class = layer_metadata['class']
            layer_class = import_object(layer_module_class)
            layer_kwargs = {}
            for param in layer_metadata['parameters']:
                hp_name = layer_metadata['parameters'][param]
                if hp_name in tunable_hyperparameters:
                    layer_kwargs[param] = tunable_hyperparameters[hp_name].value
                else:
                    layer_kwargs[param] = fixed_hyperparameters[hp_name]

            layer = layer_class(**layer_kwargs)
            model.add(layer)

        optimizer = import_object(fixed_hyperparameters['optimizer'])()
        loss = import_object(fixed_hyperparameters['loss'])
        metrics = fixed_hyperparameters.get('metrics')
        model.compile(loss=loss, optimizer=optimizer, metrics=metrics)

        return model
github HDI-Project / MLBlocks / mlblocks / parsers / keras.py View on Github external
for layer_metadata in layers:
            layer_module_class = layer_metadata['class']
            layer_class = import_object(layer_module_class)
            layer_kwargs = {}
            for param in layer_metadata['parameters']:
                hp_name = layer_metadata['parameters'][param]
                if hp_name in tunable_hyperparameters:
                    layer_kwargs[param] = tunable_hyperparameters[hp_name].value
                else:
                    layer_kwargs[param] = fixed_hyperparameters[hp_name]

            layer = layer_class(**layer_kwargs)
            model.add(layer)

        optimizer = import_object(fixed_hyperparameters['optimizer'])()
        loss = import_object(fixed_hyperparameters['loss'])
        metrics = fixed_hyperparameters.get('metrics')
        model.compile(loss=loss, optimizer=optimizer, metrics=metrics)

        return model