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

Keras MRI logo remains pulsing forever and never loads model #1

Open
kmader opened this issue Jun 20, 2019 · 7 comments
Open

Keras MRI logo remains pulsing forever and never loads model #1

kmader opened this issue Jun 20, 2019 · 7 comments

Comments

@kmader
Copy link

kmader commented Jun 20, 2019

When I run kmri.visualize_model on the encoder from the Keras VAE example (https://keras.io/examples/variational_autoencoder/) it doesn't render. I assume it is related to the keras.layers.Lambda is it possible to get it to skip layers which aren't supported?

Uncaught (in promise) TypeError: Cannot read property 'getBoundingClientRect' of undefined
    at VueComponent.get1DNodePositions (layer-renderer-1d.mixin.js:134)
    at VueComponent.getNodePositions (layer.mixin.js:13)
    at VueComponent.getInputLayerNodePosition (layer.mixin.js:23)
    at one-to-one-edge-renderer.mixin.js:23
    at Array.forEach (<anonymous>)
    at VueComponent.drawEdges (one-to-one-edge-renderer.mixin.js:22)
    at chrome-dino-app.comp.js:96
    at Array.forEach (<anonymous>)
    at chrome-dino-app.comp.js:95

vae_cnn_encoder

@robianmcd
Copy link
Owner

Hmm, for me when I try that model I get an exception thrown from the python process

AttributeError: Layer encoder has multiple inbound nodes, hence the notion of "layer output" is ill-defined. Use `get_output_at(node_index)` instead.

The problem seems to be that there are models nested inside the vae model. Keras MRI works by creating a wrapper model that has an output for every layer.

layer_outputs = [layer.output for layer in model.layers if not isinstance(layer, InputLayer)]
wrappedModel = Model(inputs=model.inputs, outputs=layer_outputs)

I tried recursively getting the layers in the nested model

def get_outputs(model):
    outputs = []

    for layer in model.layers:
        if isinstance(layer, Model):
           outputs = outputs + get_outputs(layer)
        elif not isinstance(layer, InputLayer):
            outputs.append(layer.output)

    return outputs

layer_outputs = get_outputs(model)

wrappedModel = Model(inputs=model.inputs, outputs=layer_outputs)

But it seems like I can't create a model with outputs from a nested model
ValueError: Graph disconnected: cannot obtain value for tensor Tensor("z_sampling:0", shape=(?, 2), dtype=float32) at layer "z_sampling". The following previous layers were accessed without issue: ['encoder_input']

So I'm not sure how to handle nested models. Seems like an issue with other attempts to visualize Keras models too raghakot/keras-vis#37

@kmader
Copy link
Author

kmader commented Jun 20, 2019

Yea I tried vae and got the same error as @robianmcd mentioned and tried just the encoder (which isn't nested) I got the error above

@robianmcd
Copy link
Owner

Loading just the encoder works for me in Chrome with kmri.visualize_model(encoder, x_test). Although the edges to the lambda layer aren't drawn. Are you using chrome?

encoder

@kmader
Copy link
Author

kmader commented Jun 20, 2019

Yes latest chrome but perhaps the pypi for keras_mri is out of date? I'll try installing it from GitHub tomorrow

@robianmcd
Copy link
Owner

I just published version 0.1.1 that has some better error handling but I'm still not sure what could be causing the issue you are having. Try it out when you get a chance and maybe do a hard refresh in chrome to make sure it gets the latest changes.

@kmader
Copy link
Author

kmader commented Jun 21, 2019

So in the updated version I get an error message as alert in the browser and the original

Screen Shot 2019-06-21 at 12 00 21 PM

and then I see some of the visualizations but it fails at the draw edges step

Screen Shot 2019-06-21 at 12 00 50 PM

keras-mri-app.comp.js:115 TypeError: Cannot read property 'getBoundingClientRect' of undefined
    at VueComponent.get1DNodePositions (layer-renderer-1d.mixin.js:134)
    at VueComponent.getNodePositions (layer.mixin.js:13)
    at VueComponent.getInputLayerNodePosition (layer.mixin.js:23)
    at one-to-one-edge-renderer.mixin.js:23
    at Array.forEach (<anonymous>)
    at VueComponent.drawEdges (one-to-one-edge-renderer.mixin.js:22)
    at keras-mri-app.comp.js:101
    at Array.forEach (<anonymous>)
    at keras-mri-app.comp.js:100

@robianmcd
Copy link
Owner

Can you post the code you are using?

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

No branches or pull requests

2 participants