When I run
pickle.dump(model,open('modelDL.pkl','wb'))
I get
TypeError: can't pickle weakref objects
I have a created a deep learning model which I am trying to save. The model:
model = Sequential()
model.add( Dense(30,activation='relu') )
model.add( Dropout(0.5) )
model.add( Dense(20,activation='relu') )
model.add( Dropout(0.5) )
model.add( Dense(20,activation='relu') )
model.add( Dropout(0.5) )
model.add( Dense(1,activation='sigmoid') )
model.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])
can't pickle weakref comes because Deep Learning models are too large and pickle only used for storing small models
Use this : HDF5 used for storing large data
from keras.models import load_model
model.save('my_model.h5') # creates a HDF5 file 'my_model.h5'
returns a compiled model
identical to the previous one
model1 = load_model('my_model.h5')
y_pred = model1.predict(x_test)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With