简体   繁体   中英

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.

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)

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM