I am currently trying to train Google's sketch recognition model, just the one in the link: Github. But I recently encountered problems that have been bothering me for a long time.
The problem is as follows: I have used the code in the link and the data from quickdraw to complete the training. I now have a trained model with three files(.meta,.index,.data), now I want to calculate the confusion matrix for the trained model of 345 categories. But since I have never used the "estimator" of tensorflow, I don't know how to load my trained model files into the code and test it (no training), and how to get the classification score after the softmax layer (used to calculate Confusion matrix).
The ‘estimator’ API really confused me for a long time. Please solve my problem under the code in link:
def create_estimator_and_specs(run_config):
"""Creates an Experiment configuration based on the estimator and input fn."""
model_params = tf.contrib.training.HParams(
num_layers=FLAGS.num_layers,
num_nodes=FLAGS.num_nodes,
batch_size=FLAGS.batch_size,
num_conv=ast.literal_eval(FLAGS.num_conv),
conv_len=ast.literal_eval(FLAGS.conv_len),
num_classes=get_num_classes(),
learning_rate=FLAGS.learning_rate,
gradient_clipping_norm=FLAGS.gradient_clipping_norm,
cell_type=FLAGS.cell_type,
batch_norm=FLAGS.batch_norm,
dropout=FLAGS.dropout)
estimator = tf.estimator.Estimator(
model_fn=model_fn,
config=run_config,
params=model_params)
train_spec = tf.estimator.TrainSpec(
input_fn=get_input_fn(
mode=tf.estimator.ModeKeys.TRAIN,
tfrecord_pattern=FLAGS.training_data,
batch_size=FLAGS.batch_size),
max_steps=FLAGS.steps)
eval_spec = tf.estimator.EvalSpec(
input_fn=get_input_fn(
mode=tf.estimator.ModeKeys.EVAL,
tfrecord_pattern=FLAGS.eval_data,
batch_size=FLAGS.batch_size)
)
return estimator, train_spec, eval_spec
def main(unused_args):
estimator, train_spec, eval_spec = create_estimator_and_specs(
run_config=tf.estimator.RunConfig(
model_dir=FLAGS.model_dir,
save_checkpoints_secs=300,
save_summary_steps=100)
)
tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)
I want to load my trained model into above code and calculate confusion matrix for 345 categories.