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

Converter flag for allowing network to receive input from outside #146

Open
studywolf opened this issue Apr 2, 2020 · 0 comments
Open

Comments

@studywolf
Copy link
Collaborator

The scenario is that I want to convert a Keras network to a subnetwork in a larger Nengo network. Currently this doesn't work because I can't pass input into the converted network. I can hack this in by changing

@Converter.register(tf.keras.layers.InputLayer)
class ConvertInput(LayerConverter):
    """Convert ``tf.keras.layers.InputLayer`` to Nengo objects."""
    def convert(self, node_id):
        try:
            # if this input layer has an input obj, that means it is a passthrough
            # (so we just return the input)
            output = self.get_input_obj(node_id)
        except KeyError:
            # not a passthrough input, so create input node
            shape = self.output_shape(node_id)
            if any(x is None for x in shape):
                raise ValueError(
                    "Input shapes must be fully specified; got %s" % (shape,)
                )
            # output = nengo.Node(np.zeros(np.prod(shape)), label=self.layer.name)
            output = nengo.Node(size_in=np.prod(shape), label=self.layer.name)
...

and then i can

with nengo.Network() as net:
    converter = nengo_dl.Convert(model)
    vision = converter.net
    ens = nengo.Ensemble(...)
    nengo.Connection(ens, converter.inputs[model.input])
    nengo.Connection(converter.layers[model.output_layer], ens)

which isn't great but works. But now it no longer works when just running it in with the nengo dl sim.predict. Since i'm unfamiliar with the code i'm not sure what setting it to handle both cases would look like, but ideally there would be another function to export to a subnetwork. So i could

with nengo.Network() as net:
    converter = nengo_dl.Convert(model, make_subnet=True)
    visionnet = converter.ExportSubNet()
    ens = nengo.Ensemble(...)
    nengo.Connection(ens, visionnet.input)
    nengo.Connection(visionnet.outpt, ens)

or somesuch!

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

No branches or pull requests

1 participant