question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lambda output layer

See original GitHub issue

I’ve a sequential model as follows with a linear activation function (Keras default) for the single output neuron:

model = Sequential()
model.add( ...
...
model.add(Dense(100, activation='relu'))
model.add(Dense(1))

I need the final number to be bounded by 100, so I modified the last line of code above to be: model.add(Lambda(lambda x: x%100, output_shape=(1))) 1- Is it correct? Does x here means the net as I expect ? 2- I get an error: “In Lambda, output_shape must be a list, a tuple, or a function”.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
farizrahman4ucommented, Oct 25, 2016

(Notice the comma after 1)

model.add(Lambda(lambda x: x%100, output_shape=(1,))

You can also igonre the output_shape argument in this case.

model.add(Lambda(lambda x: x%100))

For bounding by 100, I think you should use K.clip.

1reaction
kgrmcommented, Oct 27, 2016

For an example of a function that takes an arbitrary-shape tensor and outputs a scalar, see K.sum().

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using layers with your Lambda function - AWS Documentation
A Lambda layer is a .zip file archive that can contain additional code or other content. A layer can contain libraries, a custom...
Read more >
Lambda layer - Keras
The Lambda layer exists so that arbitrary expressions can be used as a Layer when constructing Sequential and Functional API models. Lambda layers...
Read more >
Working With The Lambda Layer in Keras - Paperspace Blog
In this tutorial we'll cover how to use the Lambda layer in Keras to build, save and load models which perform custom operations...
Read more >
How to Use Lambda Layer in a Neural Network?
the lambda layer is a layer for neural network that helps in the data transformation between the other layers of a neural network....
Read more >
Lambda Layers in tf.keras - Medium
Lambda layer is an easy way to customize a layer to do simple… ... the output from the previous layer as input and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found