I have trained a TensorFlow model and it worked fine when tested with one img. But when I wanted to test more than one img, an error occurred.

**Error:**

> 
> 
> ```
> Traceback (most recent call last):
>   File "C:\Anaconda\lib\site-packages\tensorflow\python\client\session.py", line 1139, in _do_call
>     return fn(*args)
>   File "C:\Anaconda\lib\site-packages\tensorflow\python\client\session.py", line 1121, in _run_fn
>     status, run_metadata)
>   File "C:\Anaconda\lib\contextlib.py", line 89, in __exit__
>     next(self.gen)
>   File "C:\Anaconda\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 466, in raise_exception_on_not_ok_status
>     pywrap_tensorflow.TF_GetCode(status))
> tensorflow.python.framework.errors_impl.NotFoundError: Key Variable_10 not found in checkpoint
>      [[Node: save_1/RestoreV2_2 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_arg_save_1/Const_0_0, save_1/RestoreV2_2/tensor_names, save_1/RestoreV2_2/shape_and_slices)]]
> 
> ```
> 
> 

During handling of the above exception, another exception occurred:

> 
> 
> ```
> Traceback (most recent call last):   File "C:/Users/Louis Song/Desktop/LetsFuckDog/captcha_server.py", line 317, in <module>
>     fuck_captcha("data/bv22.jpg")   File "C:/Users/Louis Song/Desktop/LetsFuckDog/captcha_server.py", line 251, in fuck_captcha
>     saver.restore(sess, tf.train.latest_checkpoint('.'))   File "C:\Anaconda\lib\site-packages\tensorflow\python\training\saver.py", line 1548, in restore
>     {self.saver_def.filename_tensor_name: save_path})   File "C:\Anaconda\lib\site-packages\tensorflow\python\client\session.py", line 789, in run
>     run_metadata_ptr)   File "C:\Anaconda\lib\site-packages\tensorflow\python\client\session.py", line 997, in _run
>     feed_dict_string, options, run_metadata)   File "C:\Anaconda\lib\site-packages\tensorflow\python\client\session.py", line 1132, in _do_run
>     target_list, options, run_metadata)   File "C:\Anaconda\lib\site-packages\tensorflow\python\client\session.py", line 1152, in _do_call
>     raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.NotFoundError: Key Variable_10 not found in checkpoint      [[Node: save_1/RestoreV2_2 = RestoreV2[dtypes=[DT_FLOAT],
> _device="/job:localhost/replica:0/task:0/cpu:0"](_arg_save_1/Const_0_0, save_1/RestoreV2_2/tensor_names, save_1/RestoreV2_2/shape_and_slices)]]
> Caused by op 'save_1/RestoreV2_2', defined at:   File "C:/Users/Louis Song/Desktop/LetsFuckDog/captcha_server.py", line 317, in <module>
>     fuck_captcha("data/bv22.jpg")   File "C:/Users/Louis Song/Desktop/LetsFuckDog/captcha_server.py", line 249, in fuck_captcha
>     saver = tf.train.Saver()   File "C:\Anaconda\lib\site-packages\tensorflow\python\training\saver.py", line 1139, in __init__
>     self.build()   File "C:\Anaconda\lib\site-packages\tensorflow\python\training\saver.py", line 1170, in build
>     restore_sequentially=self._restore_sequentially)   File "C:\Anaconda\lib\site-packages\tensorflow\python\training\saver.py", line 691, in build
>     restore_sequentially, reshape)   File "C:\Anaconda\lib\site-packages\tensorflow\python\training\saver.py", line 407, in _AddRestoreOps
>     tensors = self.restore_op(filename_tensor, saveable, preferred_shard)   File "C:\Anaconda\lib\site-packages\tensorflow\python\training\saver.py", line 247, in restore_op
>     [spec.tensor.dtype])[0])   File "C:\Anaconda\lib\site-packages\tensorflow\python\ops\gen_io_ops.py", line 640, in restore_v2
>     dtypes=dtypes, name=name)   File "C:\Anaconda\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 767, in apply_op
>     op_def=op_def)   File "C:\Anaconda\lib\site-packages\tensorflow\python\framework\ops.py", line 2506, in create_op
>     original_op=self._default_original_op, op_def=op_def)   File "C:\Anaconda\lib\site-packages\tensorflow\python\framework\ops.py", line 1269, in __init__
>     self._traceback = _extract_stack()
> 
> ```
> 
> 

NotFoundError (see above for traceback): Key Variable\_10 not found in checkpoint [[Node: save\_1/RestoreV2\_2 = RestoreV2[dtypes=[DT\_FLOAT],
\_device="/job:localhost/replica:0/task:0/cpu:0"](\_arg\_save\_1/Const\_0\_0, save\_1/RestoreV2\_2/tensor\_names, save\_1/RestoreV2\_2/shape\_and\_slices)]]

**Demo code:**

```
def crack_captcha():
output = crack_captcha_cnn()

saver = tf.train.Saver()
with tf.Session() as sess:
    saver.restore(sess, tf.train.latest_checkpoint('.'))
    n = 1
    while n <= 10:
        name, image = get_name_and_image()
        print(image.shape)
        print(name)
        if image.shape !=(60, 160, 3):
            print('原始图片错误，请核查')
            pass
        else:
            image = convert2gray(image)
        # middle=image.flatten() /255
        try:
            image = image.flatten() / 255
            predict = tf.argmax(tf.reshape(output, [-1, MAX_CAPTCHA, ALL_SET_LEN]), 2)
            text_list = sess.run(predict, feed_dict={X: [image], keep_prob: 1})
            text = text_list[0].tolist()
            vector = np.zeros(MAX_CAPTCHA * ALL_SET_LEN)
            i = 0
            for n in text:
                vector[i * ALL_SET_LEN + n] = 1
                i += 1

            print(vector)
            predict_text = vec2name(vector)
            print("正确: {}  预测: {}".format(name, predict_text))
            if name !=predict_text:
                print('预测失败')
                global error_time
                error_time+=1
            else:
                print('预测成功')
                global correct_time
                correct_time+=1
            n += 1
            print(n)
        except TypeError as e :
            print(e)
            n += 1
            print(n)
            pass

```

**Magic reason:**

When I call more than once `crack_captcha` function, here is the error. But when I just call one time `crack_captcha` function, It can give my predict result.