agents icon indicating copy to clipboard operation
agents copied to clipboard

How to convert keras Model to DDQN QNetwork?

Open linfanzz opened this issue 2 years ago • 0 comments

I have a Keras model and I want to use it as the q network for DDQN. I don't know how to do it.

def model():
    x = Input(shape=(_pkt_num, _pkt_bytes, 1))
    y = tf.reshape(x, shape=(-1, _pkt_num, _pkt_bytes, 1))
    data_format = 'channels_last'
    y1 = _text_cnn_block(y, filters=256, height=3, width=_pkt_bytes)
    y2 = _text_cnn_block(y, filters=256, height=4, width=_pkt_bytes)
    y3 = _text_cnn_block(y, filters=256, height=5, width=_pkt_bytes)
    y = layers.concatenate(inputs=[y1, y2, y3], axis=-1)
    y = layers.Flatten(data_format=data_format)(y)
    y = layers.Dense(512, activation='relu')(y)
    y = layers.Dense(256, activation='relu')(y)
    # y = layers.Dense(128, activation='relu')(y)
    y = layers.Dense(_num_class, activation='linear')(y)
    return Model(inputs=x, outputs=y)

I tried using Sequential but failed. So what should I do? If there is one example that is the best.

linfanzz avatar Jan 04 '24 14:01 linfanzz