how to store and access trained neural networks

Viewed 2173

I just started learning NN recently on python with keras, I've a pretty obvious question that nobody seems to ever mention its answer.

the question is very simple.

what happen after you get the data, build the model and train your network ?
every tutorial go through this thoroughly, but never mention how to use your trained model or store it after that.
so for example I written this simple code with keras to train a network on MNIST :

model = Sequential()
model.add(Convolution2D(32, kernel_size=3,data_format="channels_first", 
activation='relu', input_shape=(1,28,28)))
model.add(Convolution2D(32, (3 ,3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(10, activation='softmax'))
#compiling
model.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['accuracy'])
#fitting and training
model.fit(X_train, Y_train,batch_size=32, epochs=1, verbose=1)

now how do i store the final network and reuse it again after i close the the the editor ?

for example if i wanna build a simple web interface to upload a MNIST pic and run it through the pre-trained model and detect the answer.

How can i store the trained Model with Python , access it with JS or php, run the uploaded picture through it , and return the output back to the user.

thanks, and sorry if my question seems stupid or obvious.

1 Answers
Related