def run_eval(load_model, load_sess, filename, sample_num_file, hparams, flag): # load sample num with open(sample_num_file, 'r') as f: sample_num = int(f.readlines()[0].strip()) load_sess.run(load_model.iterator.initializer, feed_dict={load_model.filenames: [filename]}) preds = [] labels = [] while True: try: _, _, step_pred, step_labels = load_model.model.eval(load_sess) preds.extend(np.reshape(step_pred, -1)) labels.extend(np.reshape(step_labels, -1)) except tf.errors.OutOfRangeError: break preds = preds[:sample_num] labels = labels[:sample_num] hparams.logger.info("data num:{0:d}".format(len(labels))) res = metric.cal_metric(labels, preds, hparams, flag) return res