jiegzhan / multi-class-text-classification-cnn

Classify Kaggle Consumer Finance Complaints into 11 classes. Build the model with CNN (Convolutional Neural Network) and Word Embeddings on Tensorflow.
Apache License 2.0
426 stars 198 forks source link

NotFoundError: encountered while running function tf.train.latest_checkpoint() in predict.py #13

Open bhanu-sharma opened 7 years ago

bhanu-sharma commented 7 years ago

Both the model and the checkpoints exist in the same directory. This is the error i encounter when i try to run the file.

NotFoundError                    Traceback (most recent call last)
<ipython-input-60-8de4d687f60c> in <module>()
  5     checkpoint_dir += '/'
  6 print (checkpoint_dir + 'checkpoints')
  ----> 7 checkpoint_file = tf.train.latest_checkpoint(checkpoint_dir +    'checkpoints')
  8 print (checkpoint_file)

  /usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py in latest_checkpoint(checkpoint_dir, latest_filename)
 1612     v1_path = _prefix_to_checkpoint_path(ckpt.model_checkpoint_path,
 1613                                          saver_pb2.SaverDef.V1)
 -> 1614     if file_io.get_matching_files(v2_path) or     file_io.get_matching_files(
 1615         v1_path):
 1616       return ckpt.model_checkpoint_path

 /usr/local/lib/python3.5/dist-packages/tensorflow/python/lib/io/file_io.py in get_matching_files(filename)
 330           # Convert the filenames to string from bytes.
 331           compat.as_str_any(matching_filename)
 --> 332           for single_filename in filename
 333           for matching_filename in pywrap_tensorflow.GetMatchingFiles(
 334               compat.as_bytes(single_filename), status)

/usr/lib/python3.5/contextlib.py in __exit__(self, type, value, traceback)
 64         if type is None:
 65             try:
 ---> 66                 next(self.gen)
 67             except StopIteration:
 68                 return

/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/errors_impl.py in raise_exception_on_not_ok_status()
464           None, None,
465           compat.as_text(pywrap_tensorflow.TF_Message(status)),
--> 466           pywrap_tensorflow.TF_GetCode(status))
467   finally:
468     pywrap_tensorflow.TF_DeleteStatus(status)

NotFoundError: /home/user/cnn-model/trained_model_1506946529/checkpoints
jiegzhan commented 7 years ago

~/Desktop/multi-class-text-classification-cnn/trained_model_1509570669/checkpoints$ ls checkpoint model-1000.meta model-1200.meta model-1400.meta model-600.meta model-800.meta model-1000.data-00000-of-00001 model-1200.data-00000-of-00001 model-1400.data-00000-of-00001 model-600.data-00000-of-00001 model-800.data-00000-of-00001 model-1000.index model-1200.index model-1400.index model-600.index model-800.index ~/Desktop/multi-class-text-classification-cnn/trained_model_1509570669/checkpoints$ ls ../../trained_model_1479757124/

Got a trained_model_1509570669 folder.

jiegzhan commented 7 years ago

~/Desktop/multi-class-text-classification-cnn$ python3 predict.py ./trained_model_1509570669/ ./data/small_samples.json CRITICAL:root:Loaded the trained model: /home/ai-admin/Desktop/multi-class-text-classification-cnn/trained_model_1509570669/checkpoints/model-1400 INFO:root:The number of x_test: 1000 INFO:root:The number of y_test: 1000 2017-11-01 21:30:05.576209: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations. 2017-11-01 21:30:05.576240: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. 2017-11-01 21:30:05.576247: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. 2017-11-01 21:30:05.576258: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations. 2017-11-01 21:30:05.576268: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations. NVIDIA: no NVIDIA devices found 2017-11-01 21:30:05.585781: E tensorflow/stream_executor/cuda/cuda_driver.cc:406] failed call to cuInit: CUDA_ERROR_UNKNOWN 2017-11-01 21:30:05.585827: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:145] kernel driver does not appear to be running on this host: /proc/driver/nvidia/version does not exist INFO:tensorflow:Restoring parameters from /home/ai-admin/Desktop/multi-class-text-classification-cnn/trained_model_1509570669/checkpoints/model-1400 INFO:tensorflow:Restoring parameters from /home/ai-admin/Desktop/multi-class-text-classification-cnn/trained_model_1509570669/checkpoints/model-1400 CRITICAL:root:The accuracy is: 0.741

bhanu-sharma commented 7 years ago

Thank you. Though i saved the model as a ckpt file and to call the model ran these commands

saver = tf.train.import_meta_graph(checkpoint_dir + 'checkpoints/generator.ckpt.meta')  
saver.restore(sess, tf.train.latest_checkpoint(checkpoint_dir + 'checkpoints'))   

The prediction script worked for me then.
You can now close the issue if you like, it's resolved from my side.