Code Monkey home page Code Monkey logo

Comments (8)

devinplatt avatar devinplatt commented on May 2, 2024 49

A note to future readers. Because we need to explicitly specify the size of the input we must use the "input_shape" parameter, ie. if before we used

model = Sequential()
model.add(Dense(64, input_dim=20, init='uniform'))

Now we would use

model = Sequential()
model.add(Dropout(0.5, input_shape=(20,)))
model.add(Dense(64, init='uniform'))

(This took me a while to figure out, since I haven't tried anything yet like convolutions which use the "input_shape" parameter, and since I hadn't read about the Abstract base layer class in the documentation, which Dropout inherits from.)

from keras.

the-moliver avatar the-moliver commented on May 2, 2024 15

Dropout on the input layer is actually pretty common, and was used in the original dropout paper IIRC. It would be nice if the following syntax worked (which it currently does not):

model = Sequential()
model.add(Dropout(0.1))
model.add(Dense(784, 20))

from keras.

fchollet avatar fchollet commented on May 2, 2024 3

31ea018 both allows to start models with dimension-agnostic layers like Activation and Dropout, and allows for custom output target shapes (must be specified by the user).

from keras.

pranv avatar pranv commented on May 2, 2024 1

Hey,
Yes you can. The layer takes in a 4D tensor and a probability as input.

Not sure why you would want to do that, but here are is another simple solution:
Do it outside keras. In Python.

from keras.

MadsAdrian avatar MadsAdrian commented on May 2, 2024 1

In the documentation/docstring of keras.layers.core.Activation it is specified that

# Input shape
Arbitrary. Use the keyword argument input_shape
(tuple of integers, does not include the samples axis)
when using this layer as the first layer in a model.

Maybe add this to keras.layers.core.Dropout to clarify that this applies here to. @devinplatt's answer should reach the docs..

from keras.

fchollet avatar fchollet commented on May 2, 2024

That would require to know what tensor type is expected as input (tensor2, tensor3, tensor4...). We need this info at compile time, so before any input has been seen by the network. So it would have to be specified by the user, it can't be automatically inferred.

There would be two potential ways to do that. Either have the user pass the tensor type as an argument to Dropout (only used/needed when Dropout is the first layer in a network), or introduce an "input" layer that takes a similar argument, and that can be optionally used as first layer in a network (required when the first "real" layer is one that does not have a fixed shape, like activation, dropout, etc).

from keras.

jfsantos avatar jfsantos commented on May 2, 2024

I like the input layer approach, especially if we make it optional (i.e., use it only when it's needed by the first "real" layer). Otherwise, all general "adimensional" layers will need to have their dimensions specified, which does not make much sense since it's not really a layer property, but a side effect from the input size.

from keras.

fchollet avatar fchollet commented on May 2, 2024

Here's a different idea that would be even simpler: at compile time, if the first layer is "adimensional", go through the model (list or tree depending on the model type) until you find the first dimensional parent, and set an input attribute on the first layout based on the tensor type of the first dimensional parent.

This would require no change in interface. It would fail in case there is no dimensional parent in the model, in which case the user could still manually set an input attribute on the first layer...

I'll have a go at adding this later today.

from keras.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.