<p>This problem has been tackled by Yann LeCun in the 90's. You can find demos and papers on his <a href="http://yann.lecun.com/exdb/lenet/" rel="nofollow noreferrer">website</a>. </p>

<p>A not so general solution is to train a CNN on single digits MNIST and use this CNN to perform inference on images like the one you provided. Prediction is done by sliding the trained CNN on the multi-digit image and applying post processing to aggregate the results and possibly estimating the bounding boxes.</p>

<p>A very general solution that can handle a variable number of number and of different scales and positions is to build a model that is able to predict the bounding boxes of the numbers and perform classification on them. There's a recent history of such models with R-CNN, Fast-RCNN and <a href="https://arxiv.org/abs/1506.01497" rel="nofollow noreferrer">Faster-RCNN</a>. </p>

<p>You can find a python implementation of Faster-RCNN on <a href="https://github.com/rbgirshick/py-faster-rcnn" rel="nofollow noreferrer">github.</a></p>
Mnist recognition using keras
<p>How can I train the model to recognize five numbers in one picture.
The code is as follows:</p>

<pre><code>from keras.layers import Conv2D
from keras.layers import MaxPooling2D
from keras.layers import Flatten
from keras.layers import Dropout, Dense, Input
from keras.models import Model, Sequential

model = Sequential()
model.add(Conv2D(32, kernel_size=(3, 3),
             activation='relu',
             input_shape=(28, 140, 1)))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dropout(0.5))
</code></pre>

<p>Here should be a loop for recognizing each number in the picture, but I don't know how to realize it.</p>

<pre><code>model.add(Dense(11, activation='softmax'))

model.compile(loss=keras.losses.categorical_crossentropy,
          optimizer=keras.optimizers.Adadelta(),
          metrics=['accuracy'])

model.fit(X_train, y_train,
      batch_size=1000,
      epochs=8,
      verbose=1,
      validation_data=(X_valid, y_valid))
</code></pre>

<p>The picture of combined mnist number is as follows:</p>

<p><img src="https://i.stack.imgur.com/uOFFU.png" alt="combined numbers in one picture"></p>