cs230-stanford / cs230-code-examples

Code examples in pyTorch and Tensorflow for CS230
Other
3.79k stars 984 forks source link

Using saved models for prediction of a single image #10

Closed pehpa closed 6 years ago

pehpa commented 6 years ago

Hi,

I am looking for an example how to use a saved checkpoint of your example for simple inference of a given image, i.e. perform classification on a single image. Unfortunately, searching the internet has not been successful so far.

What I haven been doing so far is the following:

with tf.Session() as sess:
    saver = tf.train.import_meta_graph(metafile)
    saver.restore(sess, path_to_ckpt)
    graph = tf.get_default_graph()

    output = graph.get_tensor_by_name('model/pred:0')
    pred = sess.run([output], feed_dict={x: image})

Unfortunately, I am not sure what x is supposed to be. Could you please provide an example for a simple prediction of a single image? Especially, I would need to know which layers to give what name in the model_fn so that I can reference them in the code above.

Best regards.

syw2014 commented 5 years ago

Hi, I met the same problem, have solved it?