Scratch
Scratch

Reputation: 373

How can I create a dummy model in Keras?

I am using keras and trying to train a classifier on 64x64 images.

I am trying to optimise my training pipeline and to catch the bottlenecks.

To this end I'm trying to create the simpler Keras model so that I know what time the whole process (loading image, data augmentation,...) takes with a very low charge on the GPU.

So far I managed to write:

def create_network_dummy():
  INPUT_SHAPE = (64, 64, 1)
  inputs = Input(INPUT_SHAPE)
  out = MaxPooling2D(pool_size = (1,1), strides=(64,64), 1)(inputs)
  model = Model(inputs=[inputs], outputs=[out])
  return model

Is it possible to have an even smaller one ? Returning a constant won't do because it breaks the graph and keras will not allow it.

Upvotes: 5

Views: 3840

Answers (2)

Daniel Möller
Daniel Möller

Reputation: 86630

import keras.backend as K
from keras.layers import Input, Lambda
from keras.models import Model

inp = Input((64,64,1))
out = Lambda(lambda x: K.identity(x))(inp)
model = Model(inp,out) #You could even try Model(inp,inp)

??

If the idea is to have a model that does nothing, this seems the best.
You can return a constant too, you don't really need to "train" to see what you proposed, you can just "predict".

model.predict_generator(....)

Another model wich outputs 1 class

inp = Input((64,64,1))
out = Lambda(lambda x: x[:,0,0])(inp)
model = Model(inp,out)

Upvotes: 2

today
today

Reputation: 33450

I think there is no need to even use K.identity:

inp = Input((64, 64, 1))
out = Lambda(lambda x: x)(inp)
model = Model(inp, out)

Upvotes: 2

Related Questions