Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for importing architectures from keras code #12

Open
brollb opened this issue Oct 28, 2017 · 4 comments
Open

Support for importing architectures from keras code #12

brollb opened this issue Oct 28, 2017 · 4 comments
Assignees

Comments

@brollb
Copy link
Contributor

brollb commented Oct 28, 2017

We should be able to import architectures from definitions in keras code

@brollb
Copy link
Contributor Author

brollb commented Oct 28, 2017

This would be nice for the initial release as it would help with creating test cases quickly (rather than manually porting things) but isn't a hard requirement for the initial release

@brollb
Copy link
Contributor Author

brollb commented Mar 30, 2018

It may be better to import from the JSON representation of the model (output of model.to_json())

@umesh-timalsina
Copy link
Contributor

This would definitely be helpful for larger stacked models, where the use of GUI could be tiresome.
Let's look at what happens when you save a model as JSON keras. The code below shows it:

    def to_json(self, **kwargs):
        """Returns a JSON string containing the network configuration.
        To load a network from a JSON save file, use
        `keras.models.model_from_json(json_string, custom_objects={})`.
        # Arguments
            **kwargs: Additional keyword arguments
                to be passed to `json.dumps()`.
        # Returns
            A JSON string.
        """
        def get_json_type(obj):
            # If obj is any numpy type
            if type(obj).__module__ == np.__name__:
                if isinstance(obj, np.ndarray):
                    return obj.tolist()
                else:
                    return obj.item()

            # If obj is a python 'type'
            if type(obj).__name__ == type.__name__:
                return obj.__name__

            raise TypeError('Not JSON Serializable:', obj)

        model_config = self._updated_config()
        return json.dumps(model_config, default=get_json_type, **kwargs)

The self._updated_config() method in the Network Class, from which the Model Class inherits will get the configuration of layers, inputs, outputs, activation as well as other necessary params for the model. One thing to keep in mind is to provide a custom object scope if you are using your own implementation by inheriting from Model or Layer classes in keras.

@umesh-timalsina
Copy link
Contributor

umesh-timalsina commented Sep 13, 2019

Update: 962e75c, adds layers, properties such as activation, initializers and connections to a newly imported architecture node. Also, I have created another repositiory here, for collecting different keras model examples and converting them to JSON files for testing. One interesting issue to tackle would be the difference between Sequential Model JSON files and Functional Model JSON files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants