//  [python]
def train(self):
        y_pred = self.alexnet_model()
        # y_pred = self.Letnet_model()
        print(">>>input batch predict shape:{}".format(y_pred.shape))
        print(">>>End model test")
        # 计算损失函数
        with tf.name_scope('cost'):
            cost = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=y_pred, labels=self.Y))
        # 梯度下降法
        with tf.name_scope('train'):
            optimizer = tf.train.GradientDescentOptimizer(0.000008).minimize(cost)
        # 计算准确率
        predict = tf.reshape(y_pred, [-1, self.max_captcha, self.char_set_len])
        max_idx_p = tf.argmax(predict, 2)  # 返回在张量轴上具有最大值的索引
        max_idx_l = tf.argmax(tf.reshape(self.Y, [-1, self.max_captcha, self.char_set_len]), 2)  #
        # 计算准确率
        correct_pred = tf.equal(max_idx_p, max_idx_l)
        with tf.name_scope('char_acc'):
            accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32))
        with tf.name_scope('image_acc'):
            accuracy_image_count = tf.reduce_mean(tf.reduce_min(tf.cast(correct_pred, tf.float32), axis=1))
        init = tf.initialize_all_variables()
        saver = tf.train.Saver()
        # 设置模型存储路径

        config = tf.ConfigProto()
        config.gpu_options.per_process_gpu_memory_fraction = 0.7

        with tf.Session(config=config) as sess:
            init = tf.initialize_all_variables()
            sess.run(init)
            # 导入模型
            if os.path.exists(self.model_save_dir):
                try:
                    saver.restore(sess, self.model_save_dir)
                except:
                    print('model文件夹为空')

            tf.summary.FileWriter("logs/", sess.graph)
            step = 1
            for i in range(self.cycle_stop):
                batch_x, batch_y = self.get_train_batch(i, self.train_batch_size)

                # 梯度下降法训练
                _, cost_ = sess.run([optimizer, cost], feed_dict={self.X: batch_x, self.Y: batch_y, self.keep_prob: 0.75})

                if step % 10 == 0:  # 每10 step计算一次准确率
                    # 计算精度
                    batch_x_t, batch_y_t = self.get_verify_batch(64)
                    acc_char = sess.run(accuracy, feed_dict={self.X: batch_x_t, self.Y: batch_y_t, self.keep_prob: 1.})
                    acc_img = sess.run(accuracy_image_count, feed_dict={self.X: batch_x_t, self.Y: batch_y_t, self.keep_prob:1.})

                    print ("Iter:{0}, Minibatch Loss= {1}，".format(step, cost_) +
                           "Accuracy_char= {:.5f}，Accuracy_img = {:.5f}".format(acc_char, acc_img))
                    if acc_img > self.acc_stop:
                        saver.save(sess, self.model_save_dir)
                        print("准确率得到标准，保存模型")
                        break

                    if step % 500 == 0:
                        saver.save(sess, self.model_save_dir)
                        print('保存模型：{}'.format(step))
                step += 1
            saver.save(sess, self.model_save_dir)

            print ("Optimization Finished!")
            # 计算测试精度
            batch_x_t, batch_y_t = self.get_verify_batch(128)
            print( "Testing Accuracy:",step, sess.run(accuracy, feed_dict={self.X: batch_x_t, self.Y: batch_y_t, self.keep_prob: 1.}))