Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine multiple outputs in tensorflowjs

I have been given a model by a college and want to use it to create a heatmap. To do so, i need to get the result of the last convolutional layer. So I've tried to create a new model using the definitions of the old. I've seen this is possible in python and it seems it should be possible according to the docs.

My code looks something like this:

const combined_output_model = (cam_model) => {
    const conv_layer = cam_model.layers.length - 3
    const input_layer = cam_model.input
    const output_layer = cam_model.layers[conv_layer].output
    return model = tf.model(
        inputs=input_layer,
        outputs=output_layer
    )

However, when I run the code I get the following error:

container.ts:156 Uncaught (in promise) TypeError: Cannot read property 'sourceLayer' of undefined
    at e [as constructor] (container.ts:156)
    at new e (training.ts:483)
    at Object.t.model (exports.ts:74)
    at predictor (prediction.js:28)

when looking at both input_layer and output_layer in the local variables show they both have sourceLayers

Any help appreciated.

Regards

like image 668
user25470 Avatar asked Apr 26 '26 07:04

user25470


1 Answers

You are using a python-like sentence for creating the model in js. In js, tf.model takes an object

return model = tf.model(
        {inputs: input_layer,
        outputs: output_layer}
    )

Similar answer can be found here

like image 55
edkeveked Avatar answered Apr 27 '26 21:04

edkeveked



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!