Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import keras
- from keras.models import Model
- from keras.layers import Input, Dense
- def get_model1():
- inputs = Input(shape=(20,))
- x = inputs
- x = Dense(15)(x)
- x = Dense(10)(x)
- x = Dense(30, activation='softmax')(x)
- model = Model(inputs=inputs, outputs=x)
- return model
- def main():
- model1 = get_model1()
- model1.compile(loss='categorical_crossentropy', optimizer='sgd')
- print(model1.summary())
- # Assume a scenario where user sets weights of model1 via some
- # pretraining strategy, such as stacked DAEs, and the size of the last
- # layer is inconsequential, since users typically ignore it in pretraining
- # Now, after it is trained, we save the weights
- # (just using the initial weights here)
- model1.save_weights('pretrained_weights.h5')
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment