Python tensorflow ValueError: Parent directory of my_test_model doesn't exist, can't save.

import tensorflow as tf  
w1 = tf.Variable(tf.random_normal(shape=[2]), name='w1')  
w2 = tf.Variable(tf.random_normal(shape=[5]), name='w2')  
saver = tf.train.Saver([w1,w2])  
sess = tf.Session()  
sess.run(tf.global_variables_initializer())  
saver.save(sess, 'my_test_model',global_step=1000)

出現錯誤:

wu@wu-X555LF:~/test$ python tf_test1.py 
2019-08-10 12:56:26.243857: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-08-10 12:56:26.330550: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-08-10 12:56:26.330992: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1212] Found device 0 with properties: 
name: GeForce 930M major: 5 minor: 0 memoryClockRate(GHz): 0.941
pciBusID: 0000:04:00.0
totalMemory: 1.96GiB freeMemory: 1.73GiB
2019-08-10 12:56:26.331023: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1312] Adding visible gpu devices: 0
2019-08-10 12:56:27.022071: I tensorflow/core/common_runtime/gpu/gpu_device.cc:993] Creating TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1497 MB memory) -> physical GPU (device: 0, name: GeForce 930M, pci bus id: 0000:04:00.0, compute capability: 5.0)
2019-08-10 12:56:27.054688: W tensorflow/core/framework/op_kernel.cc:1202] OP_REQUIRES failed at save_restore_v2_ops.cc:109 : Not found: ; No such file or directory
Traceback (most recent call last):
  File "tf_test1.py", line 7, in <module>
    saver.save(sess, 'my_test_model',global_step=1000)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1675, in save
    raise exc
ValueError: Parent directory of my_test_model doesn't exist, can't save.

ValueError: Parent directory of my_test_model doesn't exist, can't save.

提示父目錄不存在,所以需要指定目錄

將saver.save(sess, 'my_test_model',global_step=1000)

改成saver.save(sess, './test/my_test_model',global_step=1000)

import tensorflow as tf  
w1 = tf.Variable(tf.random_normal(shape=[2]), name='w1')  
w2 = tf.Variable(tf.random_normal(shape=[5]), name='w2')  
saver = tf.train.Saver([w1,w2])  
sess = tf.Session()  
sess.run(tf.global_variables_initializer())  
saver.save(sess, './test/my_test_model',global_step=1000)

執行成功

wu@wu-X555LF:~/test$ python tf_test1.py 
2019-08-10 13:09:04.518170: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-08-10 13:09:04.616985: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-08-10 13:09:04.617427: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1212] Found device 0 with properties: 
name: GeForce 930M major: 5 minor: 0 memoryClockRate(GHz): 0.941
pciBusID: 0000:04:00.0
totalMemory: 1.96GiB freeMemory: 1.73GiB
2019-08-10 13:09:04.617458: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1312] Adding visible gpu devices: 0
2019-08-10 13:09:05.324274: I tensorflow/core/common_runtime/gpu/gpu_device.cc:993] Creating TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1489 MB memory) -> physical GPU (device: 0, name: GeForce 930M, pci bus id: 0000:04:00.0, compute capability: 5.0)

指定文件夾下多了四個文件:

checkpoint

my_test_model-1000.data-00000-of-00001

my_test_model-1000.index

my_test_model-1000.meta

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章