accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32)) '''Model save''' # Initialize the saver to save session. saver = tf.train.Saver(write_version=tf.train.SaverDef.V1, max_to_keep=50) saved_model_path = 'model/' to_save_model_path = 'model/' '''Start a session and run up.''' with tf.Session(config=config) as sess: logging.info("Session started!") sess.run(tf.global_variables_initializer()) # Prepare data set. dataSet = InputReader(dataFile, batchSize, timestepSize) # Prepare result writer. resultWriter = ResultWriter(resultFile) for i in range(iteration): (batchX, batchY) = dataSet.getBatch(i) _, trainingCost, modelOutput = sess.run([train_op, cost, logits], feed_dict={ X: batchX, y: batchY, keep_prob: 1.0 }) logging.info("Iteration:" + str(i) + ", \tbatch loss= {:.6f}".format(trainingCost)) logging.debug("batchX:" + str(batchX[0])) logging.debug("batchY:" + str(batchY[0])) logging.debug("modelOutput:" + str(modelOutput[0])) # Save output result. if (i) % saveIteration == 0: # Save model saver.save(sess, to_save_model_path, global_step=saveIteration)