def myModel():
noOfFilters = 60
sizeOfFilter1 = (5, 5)
sizeOfFilter2 = (3, 3)
sizeOfPool = (2, 2)
noOfNodes = 500
model = Sequential()
model.add((Conv2D(6, sizeOfFilter1, input_shape=(32, 32, 1), activation='relu')))
model.add(MaxPooling2D(pool_size=sizeOfPool))
model.add((Conv2D(16, sizeOfFilter1, activation='relu')))
model.add(MaxPooling2D(pool_size=sizeOfPool))
model.add(Flatten())
model.add(Dense(120,activation='relu'))
model.add(Dense(84, activation='relu'))
model.add(Dropout(0.4))
model.add(Dense(noOfClasses, activation='softmax'))
model.compile(Adam(learning_rate=0.001), loss='categorical_crossentropy', metrics=['accuracy'])
return model
model = myModel()
history = model.fit(X_train,y_train,validation_data=(X_val,y_val),epochs=5,steps_per_epoch=1000)
pickle_out = open("model_trained.p", "wb")
pickle.dump(model,pickle_out)
pickle_out.close()
This is the error i'm getting:
pickle.dump(model,pickle_out)
TypeError: can't pickle _thread.RLock objects
I want to save my trained model so that i can use it in a different file. When i try to save the model using pickle, this error pops up. What can i do to remove this error? Or is there an alternate way to save my model?