Chatbot UseCase Specific : tensorflow.python.framework.errors_impl.NotFoundError:

This error is specific to my use case.

I renamed the directory

/home/cdpdemo/tensorflow/ticket_classification to /home/cdpdemo/tensorflow/Intent

I added on file PredictIntent.py and updated it with correct path.

#! /usr/bin/env python

import tensorflow as tf
import numpy as np
import os
import time
import datetime
import data_helpers
from text_cnn import TextCNN
from tensorflow.contrib import learn
import csv


# Eval Parameters
tf.flags.DEFINE_integer("batch_size", 64, "Batch Size (default: 64)")
tf.flags.DEFINE_string("checkpoint_dir", "", "Checkpoint directory from training run")
tf.flags.DEFINE_boolean("eval_train", False, "Evaluate on all training data")

# Misc Parameters
tf.flags.DEFINE_boolean("allow_soft_placement", True, "Allow device soft device placement")
tf.flags.DEFINE_boolean("log_device_placement", False, "Log placement of ops on devices")


FLAGS = tf.flags.FLAGS
FLAGS._parse_flags()

def predict(x_raw):

        FULL_MODEL_PATH='/home/cdpdemo/tensorflow/Intent/runs/1495193437/checkpoints/'
        FULL_VOCAB_PATH='/home/cdpdemo/tensorflow/Intent/runs/1495193437/vocab'
        CLASS_PATH='/home/cdpdemo/UbuntuDialogeDataSet/ubuntu-ranking-dataset-creator/src/dialogs/newcategories2'

        y_test = None #[1,0,0,0,0,0,0,0,0,0,0,0,0]

        # Map data into vocabulary
        vocab_processor = learn.preprocessing.VocabularyProcessor.restore(FULL_VOCAB_PATH)
        x_test = np.array(list(vocab_processor.transform(x_raw)))
        print("\nEvaluating...\n")

        checkpoint_file = tf.train.latest_checkpoint(FULL_MODEL_PATH)
        graph = tf.Graph()
        with graph.as_default():
                session_conf = tf.ConfigProto(
                allow_soft_placement=FLAGS.allow_soft_placement,
                log_device_placement=FLAGS.log_device_placement)
                sess = tf.Session(config=session_conf)
                with sess.as_default():
                # Load the saved meta graph and restore variables
                        saver = tf.train.import_meta_graph("{}.meta".format(checkpoint_file))
                        saver.restore(sess, checkpoint_file)

        # Get the placeholders from the graph by name
                        input_x = graph.get_operation_by_name("input_x").outputs[0]
        # input_y = graph.get_operation_by_name("input_y").outputs[0]
                        dropout_keep_prob = graph.get_operation_by_name("dropout_keep_prob").outputs[0]

        # Tensors we want to evaluate
                        predictions = graph.get_operation_by_name("output/predictions").outputs[0]

        # Generate batches for one epoch
                        batches = data_helpers.batch_iter(list(x_test), FLAGS.batch_size, 1, shuffle=False)

        # Collect the predictions here
                        all_predictions = []

                        for x_test_batch in batches:
                                batch_predictions = sess.run(predictions, {input_x: x_test_batch, dropout_keep_prob: 1.0})
                                all_predictions = np.concatenate([all_predictions, batch_predictions])

                # Print accuracy if y_test is defined
        if y_test is not None:
                correct_predictions = float(sum(all_predictions == y_test))
                print("Total number of test examples: {}".format(len(y_test)))
                print("Accuracy: {:g}".format(correct_predictions/float(len(y_test))))

                # Save the evaluation to a csv
        predictions_human_readable = np.column_stack((np.array(x_raw), all_predictions))
        print(predictions_human_readable)

        files=os.listdir(CLASS_PATH)
        pred_class=""
        for pred in predictions_human_readable:
                print("Description:",pred[0],", Category:",files[int(float(pred[1]))])
                pred_class=files[int(float(pred[1]))]
        return pred_class

I added below empty file to directory /home/cdpdemo/tensorflow/Intent to act as a package

 __init__.py

When i tried to use this package in python cli, i get below error,

Mon May 22 05:32:47 UTC 2017:cdpdemo:/home/cdpdemo>python
Python 2.7.12+ (default, Sep 17 2016, 12:08:02)
[GCC 6.2.0 20160914] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from Intent import PredictIntent
>>> PredictIntent.predict("How are you?")

Evaluating...

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/cdpdemo/tensorflow/Intent/PredictIntent.py", line 41, in predict
    checkpoint_file = tf.train.latest_checkpoint(FULL_MODEL_PATH)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1599, in latest_checkpoint
    if file_io.get_matching_files(v2_path) or file_io.get_matching_files(
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/lib/io/file_io.py", line 323, in get_matching_files
    compat.as_bytes(filename), status)]
  File "/usr/lib/python2.7/contextlib.py", line 24, in __exit__
    self.gen.next()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/errors_impl.py", line 466, in raise_exception_on_not_ok_status
    pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.NotFoundError: /home/cdpdemo/tensorflow/ticket_classification/runs/1495193437/checkpoints
>>>

Initially I thought this was error from the code, but it is actually in the checkpoint file.

Checkpoint file at location /home/cdpdemo/tensorflow/Intent/runs/1495193437/checkpoints/ contained following entry

model_checkpoint_path: "/home/cdpdemo/tensorflow/ticket_classification/runs/1495193437/checkpoints/model-101600"
all_model_checkpoint_paths: "/home/cdpdemo/tensorflow/ticket_classification/runs/1495193437/checkpoints/model-101200"
all_model_checkpoint_paths: "/home/cdpdemo/tensorflow/ticket_classification/runs/1495193437/checkpoints/model-101300"
all_model_checkpoint_paths: "/home/cdpdemo/tensorflow/ticket_classification/runs/1495193437/checkpoints/model-101400"
all_model_checkpoint_paths: "/home/cdpdemo/tensorflow/ticket_classification/runs/1495193437/checkpoints/model-101500"
all_model_checkpoint_paths: "/home/cdpdemo/tensorflow/ticket_classification/runs/1495193437/checkpoints/model-101600"

Updated this file to

model_checkpoint_path: "/home/cdpdemo/tensorflow/Intent/runs/1495193437/checkpoints/model-101600"
all_model_checkpoint_paths: "/home/cdpdemo/tensorflow/Intent/runs/1495193437/checkpoints/model-101200"
all_model_checkpoint_paths: "/home/cdpdemo/tensorflow/Intent/runs/1495193437/checkpoints/model-101300"
all_model_checkpoint_paths: "/home/cdpdemo/tensorflow/Intent/runs/1495193437/checkpoints/model-101400"
all_model_checkpoint_paths: "/home/cdpdemo/tensorflow/Intent/runs/1495193437/checkpoints/model-101500"
all_model_checkpoint_paths: "/home/cdpdemo/tensorflow/Intent/runs/1495193437/checkpoints/model-101600"

Now I am able to load the package properly.

results for ""

    No results matching ""