def train_cnn():
    output = panda_joke_cnn()
    loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=Y, logits=output))
    optimizer = tf.train.AdamOptimizer(learning_rate=0.001).minimize(loss)
    accuracy = tf.reduce_mean(tf.cast(tf.equal(tf.argmax(output, 1), tf.argmax(Y, 1)), tf.float32))
    tf.summary.scalar('loss', loss)
    tf.summary.scalar('accuracy', accuracy)
    merged_summary_op = tf.summary.merge_all()
    saver = tf.train.Saver()
    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        summary_writer = tf.summary.FileWriter('./log', graph=tf.get_default_graph())
        for e in range(50):
            for i in range(num_batch):
                batch_x = train_x[(i * batch_size):((i + 1) * batch_size)]
                batch_y = train_y[(i * batch_size):((i + 1) * batch_size)]
                (_, loss_, summary) = sess.run([optimizer, loss, merged_summary_op], feed_dict={X: batch_x, Y: batch_y, keep_prob_5: 0.5, keep_prob_75: 0.75})
                summary_writer.add_summary(summary, ((e * num_batch) + i))
                print(((e * num_batch) + i), 'loss= ', loss_)
                if ((((e * num_batch) + i) % 100) == 0):
                    acc = accuracy.eval({X: test_x, Y: test_y, keep_prob_5: 1.0, keep_prob_75: 1.0})
                    print(((e * num_batch) + i), 'acc= ', (+ acc))
                    if (acc > 0.99):
                        saver.save(sess, 'G:/codes/tensorflow2/WhetherOrNotMe/models/whether_orNot_me.model', global_step=((e * num_batch) + i))
                        if (((e * num_batch) + i) > 0):
                            sys.exit(0)
def train_cnn():
    output = panda_joke_cnn()
    loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=Y, logits=output))
    optimizer = tf.train.AdamOptimizer(learning_rate=0.001).minimize(loss)
    accuracy = tf.reduce_mean(tf.cast(tf.equal(tf.argmax(output, 1), tf.argmax(Y, 1)), tf.float32))
    tf.summary.scalar('loss', loss)
    tf.summary.scalar('accuracy', accuracy)
    merged_summary_op = tf.summary.merge_all()
    saver = tf.train.Saver()
    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        summary_writer = tf.summary.FileWriter('./log', graph=tf.get_default_graph())
        for e in range(50):
            for i in range(num_batch):
                batch_x = train_x[(i * batch_size):((i + 1) * batch_size)]
                batch_y = train_y[(i * batch_size):((i + 1) * batch_size)]
                (_, loss_, summary) = sess.run([optimizer, loss, merged_summary_op], feed_dict={X: batch_x, Y: batch_y, keep_prob_5: 0.5, keep_prob_75: 0.75})
                summary_writer.add_summary(summary, ((e * num_batch) + i))
                print(((e * num_batch) + i), 'loss= ', loss_)
                if ((((e * num_batch) + i) % 100) == 0):
                    acc = accuracy.eval({X: test_x, Y: test_y, keep_prob_5: 1.0, keep_prob_75: 1.0})
                    print(((e * num_batch) + i), 'acc= ', (+ acc))
                    if (acc > 0.99):
                        saver.save(sess, 'G:/codes/tensorflow2/WhetherOrNotMe/models/whether_orNot_me.model', global_step=((e * num_batch) + i))
                        if (((e * num_batch) + i) > 0):
                            sys.exit(0)