Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tensorflow已保存\u模型负载问题_Python_Tensorflow - Fatal编程技术网

Python Tensorflow已保存\u模型负载问题

Python Tensorflow已保存\u模型负载问题,python,tensorflow,Python,Tensorflow,我试图从检查点加载tensorflow模型,但由于某些原因,我得到了错误: “传递的保存路径不是有效的检查点:/path/variables/variables” 我注意到,出于某种原因,它向路径添加了一个额外的“变量”字符串。对吗?我的目录文件结构包含/path/variables文件夹中的variables.data--和variables.index文件 我用来加载模型的代码是: tf.saved_model.loader.load(current_session, [tf.saved_m

我试图从检查点加载tensorflow模型,但由于某些原因,我得到了错误: “传递的保存路径不是有效的检查点:/path/variables/variables”

我注意到,出于某种原因,它向路径添加了一个额外的“变量”字符串。对吗?我的目录文件结构包含/path/variables文件夹中的variables.data--和variables.index文件

我用来加载模型的代码是:

tf.saved_model.loader.load(current_session, [tf.saved_model.tag_constants.SERVING], path)
为了保存它,我正在做:

self.builder = tf.saved_model.builder.SavedModelBuilder(path)
self.builder.add_meta_graph_and_variables(self.sess, [tf.saved_model.tag_constants.SERVING], signature_def_map='prediction': self.prediction.signature,})
self.builder.save()
我注意到它在路径中添加了一个额外的“变量”字符串,例如 有些原因。对吗

是的,它是正确的。请参考下面的代码,这里的模型保存在
/savedmodel/
,当它从
/savedmodel/variables/variables
加载时

我能够使用
tf执行代码保存和恢复。保存的_模型
在Google Colab和Ananconda(Jupyter笔记本)中都能正常工作

为了社区的利益,这里使用Google Colab中的
tf.saved_model
添加保存和加载

保存模型:

%tensorflow_version 1.x

import tensorflow as tf

# define the tensorflow network and do some trains
x = tf.placeholder("float", name="x")
w = tf.Variable(2.0, name="w")
b = tf.Variable(0.0, name="bias")

h = tf.multiply(x, w)
y = tf.add(h, b, name="y")
sess = tf.Session()
sess.run(tf.global_variables_initializer())

# save the model
export_path =  './savedmodel'
builder = tf.saved_model.builder.SavedModelBuilder(export_path)

tensor_info_x = tf.saved_model.utils.build_tensor_info(x)
tensor_info_y = tf.saved_model.utils.build_tensor_info(y)

prediction_signature = (
  tf.saved_model.signature_def_utils.build_signature_def(
      inputs={'x_input': tensor_info_x},
      outputs={'y_output': tensor_info_y},
      method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME))

builder.add_meta_graph_and_variables(
  sess, [tf.saved_model.tag_constants.SERVING],
  signature_def_map={
      tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY:
          prediction_signature 
  },
  )
builder.save()
输出:

TensorFlow 1.x selected.
WARNING:tensorflow:From <ipython-input-1-1c4a4b6eef10>:19: build_tensor_info (from tensorflow.python.saved_model.utils_impl) is deprecated and will be removed in a future version.
Instructions for updating:
This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.utils.build_tensor_info or tf.compat.v1.saved_model.build_tensor_info.
INFO:tensorflow:No assets to save.
INFO:tensorflow:No assets to write.
INFO:tensorflow:SavedModel written to: ./savedmodel/saved_model.pb
b'./savedmodel/saved_model.pb'
TensorFlow 1.x selected.
WARNING:tensorflow:From <ipython-input-1-097ac1a9f3ad>:14: load (from tensorflow.python.saved_model.loader_impl) is deprecated and will be removed in a future version.
Instructions for updating:
This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.loader.load or tf.compat.v1.saved_model.load. There will be a new function for importing SavedModels in Tensorflow 2.0.
INFO:tensorflow:Restoring parameters from ./savedmodel/variables/variables
6.0
输出:

TensorFlow 1.x selected.
WARNING:tensorflow:From <ipython-input-1-1c4a4b6eef10>:19: build_tensor_info (from tensorflow.python.saved_model.utils_impl) is deprecated and will be removed in a future version.
Instructions for updating:
This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.utils.build_tensor_info or tf.compat.v1.saved_model.build_tensor_info.
INFO:tensorflow:No assets to save.
INFO:tensorflow:No assets to write.
INFO:tensorflow:SavedModel written to: ./savedmodel/saved_model.pb
b'./savedmodel/saved_model.pb'
TensorFlow 1.x selected.
WARNING:tensorflow:From <ipython-input-1-097ac1a9f3ad>:14: load (from tensorflow.python.saved_model.loader_impl) is deprecated and will be removed in a future version.
Instructions for updating:
This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.loader.load or tf.compat.v1.saved_model.load. There will be a new function for importing SavedModels in Tensorflow 2.0.
INFO:tensorflow:Restoring parameters from ./savedmodel/variables/variables
6.0
选择了TensorFlow 1.x。 警告:tensorflow:From:14:load(来自tensorflow.python.saved\u model.loader\u impl)已被弃用,并将在将来的版本中删除。 更新说明: 此功能只能通过v1兼容性库作为tf.compat.v1.saved_model.loader.load或tf.compat.v1.saved_model.load使用。在Tensorflow 2.0中,将有一个新函数用于导入保存的模型。 信息:tensorflow:从./savedmodel/variables/variables恢复参数 6 请参阅tf.compat.v1版本以了解和 更多细节

我注意到它在路径中添加了一个额外的“变量”字符串,例如 有些原因。对吗

是的,它是正确的。请参考下面的代码,这里的模型保存在
/savedmodel/
,当它从
/savedmodel/variables/variables
加载时

我能够使用
tf执行代码保存和恢复。保存的_模型
在Google Colab和Ananconda(Jupyter笔记本)中都能正常工作

为了社区的利益,这里使用Google Colab中的
tf.saved_model
添加保存和加载

保存模型:

%tensorflow_version 1.x

import tensorflow as tf

# define the tensorflow network and do some trains
x = tf.placeholder("float", name="x")
w = tf.Variable(2.0, name="w")
b = tf.Variable(0.0, name="bias")

h = tf.multiply(x, w)
y = tf.add(h, b, name="y")
sess = tf.Session()
sess.run(tf.global_variables_initializer())

# save the model
export_path =  './savedmodel'
builder = tf.saved_model.builder.SavedModelBuilder(export_path)

tensor_info_x = tf.saved_model.utils.build_tensor_info(x)
tensor_info_y = tf.saved_model.utils.build_tensor_info(y)

prediction_signature = (
  tf.saved_model.signature_def_utils.build_signature_def(
      inputs={'x_input': tensor_info_x},
      outputs={'y_output': tensor_info_y},
      method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME))

builder.add_meta_graph_and_variables(
  sess, [tf.saved_model.tag_constants.SERVING],
  signature_def_map={
      tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY:
          prediction_signature 
  },
  )
builder.save()
输出:

TensorFlow 1.x selected.
WARNING:tensorflow:From <ipython-input-1-1c4a4b6eef10>:19: build_tensor_info (from tensorflow.python.saved_model.utils_impl) is deprecated and will be removed in a future version.
Instructions for updating:
This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.utils.build_tensor_info or tf.compat.v1.saved_model.build_tensor_info.
INFO:tensorflow:No assets to save.
INFO:tensorflow:No assets to write.
INFO:tensorflow:SavedModel written to: ./savedmodel/saved_model.pb
b'./savedmodel/saved_model.pb'
TensorFlow 1.x selected.
WARNING:tensorflow:From <ipython-input-1-097ac1a9f3ad>:14: load (from tensorflow.python.saved_model.loader_impl) is deprecated and will be removed in a future version.
Instructions for updating:
This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.loader.load or tf.compat.v1.saved_model.load. There will be a new function for importing SavedModels in Tensorflow 2.0.
INFO:tensorflow:Restoring parameters from ./savedmodel/variables/variables
6.0
输出:

TensorFlow 1.x selected.
WARNING:tensorflow:From <ipython-input-1-1c4a4b6eef10>:19: build_tensor_info (from tensorflow.python.saved_model.utils_impl) is deprecated and will be removed in a future version.
Instructions for updating:
This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.utils.build_tensor_info or tf.compat.v1.saved_model.build_tensor_info.
INFO:tensorflow:No assets to save.
INFO:tensorflow:No assets to write.
INFO:tensorflow:SavedModel written to: ./savedmodel/saved_model.pb
b'./savedmodel/saved_model.pb'
TensorFlow 1.x selected.
WARNING:tensorflow:From <ipython-input-1-097ac1a9f3ad>:14: load (from tensorflow.python.saved_model.loader_impl) is deprecated and will be removed in a future version.
Instructions for updating:
This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.loader.load or tf.compat.v1.saved_model.load. There will be a new function for importing SavedModels in Tensorflow 2.0.
INFO:tensorflow:Restoring parameters from ./savedmodel/variables/variables
6.0
选择了TensorFlow 1.x。 警告:tensorflow:From:14:load(来自tensorflow.python.saved\u model.loader\u impl)已被弃用,并将在将来的版本中删除。 更新说明: 此功能只能通过v1兼容性库作为tf.compat.v1.saved_model.loader.load或tf.compat.v1.saved_model.load使用。在Tensorflow 2.0中,将有一个新函数用于导入保存的模型。 信息:tensorflow:从./savedmodel/variables/variables恢复参数 6 请参阅tf.compat.v1版本以了解和 更多细节